Info

此问题已关闭。 请重新打开它进行编辑或回答。

plotting: making an array out of values made in a for loop?

1 次查看(过去 30 天)
Hello, I have variable theta and 100 points along its interval, and have found 100 corresponding points of phi. Now I need to plot phi vs theta, so I need to somehow call phi as an array of all those phi values. How do I do this? Thank you.
Here's my code for finding the 100 phi values (successful):
R = .5 %m
L = 1.25 %m
H = .25 %m
N = 100
theta = linspace(0, 4*pi, N);
for i = 1:N
fphi = @(phi) R*sin(theta(i)) + L*sin(phi) - H;
phi = fzero(fphi, phi)
end
here's my code for trying to plot phi vs theta, which is just making a blank graph as of yet:
%phi vs theta
plot(theta,phi);
title('Phi vs Theta')
ylabel('Phi [rad]')
xlabel('Theta [rad]')

回答(1 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-10-1
编辑:KALYAN ACHARJYA 2019-10-1
R=.5; %m
L=1.25; %m
H=.25; %m
N=100;
phi=zeros(1,N);
theta=linspace(0, 4*pi, N);
for i=1:N
fphi=@(phi) R*sin(theta(i)) + L*sin(phi) - H;
phi(i)=fzero(fphi,phi(i));
end
%phi vs theta
plot(theta,phi);
title('Phi vs Theta')
ylabel('Phi [rad]')
xlabel('Theta [rad]')
678.png

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by