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!



