MATLAB Answers

Having trouble with ODE45 and a System of Ordinary Differential Equations

2 views (last 30 days)
Aymeric Alejo-chaban
Aymeric Alejo-chaban on 4 Dec 2019
Edited: Stephan on 5 Dec 2019
For a class project, I am trying to solve for an automobile’s vertical and pitching motions as a function of time. I have the equations of motion describing the vehicle and I am trying to use ODE45. However, I keep getting the error Not enough input arguments. I have tried to fiddle with each variable but I am getting nowhere. If anyone could help me it would be greatly appreciated.
Main Code:
[t,z] = ode45(@ode, [0 10], [8 0]);
plot(t,z(:,5),'-o')
plot(t,z(:,7),'-o')
title('Automobiles Vertical and Pitching Motions');
xlabel('time t');
ylabel('displacement (m)');
Function Code:
function zdot = ode(t,z)
Mv = 1500;
Jg = 1000;
Mw = 20;
kc = 200000;
kt = 350000;
l1 = 2;
l2 = 2.5;
w = 100;
zdot = zeros(1,8);
zdot(1) = z(2)
zdot(2) = (1/Mw)*(.01*cos(w*t)+kc*x(3)-(kt+kc)*x(2)-kc*l1*theta)
zdot(3) = z(4)
zdot(4) = (1/Mw)*(.01*cost(w*t)+kc*x(3)+kc*l2*theta-(kt+kc)*x(2))
zdot(5) = z(6)
zdot(6) = (1/Mv)*(kc*l1*theta+kc*x1+kc*x2-kc*l2*theta-2*kc*x3)
zdot(7) = z(8)
zdot(8) = (1/Jg)*(kc*l1*x3-kc*((l2^2)+(l1^2))*theta-kc*l1*x1-kc*l2*x3+kc*l2*x2)
%zdot = [z(2) , (1/Mw)*(.01*cos(w*t)+kc*x(3)-(kt+kc)*x(2)-kc*l1*theta) , z(4) , (1/Mw)*(.01*cost(w*t)+kc*x(3)+kc*l2*theta-(kt+kc)*x(2)) , z(6) , (1/Mv)*(kc*l1*theta+kc*x1+kc*x2-kc*l2*theta-2*kc*x3) , z(8) , (1/Jg)*(kc*l1*x3-kc*((l2^2)+(l1^2))*theta-kc*l1*x1-kc*l2*x3+kc*l2*x2)];
end

  0 Comments

Sign in to comment.

Answers (2)

Stephan
Stephan on 4 Dec 2019
For every equation you have to input an initial condition. You have 8 but only give 2 initial conditions to ode45.
Also your function should return a column vector.
And where is x?

  4 Comments

Show 1 older comment
Stephan
Stephan on 4 Dec 2019
So you have unknowns - then this approach is not the right one. The result of ode45 in this case would be the numerical solution of z(1)...z(8), but only if all other values are known. Another suitable case would be if you have measured data that fulfills the differential equations and you look for parameters x and theta that best fit to your data. If both is not the case, you shouldn't use ode45 probably, because it wouldn't help. Can you post your full question?
Aymeric Alejo-chaban
Aymeric Alejo-chaban on 4 Dec 2019
A vehicle can be modeled with the simplified model in the figure. Mv, Jv, Mw, Kc, and Kt represent the mass of the vehicle, its moment of inertia, the mass of each axle, the stiffness of each axle, and the stiffness of each tire, respectively.
Mv=1500kg, Jv=1000kgm2, Mw=20kg, kc=200kN/m, kt=350kN/m, l1=2m, l2=2.5m
Determine the following:
1.The equation of motion
2.The natural frequencies and mode shapes
3.The automobile’s vertical and pitching motions as a function of time when the road creates a displacement of 0.01cos(wt) m for each tire, where w = 100 rad/s.
Stephan
Stephan on 5 Dec 2019
Ok, can you provide the equations in a mathematical form, for example as latex?
I suspect that you have substituted x and theta by z(?) and that this makes a problem, but im not sure about this.

Sign in to comment.


Aymeric Alejo-chaban
Aymeric Alejo-chaban on 4 Dec 2019
All of the initial conditions should be zero so how would I go about writing that? And would the section commented out return a column vector. Finally, x and theta are what I am looking for.

  0 Comments

Sign in to comment.

Sign in to answer this question.

Tags

Products


Release

R2017a