draw a control plot for a function

2 views (last 30 days)
debabrat
debabrat on 15 Apr 2014
Commented: debabrat on 16 Apr 2014
hello everyone, I need to generate a contour plot for the following code:- e=2.71828; dt=.01; A=-1; B=1; a=cell(12,12); data=zeros(1,220) for i=1:20 eps=i for j=0:0.1:1 beta=j for t=0:0.01:1.9 t=t+dt xp=0.1 fxp=eps*xp fz0=1/1+power(e,beta*(-t)) fzi=A+(B-A)*rand(1,12) for ii=1:12 for jj=1:12 if ii==jj a2(ii,jj)=fzi(jj) else a2(ii,jj)=0; end end end s=fxp*fz0 *a2 x=xp+(s*dt) xp=x end p=abs(fft(x)) p=p.^2 ne=max(p(1:10)) ne1=max(p(10:30)) ne2=max(p(80:120)) end end figure (1) [C,h]=contour(eps,beta,ne,'linewidth',2) figure (2) [C,h]=contour(eps,beta,ne1,'linewidth',2) figure (3) [C,h]=contour(eps,beta,ne2,'linewidth',2)
ne,ne1,ne2 is holding the value only for the last loop..but i need all the values of ne,ne1,ne2.. what should i do..please help....

Accepted Answer

A Jenkins
A Jenkins on 15 Apr 2014
You want to store ne, etc as a matrix of the size of your loops, so it would be ne(i,j), etc:
e=2.71828;
dt=.01;
A=-1; B=1;
a=cell(12,12);
data=zeros(1,220);
eps=1:20;
beta=0:0.1:1;
kk=0;
for i=1:length(eps)
for j=1:length(beta)
for t=0:0.01:1.9
t=t+dt;
xp=0.1;
fxp=eps(i)*xp ;
fz0=1/1+power(e,beta(j)*(-t));
fzi=A+(B-A)*rand(1,12);
for ii=1:12
for jj=1:12
if ii==jj
a2(ii,jj)=fzi(jj);
else
a2(ii,jj)=0;
end
end
end
s=fxp*fz0 *a2;
x=xp+(s*dt);
xp=x;
end
p=abs(fft(x));
p=p.^2;
ne(i,j)=max(p(1:10));
ne1(i,j)=max(p(10:30));
ne2(i,j)=max(p(80:120));
end
end
figure(1)
[C,h]=contour(eps,beta,ne','linewidth',2)
figure(2)
[C,h]=contour(eps,beta,ne1','linewidth',2)
figure(3)
[C,h]=contour(eps,beta,ne2','linewidth',2)
  1 Comment
debabrat
debabrat on 16 Apr 2014
Thank you very much A Jenkins... It works nicely..

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!