Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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!

Risposta accettata

Azzi Abdelmalek
Azzi Abdelmalek il 6 Lug 2013
Modificato: Azzi Abdelmalek il 6 Lug 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)

Più risposte (0)

Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by