Help using ode45 to solve a pair of equations.
Ältere Kommentare anzeigen
I have two equations that, according to my professor, I need to solve in MATLAB using ode45: (o is theta, o' means theta-dot e.g. dynamics notations)
F = m2(d'' - (L1+d)o'^2) + m2*g*sin(o)
T = [(1/3)m1(L1)^2 + (1/12)m2(L2)^2 + m2(L1+d)^2]o'' + (2(m2)(L1+d)d'o' + gcos(o)[m1(L1/2) + m2(L1 + d)]
I substituted the following:
u = d'
w = o'
Simplified equations are:
u1 = u' = d'' = [(F=m2gsin(o))/m2] + (L1 + d)w^2
w1 = w' = o'' = {[T-(2(m2)(L1 + d)uw - gcos(o)(m1(L1/2) + m2(L1 + d)] / [(1/3)m1(L1)^2 + (1/12)m2(L2)^2 + m2(L1 + d)^2]}
[I tried to type this out cleanly, hope it is clear]
Into MATLAB, I entered:
m1=1
m2=1
l1=1
l2=1
g=9.81
o0=0
d0=0
u0=0
w0=0
F=0
T=0
u1=@(d,o,u,w) ((F-m2*g*sin(o))/(m2))+(l1+d)*w^2
w1=@(d,o,u,w) ((T-(2*m2(L1+d)*u*w)-g*cos(o)*(m1*((L1)/2)+m2*(L1+d)))/((1/3)*m1*(l1)^2+(1/12)*m2*(l2)^2+m2(l1+d)^2))
[d,u,o,w] = ode45(u1, [0,10], d0)
MATLAB responded with this:
m1 =
1
m2 =
1
l1 =
1
l2 =
1
g =
9.8100
o0 =
0
d0 =
0
u0 =
0
w0 =
0
F =
0
T =
0
u1 =
@(d,o,u,w)((F-m2*g*sin(o))/(m2))+(l1+d)*w^2
w1 =
@(d,o,u,w)((T-(2*m2(L1+d)*u*w)-g*cos(o)*(m1*((L1)/2)+m2*(L1+d)))/((1/3)*m1*(l1)^2+(1/12)*m2*(l2)^2+m2(l1+d)^2))
Not enough input arguments.
Error in try1>@(d,o,u,w)((F-m2*g*sin(o))/(m2))+(l1+d)*w^2
Error in odearguments (line 87)
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 try1 (line 19)
[d,u,o,w] = ode45(u1, [0,10], d0)
What am I doing wrong?
My professor said I should be able to receive output values for d, d', o, o'.
Antworten (1)
Star Strider
am 1 Aug. 2016
I cannot follow what you’re doing.
You are getting the ‘not enough input arguments’ error because your ODE function has 4 input arguments and ode45 is only supplying 2. You can pass extra arguments, but to do that you have to create a second anonymous function from your ODE function.
You first have to put your two equations:
F = m2(d'' - (L1+d)o'^2) + m2*g*sin(o)
T = [(1/3)m1(L1)^2 + (1/12)m2(L2)^2 + m2(L1+d)^2]o'' + (2(m2)(L1+d)d'o' + gcos(o)[m1(L1/2) + m2(L1 + d)]
as a system of first-order differential equations. See the documentation for ode45 for a full explanation.
If you have the Symbolic Math Toolbox, it will immensely helpful here. Type in your equations using the diff function for the symbolic derivatives, then use the odeToVectorField function and the matlabFunction functions (in that order) to magickally convert them into a form that ode45 can use.
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!