MATLAB: How to get ode45 to work with the function

functionMATLABmrdivideodeode45

I keep getting these error messages:
Undefined function 'mrdivide' for input arguments of type 'function_handle'.
Error in adiabatic (line 35) k = kt*exp((E/R2)*((1/T0)-(1/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 KineticsProject (line 14) [X,V] = ode45(@adiabatic,Xspan,V0)
if true
function dXdV = adiabatic(V,X)
syms T
eqn1 = ((CpA+CpB)*(T-T0))+(X*(HRXStand+HvapA+HvapC+(CpC*(T-BPC))+(CpD*(T-T0))-(CpA*(T-BPA))-(CpB*(T-T0)))) == 0;
T = vpasolve(eqn1,T);
f = matlabFunction(T);
k = kt*exp((E/R2)*((1/T0)-(1/f)));
CA = CA0*(1-X);
CB = CA0*(1-X);
rA = k*CA*(CB^0.5); % mol/liter*s
dXdV = rA/FA0;
end
I plugged it into the following code (all variables in eqn1 have been defined):
if true
Xspan = [0,0.5];
V0 = 0;
[X,V] = ode45(@adiabatic,Xspan,V0)
end

Best Answer

Your code is not easy to follow.
My guess is that this line is throwing the error:
k = kt*exp((E/R2)*((1/T0)-(1/f)));
The most likely solution is to evaluate ‘f’, since that changes it from a function handle to a function evaluation:
k = kt*exp((E/R2)*((1/T0)-(1/f(X))));
Related Question