Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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

1 回表示 (過去 30 日間)
Raphael Hatami
Raphael Hatami 2019 年 10 月 1 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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