How to plot different y values for different x values, provided the x and y values are to be generated in a loop?
6 ビュー (過去 30 日間)
古いコメントを表示
Hello Everyone. I am unable to fetch the values of xy generated in the iteration process.
For every value of a, I want to plot ra. Following is my code, please help:
n=100;
b=6.9;
r=5;
y=(r-1)+0.5;
e=0;z=2;
U=9000;
for a=linspace(4500,U,500)
q=2*pi*a*r;
for m=0:n
p=(4*q/pi)*((((-1)^m)/((2*m)+1))*(exp(-((2*m)+1)*(pi/(2*b))*z))*(cos(((2*m)+1)*(pi/(2*b))*y)));
e=e+p;
if (abs(p)/e)<(10^(-6))
break
end
u=e;
while z<=6
z=z+1;
end
end
ps=1000*((u/100)^2/2);
ra=2*0.072/ps;
plot(a,ra)
hold on
end
hold off
0 件のコメント
採用された回答
DGM
2022 年 1 月 25 日
編集済み: DGM
2022 年 1 月 25 日
This is a start:
n=100;
b=6.9;
r=5;
y=(r-1)+0.5;
e=0;z=2;
U=9000;
npoints = 500;
a = linspace(4500,U,500);
q = 2*pi*a*r;
ra = zeros(1,npoints);
for idx = 1:npoints
for m=0:n
p=(4*q(idx)/pi)*((((-1)^m)/((2*m)+1))*(exp(-((2*m)+1)*(pi/(2*b))*z))*(cos(((2*m)+1)*(pi/(2*b))*y)));
e=e+p;
if (abs(p)/e)<(10^(-6))
break
end
u=e;
while z<=6
z=z+1;
end
end
ps = 1000*((u/100)^2/2);
ra(idx) = 2*0.072/ps;
end
plot(a,ra)
5 件のコメント
DGM
2022 年 1 月 26 日
n = 100; %fixing the number of iterations
b = 6.9;
r = 5;
y = (r-1)+0.5;
e = 0;
U = 4500:500:9000;
npoints = numel(U);
ra = zeros(5,npoints);
for uidx = 1:npoints
q = 2*pi*(U(uidx)/60)*r; %linear vel conversion
for z = 2:1:6
for cidx = 1:npoints
for m = 0:n
p = (4*q/pi)*((((-1)^m)/((2*m)+1))*(exp(-((2*m)+1)*(pi/(2*b))*z))*(cos(((2*m)+1)*(pi/(2*b))*y)));
e = e+p;
if (abs(p)/e)<(10^(-6)) %convergence check
break
end
u = e;
end
ps = 1000*((u/100)^2/2);
ra(z,cidx) = (2*0.072/ps)*(10^(6));
end
e = 0; % reset e
end
end
plot(U,ra)
legend({'z=2cm','z=3cm','z=4cm','z=5cm','z=6cm'})
その他の回答 (1 件)
KSSV
2022 年 1 月 25 日
As you are plotting a point, you need to use marker.
n=100;
b=6.9;
r=5;
y=(r-1)+0.5;
e=0;z=2;
U=9000;
figure
hold on
for a=linspace(4500,U,500)
q=2*pi*a*r;
for m=0:n
p=(4*q/pi)*((((-1)^m)/((2*m)+1))*(exp(-((2*m)+1)*(pi/(2*b))*z))*(cos(((2*m)+1)*(pi/(2*b))*y)));
e=e+p;
if (abs(p)/e)<(10^(-6))
break
end
u=e;
while z<=6
z=z+1;
end
end
ps=1000*((u/100)^2/2);
ra=2*0.072/ps;
plot(a,ra,'.b')
end
hold off
3 件のコメント
KSSV
2022 年 1 月 25 日
Becuase you are not plotting z. Include that plot also, so that you can get. But I feel z values lies far above the value of ra and plot doesn't look good.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



