how to plot it?

1 visualizzazione (ultimi 30 giorni)
Sadiq Akbar
Sadiq Akbar il 13 Feb 2021
Commentato: Sadiq Akbar il 13 Feb 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

Risposta accettata

Alan Stevens
Alan Stevens il 13 Feb 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 Commenti
Sadiq Akbar
Sadiq Akbar il 13 Feb 2021
Thank you very much dear Alan Stevens for your prompt response.
Sadiq Akbar
Sadiq Akbar il 13 Feb 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?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by