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 Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by