how to plot it?

1 visualización (últimos 30 días)
Sadiq Akbar
Sadiq Akbar el 13 de Feb. de 2021
Comentada: Sadiq Akbar el 13 de Feb. de 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

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by