Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

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

1 vue (au cours des 30 derniers jours)
Raphael Hatami
Raphael Hatami le 1 Oct 2019
Clôturé : MATLAB Answer Bot le 20 Août 2021
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]')

Réponses (1)

KALYAN ACHARJYA
KALYAN ACHARJYA le 1 Oct 2019
Modifié(e) : KALYAN ACHARJYA le 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

Cette question est clôturée.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by