Info

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

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

1 vue (au cours des 30 derniers jours)
Yordi Villafranca
Yordi Villafranca le 31 Mar 2020
Clôturé : MATLAB Answer Bot le 20 Août 2021
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)

Réponses (1)

KSSV
KSSV le 31 Mar 2020
Modifié(e) : KSSV le 31 Mar 2020
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 commentaires
KSSV
KSSV le 31 Mar 2020
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