Error in using ode45 to solve a second-order ODE
Show older comments
I am trying to solve a fairly simple second-order ODE using the ode45 command. I've read the documentation and created a file containing the function to be solved, having reduced it to state space form. The file is called function1dof.m
m = 12.319*0.25*0.036;
g = 386.1; % inch/s^2
L = 8.6; Lc = L/2;
I = 0.653*2;
u = 0.5; % Torque input in lb-in
function func = F(t,x)
func = zeros(2,1);
func(1) = x(2);
func(2) = (1/(Lc^2 + I))*(u - m*g*Lc*sin(x(1)));
end
Then, I created a second .m file, called solver1dof.m, to execute the ode45 command and (hopefully) solve the equation.
clear all
time_period = [0 2];
initial = [0, 0];
[t,x] = ode45(@F, time_period, initial);
However, running solver1dof.m gives an error claiming the function 'F' is undefined:
>> solver1dof
Undefined function or variable 'F'.
Error in odearguments (line 90)
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 solver1dof (line 4)
[t,x] = ode45(@F, time_period, initial);
I am unsure on how to proceed, as it seems the function is perfectly well defined, as far as I can tell (obviously, it isn't).
Accepted Answer
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!