Info

This question is closed. Reopen it to edit or answer.

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

1 view (last 30 days)
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]')

Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 1 Oct 2019
Edited: KALYAN ACHARJYA on 1 Oct 2019
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

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!