how to plot it?
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Alan Stevens
on 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')
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!