Info

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

I can’t get the program to run for some reason. I want to use for loops for this program.

1 回表示 (過去 30 日間)
Yordi Villafranca
Yordi Villafranca 2020 年 3 月 31 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
clc
momenta = zeros();
Ti = 0;
Tinc = pi/180;
Tf = pi;
Pi = 0;
Pinc = 10;
Pf = 200;
for theta = Ti:Tinc:Tf
for P = Pi:Pinc:Pf
t = theta/Ti;
p = P/Pi;
momenta(t,p) = -6000 + (p*sin(theta))*(33)-(p*cos(theta))*(25);
%t is the counter for theta increments
%p is the counter for P
%These must be integers
end
end
%For Plotting Purposes
[theta,P] = meshgrid(Ti:Tinc:Tf,Pi:Pinc:Pf);
figure
surf(theta,P,momenta)

回答 (1 件)

KSSV
KSSV 2020 年 3 月 31 日
編集済み: KSSV 2020 年 3 月 31 日
You need not to use two for loops.....that is a wrong idea.
This is what you should do:
Ti = 0;
Tinc = pi/180;
Tf = pi;
Pi = 0;
Pinc = 10;
Pf = 200;
%For Plotting Purposes
[theta,P] = meshgrid(Ti:Tinc:Tf,Pi:Pinc:Pf);
momenta = -6000 + (P.*sin(theta))*(33)-(P.*cos(theta))*(25);
figure
surf(theta,P,momenta)
  3 件のコメント
Yordi Villafranca
Yordi Villafranca 2020 年 3 月 31 日
I want to do it using for loop
KSSV
KSSV 2020 年 3 月 31 日
momenta = zeros();
Ti = 0;
Tinc = pi/180;
Tf = pi;
Pi = 0;
Pinc = 10;
Pf = 200;
%For Plotting Purposes
theta = Ti:Tinc:Tf ;
P = Pi:Pinc:Pf ;
nx = length(theta) ; ny = length(P) ;
[theta,P] = meshgrid(theta,P);
momenta = zeros(ny,nx) ;
for i = 1:ny
for j = 1:nx
momenta(i,j) = -6000 + (P(i,j)*sin(theta(i,j)))*(33)-(P(i,j)*cos(theta(i,j)))*(25);
end
end
figure
surf(theta,P,momenta)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by