how to plot it?

2 vues (au cours des 30 derniers jours)
Sadiq Akbar
Sadiq Akbar le 13 Fév 2021
Commenté : Sadiq Akbar le 13 Fév 2021
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

Réponse acceptée

Alan Stevens
Alan Stevens le 13 Fév 2021
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 commentaires
Sadiq Akbar
Sadiq Akbar le 13 Fév 2021
Thank you very much dear Alan Stevens for your prompt response.
Sadiq Akbar
Sadiq Akbar le 13 Fév 2021
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?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by