Effacer les filtres
Effacer les filtres

How to plot using all the for loop values

2 vues (au cours des 30 derniers jours)
Pranjal Pathak
Pranjal Pathak le 5 Juil 2013
Hi,
Here I am pasting a simple code which does a simple integration from - infinity to + infinity:
syms x
C=1;D=1;E=1;N=1;W=1;
alp=1;
z=1;
for P=1:1:20
a=(sqrt(-1))*(C-P);
b=(D-(sqrt(-1))*(P+x));
c=(E+(sqrt(-1))*(N-P));
d=(W^2+x.^2);
e=b*c*d;
f=a/e;
S=alp*(int(f,-inf,inf));
out = vpa(S);
k=double(out)
end
******** The problem is to plot a graph (S Vs P) using all the values of P. Can anyone help me in this regard?
Thanking You!

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 6 Juil 2013
Modifié(e) : Azzi Abdelmalek le 6 Juil 2013
You have to use: k(P) instead of k
syms x
C=1;D=1;E=1;N=1;W=1;
alp=1;
z=1;
for P=1:1:20
aa=(sqrt(-1))*(C-P);
b=(D-(sqrt(-1))*(P+x));
c=(E+(sqrt(-1))*(N-P));
d=(W^2+x.^2);
e=b*c*d;
f=a/e;
S=alp*(int(f,-inf,inf));
out = vpa(S);
k(P)=double(out)
end
plot(abs(k))
  1 commentaire
Pranjal Pathak
Pranjal Pathak le 6 Juil 2013
Thanks a lot once again...

Connectez-vous pour commenter.

Plus de réponses (1)

Neha
Neha le 5 Juil 2013
The variable S is just a single dimension matrix. You can replace S=alp*(int(f,-inf,inf)); with S(P)=alp*(int(f,-inf,inf));
By doing this the index for S is getting maintained and you can simply call
plot((double)S);
  1 commentaire
Pranjal Pathak
Pranjal Pathak le 5 Juil 2013
Hi Neha, Thanks for your answer. But I did not get the plot (S Vs P). Can you please write the code?
Thanking You!

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by