ode45 , order arguments

2 views (last 30 days)
Darron Muzavazi
Darron Muzavazi on 11 Nov 2020
Commented: Darron Muzavazi on 11 Nov 2020
I am getting these two errors when i run my code. I rececntly used the code for a different problem with no questions. How can i get it to run.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in quartercar (line 37)
[time, state_values] = ode45(sdot,tspan,IC);
This is my code,
function quartercar
k1 = 80000; %N/m
k2 = 500000;%N/m
m1 = 2500; %kg
m2 = 320; %kg
b1 = 350; %Ns/m
b2 = 15020; %Ns/m
rd = @(time) 0.15*sin(time)^2;
rdprime = @(time) 0.15*sin(2*time);
%Initial Conditions
xone0 = 0; vone0 = 0;
xtwo0 = 0; vtwo0 = 0;
IC = [xone0, vone0, xtwo0, vtwo0];
%Time Span
t0 = 0; tf = 10;
tspan = [t0,tf];
%sdot = g(t,s) state variable
sdot = @(t,s) ...
[s(2);
(-1/m1)*((k1*(s(1)-s(3))) + (b1*(s(2)-s(4))));
s(4);
((k1*(s(1)-s(3)) + b1*(s(2)-s(4)) -k2*(s(3)-rd) -b2*(s(4)-rdprime))/m2)];
i am guessing the problem is here
%Numerical Intergration
[time, state_values] = ode45(sdot,tspan,IC);
xone = state_values(:,1);
vone = state_values(:,2);
xtwo = state_values(:,3);
vtwo = state_values(:,4);
%Plots
plot(time,xone)
xlabel('time (s)')
ylabel('displacement (m)')
title('Displacement vs Time')
grid on
end

Accepted Answer

Walter Roberson
Walter Roberson on 11 Nov 2020
quartercar
function quartercar
k1 = 80000; %N/m
k2 = 500000;%N/m
m1 = 2500; %kg
m2 = 320; %kg
b1 = 350; %Ns/m
b2 = 15020; %Ns/m
rd = @(time) 0.15*sin(time)^2;
rdprime = @(time) 0.15*sin(2*time);
%Initial Conditions
xone0 = 0; vone0 = 0;
xtwo0 = 0; vtwo0 = 0;
IC = [xone0, vone0, xtwo0, vtwo0];
%Time Span
t0 = 0; tf = 10;
tspan = [t0,tf];
%sdot = g(t,s) state variable
sdot = @(t,s) ...
[s(2);
(-1/m1)*((k1*(s(1)-s(3))) + (b1*(s(2)-s(4))));
s(4);
((k1*(s(1)-s(3)) + b1*(s(2)-s(4)) -k2*(s(3)-rd(t)) -b2*(s(4)-rdprime(t)))/m2)]; %CHANGED
%Numerical Intergration
[time, state_values] = ode45(sdot,tspan,IC);
xone = state_values(:,1);
vone = state_values(:,2);
xtwo = state_values(:,3);
vtwo = state_values(:,4);
%Plots
plot(time,xone)
xlabel('time (s)')
ylabel('displacement (m)')
title('Displacement vs Time')
grid on
end

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!