ODE45 arguments not working
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
David Geistlinger
am 14 Nov. 2018
Bearbeitet: madhan ravi
am 14 Nov. 2018
Not sure why this isnt working. I cut and pasted same code from other ODE45 function for 50kg jumper. All i changed was the variable u to v for this one. The other formula works great this one is giving me errors.
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in DriverProgram (line 85)
[t2, v]=ode45(@ODE4590kg,[0:0.1:300],[0,0]);
Top code is ODE function and below is script to run it:
function [vprime] = ODE4590kg(t2,v )
% Set known variables
vprime =[0;0];
m = 90;
g = 9.81;
W= m*g;
c= W/55^2;
D= c.*(v(1)).^2;
B= 100*(v(2)-8);
R= 3.*(v(1));
if v(2) >= 0 && v(2) <= 8
vprime(1) = (W-D)/m;
vprime(2) = v(1);
else
vprime(1) = (W-D-B-R)/m;
vprime(2) = v(1);
end
end
%%
[t2, v]=ode45(@ODE4590kg,[0:0.1:300],[0,0]); %Line 85
xx2_prime = v(:,1); % all rows and column 1 of u
xx2 = v(:,2); % all rows and column 2 of u
ma = 90;
gr = 9.81; %Line 90
we= ma*gr;
co= we/55^2;
dr= co.*(xx2_prime).^2;
bu= 100.*(xx2-8);
re= 3.*(xx2_prime);
if xx2 >= 0 & xx2 <= 8
xx2_double_prime = (we-dr)./ma;
else
xx2_double_prime= (we-dr-bu-re)./ma;
end
figure(2)
subplot(3,2,2) % first 2x1 subplot %Line 115
plot(t2,xx2),title('90 kg ODE 45'),xlabel('Time'),ylabel('Position'),axis([0,300,0,30])
subplot(3,2,4) % second 2x1 subplot
plot(t2,xx2_prime),title('90 kg ODE45'),xlabel('Time'),ylabel('Velocity'),axis([0,300,-20,20])
subplot(3,2,6) % first 2x2 subplot
plot(t2,xx2_double_prime),title('90 kg ODE 45'),xlabel('Time'),ylabel('Acceleration'),axis([0,300,-20,10])
0 Kommentare
Akzeptierte Antwort
madhan ravi
am 14 Nov. 2018
Bearbeitet: madhan ravi
am 14 Nov. 2018
%%
[t2, v]=ode45(@ODE4590kg,[0:0.1:300],[0,0]); %Line 85 %FUNCTION CALLING BEFORE FUNCTION DEFINITION
xx2_prime = v(:,1); % all rows and column 1 of u
xx2 = v(:,2); % all rows and column 2 of u
ma = 90;
gr = 9.81; %Line 90
we= ma*gr;
co= we/55^2;
dr= co.*(xx2_prime).^2;
bu= 100.*(xx2-8);
re= 3.*(xx2_prime);
if xx2 >= 0 & xx2 <= 8
xx2_double_prime = (we-dr)./ma;
else
xx2_double_prime= (we-dr-bu-re)./ma;
end
figure(2)
subplot(3,2,2) % first 2x1 subplot %Line 115
plot(t2,xx2),title('90 kg ODE 45'),xlabel('Time'),ylabel('Position'),axis([0,300,0,30])
subplot(3,2,4) % second 2x1 subplot
plot(t2,xx2_prime),title('90 kg ODE45'),xlabel('Time'),ylabel('Velocity'),axis([0,300,-20,20])
subplot(3,2,6) % first 2x2 subplot
plot(t2,xx2_double_prime),title('90 kg ODE 45'),xlabel('Time'),ylabel('Acceleration'),axis([0,300,-20,10])
function [vprime] = ODE4590kg(t2,v ) %function definition
% Set known variables
vprime =[0;0];
m = 90;
g = 9.81;
W= m*g;
c= W/55^2;
D= c.*(v(1)).^2;
B= 100*(v(2)-8);
R= 3.*(v(1));
if v(2) >= 0 && v(2) <= 8
vprime(1) = (W-D)/m;
vprime(2) = v(1);
else
vprime(1) = (W-D-B-R)/m;
vprime(2) = v(1);
end
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!