MATLAB: Keep getting ‘Error in odearguments (line 90)’ and ‘Error in ode45 (line 115)’

error

I have a script that has previously run perfectly. I recently opened it up it will not run, instead returning the errors 'Error in odearguments (line 90)' and 'Error in ode45 (line 115)'. My code is below:
P = 1500e3;
G = 80e9;
L = 1.5;
D = 0.2;
J = (pi*D^4)/32;
k = (G*J)/L;
IF = 2800;
IM = 200;
A = P/(0.95*1500*((2*pi)/60))^3;
rotor_speeds=[0 31.41592654 62.83185307…
94.24777961 102.1017612 109.9557429…
117.8097245 125.6637061 133.5176878…
141.3716694 149.225651 157.0796327]';
rotor_torques=[15077.83671 17691.32841…
21310.00922 26939.06826 28346.33302…
29049.9654 29753.59778 29150.48431…
26335.95479 20103.78229 10051.89114 0]';
Fitted_Motor_Torque_Curve = fit(rotor_speeds, …
rotor_torques,'smoothingspline');
natural_frequency = (1/(2*pi()))*sqrt(k*((IM+IF)/(IM*IF)));
period = 1./natural_frequency;
t_step = 0.1*period;
h0 = [0; 0; 0];
options = odeset('reltol', 1e-6);
[t,x] = ode45('Torque_Velocity_Function', [0:t_step:40], h0, options);
subplot(2,1,1);
plot(t,x(:,2),t,x(:,3));
grid;
title('Inertia Mechanical Aspects')
xlabel('Time (seconds)');
ylabel('Inertia Angular Velocity (rad/s)');
legend('Motor Angular Velocity','Fan Angular Velocity');
subplot(2,1,2);
plot(t,x(:,1));
grid;
title('Inertia Mechanical Aspects');
xlabel('Time (seconds)');
ylabel('Angle of Twist (radians)');
legend('Relative Angle of Twist');
function dxdt = Torque_Velocity_Function(t,x)
dxdt(1) = x(2)-x(3);
dxdt(2) = ((Fitted_Motor_Torque_Curve(x(2)))-(k.*(x(1))))/IM;
dxdt(3) = ((-1*A*abs(x(3))*x(3))+k*x(1))/IF;
dxdt = dxdt';
end
The error message:
Unrecognized function or variable 'Fitted_Motor_Torque_Curve'.
Error in Torque_Velocity_Function (line 6)
dxdt(2) = ((Fitted_Motor_Torque_Curve(x(2)))-(k.*(x(1))))/IM; %Derived from Newton's II
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 PART_A (line 30)
[t,x] = ode45('Torque_Velocity_Function', [0:t_step:40], h0, options); %Solving the three differential equations

Best Answer

Use the anonymous function function handle representation to call ‘Torque_Velocity_Function’ in your ode45 call:
[t,x] = ode45(@Torque_Velocity_Function, [0:t_step:40], h0, options);
Also, fitting the motor torque isn’t necessary. Interpolation will work, and it’s faster and more efficient:
Fitted_Motor_Torque_Curve = @(x) interp1(rotor_speeds, rotor_torques, x, 'pchip','extrap')
The documentation section on Anonymous Functions explains what they areand how to use them, if you’re not familiar with them. I use them here in the ode45 call, and to construct the ‘Fitted_Motor_Torque_Curve’ function.