How do I write a while/loop function that will help me use a previous value to find the next value?

1 次查看(过去 30 天)
Hi, so I'm writing a matlab code that deals with acceleration, velocity, and distance formulas. I use the acceleration to find the velocity. The acceleration and velocity to find the distance.
I also use the initial velocity to find the next velocity and the initial distance to find the next distance. I use a for loop that deals with i. "i" is the angle used in the acceleration equation.
My code right now is very bad. I'm not very good at matlab but I'm trying so bare with me. Here is my current code:
clc
clear all
g=9.81;
uk=.15;
t=0.01;
V=0;
S=0;
a=0;
R=3;
theta=0;
V=0;
while theta<90
for i=0:90
a(i)=g*cos(theta)-(uk*(g*sin(theta))+(V.^2/R));
a=a(i);
for i=0:90
V(i)=V+a(i)*t;
V=V(i);
S(i)=S+(V*t.^2)+(.5*a(i)*t.^2);
S=S(i);
for i=0:90
theta(i)=S/R;
theta=theta(i);
end
end
end
end

回答(1 个)

Walter Roberson
Walter Roberson 2017-6-5

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by