Error "Not enough input arguments" for a ode-function

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?

 Respuesta aceptada

James Tursa
James Tursa el 12 de Mayo de 2015
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);

2 comentarios

Thank you very much for your answer and for shifting my situation from "error" to "warning". :-)
I now read in my Command Window:
Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN.
and then, after many other warnings:
Warning: Failure at t=0.000000e+00. Unable to meet integration tolerances without reducing the step size below the
smallest value allowed (7.905050e-323) at time t.
I think there might be a problem with the dimensions of some of the vectors I defined but i struggle to see which one and why.
James Tursa
James Tursa el 12 de Mayo de 2015
LOL ... yeah, if it needs a stepsize smaller than e-323 it looks like trouble!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 12 de Mayo de 2015

Comentada:

el 12 de Mayo de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by