Borrar filtros
Borrar filtros

How to plot a 2D graph using all the for loop values

2 visualizaciones (últimos 30 días)
Pranjal Pathak
Pranjal Pathak el 6 de Jul. de 2013
Comentada: Anders Kipp el 15 de Feb. de 2016
Hi, I have the following equation to be plotted in Matlab:
***************
alp=1;
K=1;
E0=1;
for w=-20:1:20;
a=K*(cos(pi*alp/2)*w^alp+w^(2*alp));
b=1+2*(cos(pi*alp/2)*w^alp+w^(2*alp));
c=a/b;
E(w)=E0*(1+c);
end
figure(1)
plot(E,w)
xlabel('w');
ylabel('E');
title('Plot of E vs w')
*********
Can anyone tell me what is wrong in the above code, as I am unable to get the plot.
Thanking You!

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 6 de Jul. de 2013
Editada: Azzi Abdelmalek el 6 de Jul. de 2013
Your errors:
  1. you can not use a negative index
  2. when you write for w=-20:20, at the end of the loop w=20, is just one value
  3. you should use plot (w,E) instead of plot(E,w)
alp=1;
K=1;
E0=1;
E=[];
for w=-20:1:20;
a=K*(cos(pi*alp/2)*w^alp+w^(2*alp));
b=1+2*(cos(pi*alp/2)*w^alp+w^(2*alp));
c=a/b;
E(end+1)=E0*(1+c);
end
figure(1)
w=-20:20
plot(w,E)
xlabel('w');
ylabel('E');
title('Plot of E vs w')t(E,w)
  1 comentario
Pranjal Pathak
Pranjal Pathak el 6 de Jul. de 2013
Thanks a lot Azzi! This was what I was looking for. I have a similar problem which I have posted yesterday. Can you help me here: http://www.mathworks.com/matlabcentral/answers/81191-how-to-plot-using-all-the-for-loop-values

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by