# Why am I getting Undefined function or variable 'kp' despite having defined it in the code?

3 views (last 30 days)
StillANovice on 20 Jul 2018
Reopened: Walter Roberson on 22 Dec 2018
% Kinetics
Rp = (kp).*rho.*A(1).*((2.*ki.*((rho.*A(1).^3)))./ktc).^0.5;
% Formulae
ki = 2.019.*10.*exp(-13810./A(2)); % m6/kg.s
kp = 1.009.*(10.^5).*exp(-3557./A(2)); % m3/kg.s
%kp = 100900;
ktc = 2.205.*(10.^7).*exp(-844./A(2)).*exp(-2.*((A1.*wp)+(A2.*(wp.^2))+(A3.*(wp.^3)))); % m3/kg.s
A1 = 2.57-((5.05.*0.001).*A(2));
A2 = 9.56-((1.76.*0.01).*A(2));
A3 = -3.032+((7.85.*0.001).*A(2));
rho = 845-(A(2)-353)+((200+(A(2)-353)).*wp); % kg/m3
wp = 1-A(1);
% Parameters
deltaH = -6.7.*(10.^5); % J/kg
cp = 1.884.*1000; % J/kg.K
% Mass balance
% Energy balance
end
To call the function:
tspan = [0 40000];
% Initial conditions
A1_0 = 1;
A2_0 = 360;
End
Error:
Undefined function or variable 'kp'.
Rp = (kp).*rho.*A(1).*((2.*ki.*((rho.*A(1).^3)))./ktc).^0.5;
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);

Aquatris on 20 Jul 2018
Edited: Aquatris on 20 Jul 2018
Becuase you define "kp" variable a little late. From your polyadiabatic function;
% Kinetics
Rp = (kp).*rho.*A(1).*((2.*ki.*((rho.*A(1).^3)))./ktc).^0.5; % THIS REQUIRES kp VARIABLE
% Formulae
ki = 2.019.*10.*exp(-13810./A(2)); % m6/kg.s % HERE IS WHERE YOU DEFINE kp VARIABLE
kp = 1.009.*(10.^5).*exp(-3557./A(2)); % m3/kg.s
You will get a similar error for A1, A2, A3, and wp variables as well. Put them in the beginning of the function, before you use them.
StillANovice on 20 Jul 2018
You are a star, thank you!