How do I store the x's, the v's and the F's from this for loop into an array??? pls and ty
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
x=0; %position of the leaf in meters
v=.5; %the velocity of the leaf in meters/seconds
m=0.3; %mass of the leaf in kilograms
t=(0:0.05:3);
h=0.05;
int=0; %the intial time for graphing
%for
for I=(1:60) %Number of instances which is 0 to 3 seconds of steps of .05
%Plot
subplot(1,3,1)
plot(int,x,'.r') %Graph of position over time
hold on
subplot(1,3,2)
plot(int,v,'.r')
hold on
%Equations
F=0.2*(sin(x))*((x^2)+x); %Force equation
a=F/m; %acceleration equation
x=x+h*v;%New Position
v=v+h*a; %New Velocity
subplot(1,3,3)
plot(int,F,'.r')
hold on
int=int+0.05;
end
0 Kommentare
Antworten (1)
Julia
am 24 Apr. 2015
Hi,
I just modified your code so that you can store the values for x, v and F.
x=zeros(1,61);
v=zeros(1,61);
F=zeros(1,60);
x(1)=0; %position of the leaf in meters
v(1)=.5; %the velocity of the leaf in meters/seconds
m=0.3; %mass of the leaf in kilograms
t=(0:0.05:3);
h=0.05;
int=0; %the intial time for graphing
%for
for I=(1:60) %Number of instances which is 0 to 3 seconds of steps of .05
%Plot
subplot(1,3,1)
plot(int,x(I),'.r') %Graph of position over time
hold on
subplot(1,3,2)
plot(int,v(I),'.r')
hold on
%Equations
F(I)=0.2*(sin(x(I)))*((x(I)^2)+x(I)); %Force equation
a=F(I)/m; %acceleration equation
x(I+1)=x(I)+h*v(I);%New Position
v(I+1)=v(I)+h*a; %New Velocity
subplot(1,3,3)
plot(int,F(I),'.r')
hold on
int=int+0.05;
end
4 Kommentare
Siehe auch
Kategorien
Mehr zu Specialized Power Systems finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!