MATLAB: Error using odearguements (vector length)

MATLABode23

Hello,
I'm having some trouble with my code which is showing these errors:
Error using odearguments (line 95)
TANLFUN returns a vector of length 0, but the length of initial conditions vector is 2. The vector returned by TANLFUN and the
initial conditions vector must have the same number of elements.
Error in ode23s (line 121)
= odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in NLinear (line 27)
[tnl,xnl]=ode23s('tanlfun',tspan,xs);
I can't find where is the mistake and I'd grateful if some could shed some light on this issue. I'm pasting the code below. Thanks in advance!
NLinear
% Linear Model: LTI
LTI
% Entry Vector LTI
global u;
% Interval of Integration
ti=0; % initial, min
tf=10; % final, min
% Implementing the perturbation
%>>>> Fji (ft^3/min)
% step
Fjis=Fji;
Fji=1.1*Fji; % non-linear
u=[0 Fji-Fjis]'; % linear
% Non-linear simulation
tspan=ti:0.01:tf;
[tnl,xnl]=ode23s('tanlfun',tspan,xs);
% Linear simulation
tspan=ti:0.01:tf;
xo=zeros(size(xs));
[tl,xl]=ode23('talfun',tspan,xo);
% returns ss
Fji=Fjis; % ft^3/min
% Graphs
figure(1)
subplot(221); % T(oF)
plot(tnl,xnl(:,1),tl,xl(:,1)+xs(1));
title('Step in Fji');
xlabel('t (min)'); ylabel('T (oF)');
legend('nlinear','linear');
subplot(222); % Tj(oF)
plot(tnl,xnl(:,2),tl,xl(:,2)+xs(2));
title('Step in Fji');
xlabel('t (min)'); ylabel('Tj (oF)');
legend('nlinear','linear');
======================================
function dx=tanlfun(~,x)
global roCp rojCpj V Vj; % parameters
global UA Fi Ti Fji Tji Tst; % specs
% States
T=x(1); % oF

Tj=x(2); % oF
% Auxiliary Equation
Q=UA*(Tst-T);
% State Equations
dT= (Fi*roCp*Ti-Fi*roCp*T+Q)/(roCp*V);
dTj= (Fji*rojCpj*Tji-Fji*rojCpj*Tj-Q)/(rojCpj*Vj);
dx= [dT dTj]';
end
=====================================
function xdot=talfun(~,x)
% x=Ax+Bu
% y=Cx+Du
global talti; % LTI model
global u; % entry vector LTI
% LTI Model
A=talti.a;
B=talti.b;
xdot=A*x+B*u;
=============================
LTI Model
global talti;
%*** A ***
A(1,1) = -Fi/V-UA/roCp/V;
A(1,2) = UA/roCp/V;
A(2,1) = UA/rojCpj/Vj;
A(2,2) = -Fji/Vj-UA/rojCpj/Vj;
%*** B ***
B(1,1) = (Ti-T)/V;
B(1,2) = 0;
B(1,3) = Fi/V;
B(1,4) = 0;
B(2,1) = 0;
B(2,2) = (Tji-Tj)/Vj;
B(2,3) = 0;
B(2,4) = Fji/Vj;
%*** C ***
C = eye(size(A));
%*** D ***
D = zeros(size(B));
% Creating LTI model: space of state
talti=ss(A,B,C,D);

Best Answer

One or more of the global variables you use are undefined at the time they are used. The default value for a variable marked global is [] and computing with [] results in []
You should avoid using global.