draw a control plot for a function

조회 수: 8 (최근 30일)
debabrat
debabrat 2014년 4월 15일
댓글: debabrat 2014년 4월 16일
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....

채택된 답변

A Jenkins
A Jenkins 2014년 4월 15일
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
debabrat
debabrat 2014년 4월 16일
Thank you very much A Jenkins... It works nicely..

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by