MATLAB: Error “Not enough input arguments” for a ode-function

odefun

Hi,
I am writing a progrem with Matlab for the solution of a system of differential equations.
The program is:
% Orto-xylene oxidation in an adiabatic PFR.
% ethylbenzene -> Anhydrated-xylene + H2
% Water as an inert in the system
global y0 F0 deltaHR0 P0 ni n
y0(1) = 0.0769; % ethylbenzene
y0(2) = 0.; % styrene
y0(3) = 0.; % hydrogen
y0(4) = 0.923; % water
Feed = 1105.; % F01 + FH2O Feed rate [mol/s]
F0 = Feed .* y0; % Inlet feed rate of components [mol/s]
Tin = 925.;
n = 4.; % Number of reacting compound
deltaHR0 = 124850.; % heat of reaction at standard conditions[J/mol]
P0 = 240000.; % pressure [Pa]
W = 25400.; % reactor weight [kg]
ni = [-1 1 1 0]; % Stoichiometric matrix
% Initial conditions (feed and T0)
u0 = F0;
u0(n+1) = Tin;
wspan = [0 W];
[w_adiab,u] = ode15s(dfuns,wspan,u0);
conv_adiab = 1 - u(:,1)/F0(1);
T = u(:,n+1);
%function file dfuns
function f = dfuns (w,U)
global y0 F0 deltaHR0 P0 ni n
y = U(1:n)/sum(U(1:n)); % molar fractions

T = U(n+1);
k = 3.46* 10e8.* exp(-10980./T); %Needs to be in Pascal

K = 8.2.* 10e11.* exp(-15200./T); %Needs to be in Pascal
rm = k.* (y(1)* P0- (y(2).* y(3).*(P0^2))./ K);
f(1:n) = -ni(1:n).* rm;
Cp1 = 37.778 + 87.940e-3.* T + 113.436e-5.* T^2; % ethylbenzene
Cp4 = 36.540 - 34.827e-3.*T + 11.681e-5.*T^2; % water
deltaCp = 0.;
deltaHR = deltaHR0;
f(n+1) = (1./((F0(1)+F0(4)).* (y(1).* Cp1 + y(4).* Cp4 +y(1).* deltaCp)*...
(1 - U(1)/F0(1)))).*-deltaHR.* rm;
f = f'; % transformation to column vector
The error I get is in the function at the line:
y = U(1:n)/sum(U(1:n)); % molar fractions
and states:
Error: File: catPFR.m Line: 37 Column: 1 Function definitions are not permitted in this context.
I don't really understand this: my function seems to have enough inputs to me. Do you? Can you help me?

Best Answer

I haven't looked at the code in detail, but the 1st argument of the ode15s call should be a function handle. E.g.,
[w_adiab,u] = ode15s(@dfuns,wspan,u0);
Related Question