plotting a special function

1 visualización (últimos 30 días)
Ali Roshanzamir
Ali Roshanzamir el 4 de Ag. de 2020
Comentada: Ali Roshanzamir el 4 de Ag. de 2020
Hey guys,
I want to plot this curve. Please help me. It's too important for me!
N=45;
N(θ)= N*7/8 for 0<θ<π/4 & π<θ<5π/4
-N/8 for other θ
  3 comentarios
Ali Roshanzamir
Ali Roshanzamir el 4 de Ag. de 2020
I did this but it doesn't show anything
N=45;
for teta=0:2*pi,
if((teta>pi/4)&(pi<teta<=5*pi/4)),
Nteta=7*N/8;
else
Nteta=-N/8;
end;
end;
subplot(2,1,1)
plot(teta,Nteta)
Walter Roberson
Walter Roberson el 4 de Ag. de 2020
Use logical indexing based upon logical comparisons you do between theta and the constants of the question.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 4 de Ag. de 2020
if((teta>pi/4)&(pi<teta<=5*pi/4)),
Nteta=7*N/8;
You are overwriting all of Nteta there, with a scalar. At the end of your for loop, Nteta will be a scalar that has whatever value was last assigned to it.
plot(teta,Nteta)
After the for teta loop, the loop control variable (teta) will have the value it was assigned last in the loop. So it will be the scalar 6. Then you are plotting that scalar on the x axis and the scalar Nteta on the y axis -- a single point. However, when you plot a single point without indicating a marker, then plot tries to draw just the between the single point and itself, which is not going to produce any visible marking.
for teta=0:2*pi,
Remember that the default increment for the : operator is 1, so you are asking to run the loop with teta = 0, 1, 2, 3, 4, 5, and 6.
  1 comentario
Ali Roshanzamir
Ali Roshanzamir el 4 de Ag. de 2020
Ok, Thanks for your information

Iniciar sesión para comentar.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by