how to plot it?

1 回表示 (過去 30 日間)
Sadiq Akbar
Sadiq Akbar 2021 年 2 月 13 日
コメント済み: Sadiq Akbar 2021 年 2 月 13 日
I have the following code. I want a plot between var1 vs e where var1 is along x-axis and ranges from 0 to 10.
th=pi/180;
b=[var1;7;50*th;85*th];
u=[2;7;50*th;85*th];
[~,C]=size(b);
P=C/2;
M=2*C;
xo=zeros(1,M);
for k=1:M
for i=1:P
xo(1,k)=xo(1,k)+u(i)*exp(-1i*(k-1)*pi*cos(u(P+i)));
end
end
xe=zeros(1,M);
for k=1:M
for i=1:P
xe(1,k)=xe(1,k)+b(i)*exp(-1i*(k-1)*pi*cos(b(P+i)));
end
end
abc=0.0;
for m1=1:M
abc=abc+(abs(xo(1,m1)-xe(1,m1))).^2;
end
abc=abc/M;
e=abc

採用された回答

Alan Stevens
Alan Stevens 2021 年 2 月 13 日
More like this perhaps:
th=pi/180;
u=[2;7;50*th;85*th];
var1 = 0:0.5:10; %%%%%%%%%%%%%%%%%%%%%
for j = 1:numel(var1) %%%%%%%%%%%%%%%%%%%%%
b=[var1(j);7;50*th;85*th]; %%%%%%%%%%%%%%%%%%%%%
C=numel(b); %%%%%%%%%%%%%%%%%%%%%
P=C/2;
M=2*C;
xo=zeros(1,M);
for k=1:M
for i=1:P
xo(1,k)=xo(1,k)+u(i)*exp(-1i*(k-1)*pi*cos(u(P+i)));
end
end
xe=zeros(1,M);
for k=1:M
for i=1:P
xe(1,k)=xe(1,k)+b(i)*exp(-1i*(k-1)*pi*cos(b(P+i)));
end
end
abc=0.0;
for m1=1:M
abc=abc+(abs(xo(1,m1)-xe(1,m1))).^2;
end
abc=abc/M;
e(j)=abc; %%%%%%%%%%%%%%%%%%%%%
end
plot(var1,e),grid
xlabel('var1'),ylabel('e')
  2 件のコメント
Sadiq Akbar
Sadiq Akbar 2021 年 2 月 13 日
Thank you very much dear Alan Stevens for your prompt response.
Sadiq Akbar
Sadiq Akbar 2021 年 2 月 13 日
Can we plot its surface plot? I mean when all the four elements of b are varied at the same time from 0 to 10 and then plot a surface plot for e vs b?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by