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

3 views (last 30 days)
function dAdT = polyadiabatic(T,A)
dAdT = zeros(2,1);
% 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
dAdT(1) = -(Rp./rho);
% Energy balance
dAdT(2) = -(Rp.*deltaH)./(cp.*rho);
end
To call the function:
function [T,A] = call_polyadiabatic()
tspan = [0 40000];
% Initial conditions
A1_0 = 1;
A2_0 = 360;
[T,A] = ode45(@polyadiabatic,tspan,[A1_0 A2_0]);
End
Error:
call_polyadiabatic
Undefined function or variable 'kp'.
Error in polyadiabatic (line 5)
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);
Error in call_polyadiabatic (line 9)
[T,A] = ode45(@polyadiabatic,tspan,[A1_0 A2_0]);

Accepted Answer

Aquatris
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.

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!