How to add known value of position to an ode45 acceleration problem
조회 수: 4 (최근 30일)
이전 댓글 표시
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
Walter Roberson
2018년 3월 26일
Do not use load in the ode routine. See https://www.mathworks.com/help/matlab/math/parameterizing-functions.html
Also your ode45 call should be to mss not Quarter_car_5
답변 (1개)
Walter Roberson
2018년 3월 27일
편집: Walter Roberson
2018년 3월 27일
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!