How to add known value of position to an ode45 acceleration problem

4 Ansichten (letzte 30 Tage)
Ross Hanna
Ross Hanna am 26 Mär. 2018
Bearbeitet: Walter Roberson am 27 Mär. 2018
Hi there,
Once again i am struggling with MATLABS ODE functions. I am using the differential solvers to find the accelerations of a mass spring damper problem, which is a simplification of a motorcycle front end. I have written some code which solves from the parameters i have given as a test, and it solves it with no errors and gives the expected response shape. However, in this problem i know the change in position of the input, aka the road, which is what i really want to solve for. However, because i have had to convert to a first order system, the equations are in the form;
y(1) = xs - xu
y(2) = xs' - xu'
y(3) = xu - Z
y(4) = xu' - Z'
dydt = [y(2); -(Ks/ms)*y(1) - (Cs/ms)*y(2); y(4); +(Ks/ms)*y(1) + (Cs/ms)*y(2) - (Ku/mu)*y(3) - (Cu/mu) *y(4);]
My problem is that i know the value of Z, but can't find a way to input it, as that then causes issues with undefined xu and xs. My only thought is that i can put it in the initial values, but then i would still have the problem with undefined xs ad xu.
as an aside, i was told to place the load() function outside of the function, but then i get the error
Attempt to execute SCRIPT Quarter_Car_5 as a function:
C:\Users\user\Dropbox\Ross Hanna Project\Matlab\Diff Solving\Quarter_Car_5.m
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode15s (line 150)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in ODE_Solver_Quarter_Car (line 8)
[t,y]=ode15s(@Quarter_Car_5, tspan, y0)
Could someone show me the correct way to achieve this, or let me know if i need to start a new thread.
My code is below, any help would be greatly appreciated.
function dydt = mss(t,y)
load('Standard_European_Bump_Data.mat','length','height')
height1 = height/1000
length1 = length/1000
%h_vs_l = plot(length1, height1)
ms = 100
mu = 18
Ks = 20000
Ku = 167000
Cs = 1200
Cu = 50
Z = height1
% y(1) = (xs - xu)
% y(3) = (xu - Z)
% y1' = y(2) % = (xs' - xu')
% y2' = (Ks/ms)*y(1) + (Cs/ms)*y(2)
% y3' = y(4) % = (xu - Z)
% y4' = -(Ks/ms)*y(1) - (Cs/ms) * y(2) + (Ku/mu)*y(3) + (Cu/mu) * y(4)
dydt = [y(2); -(Ks/ms)*y(1) - (Cs/ms)*y(2); y(4); +(Ks/ms)*y(1) + (Cs/ms)*y(2) - (Ku/mu)*y(3) - (Cu/mu) *y(4);]
end
y0 = [0.7 0.1 0.5 0.3]
tspan = [0 10]
[t,y]=ode15s(@Quarter_Car_5, tspan, y0)
where everything following y0 is in a separate file.
Thanks
  2 Kommentare
Walter Roberson
Walter Roberson am 26 Mär. 2018
Also your ode45 call should be to mss not Quarter_car_5
Ross Hanna
Ross Hanna am 27 Mär. 2018
I removed load for the moment while i get used to parametizing functions. The data is just a 1-(cos(x))^2 function anyway. However, i am still unsure how to use this function in the ODE? Can you see anything simple i am missing. Been trying to research it, but i must not be looking in the right place. Thanks

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 27 Mär. 2018
Bearbeitet: Walter Roberson am 27 Mär. 2018
file_struct = load('Standard_European_Bump_Data.mat','length','height');
bump_length = file_struct.length; %let us avoid overwriting the length() function
bump_height = file_struct.height;
y0 = [0.7 0.1 0.5 0.3]
tspan = [0 10]
[t, y] = ode15s(@(t,y) mss(t, y, bump_length, bump_height), tspan, y0)
function dydt = mss(t, y, bump_length, bump_height)
height1 = bump_height/1000;
length1 = bump_length/1000;
ms = 100;
mu = 18;
Ks = 20000;
Ku = 167000;
Cs = 1200;
Cu = 50;
%Z = height1;
% y(1) = (xs - xu)
% y(3) = (xu - Z)
% y1' = y(2) % = (xs' - xu')
% y2' = (Ks/ms)*y(1) + (Cs/ms)*y(2)
% y3' = y(4) % = (xu - Z)
% y4' = -(Ks/ms)*y(1) - (Cs/ms) * y(2) + (Ku/mu)*y(3) + (Cu/mu) * y(4)
dydt = [y(2);
-(Ks/ms)*y(1) - (Cs/ms)*y(2);
y(4);
+(Ks/ms)*y(1) + (Cs/ms)*y(2) - (Ku/mu)*y(3) - (Cu/mu) *y(4);];
end

Community Treasure Hunt

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

Start Hunting!

Translated by