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