ODE23 errorline 114)

clc;clearvars; close all; format short g; format compact;
global PT S DELH Q CPA CPB CPC CPD NA NC NB ND NE NT;
PT = 1.5; % PT is total pressure in atmospheres
S = 0.05; % S= 0.5 square meters of area
DELH = 206014; % DELH is heat of reaction in Joules per gram mole
Q = 5000; % Heat input rate per unit lenth of bed (Joules/min-meter)
CPA = 36.9607; % specific heat (J/gmole-K)
CPB = 33.7295; % specific heat (J/gmole-K)
CPC = 29.1668; % specific heat (J/gmole-K)
CPD = 28.6455; % specific heat (J/gmole-K)
zz0 = 0.0;
zzf = 0.5;
YY0 = [3;3.5;0;0.000001;1300];
[zz,YY] = ode23('chrlspr3',zz0,zzf,YY0);
K = 0.45; % For now, K is assumed to be independent of temperature, K = constant
NA= YY(:,1);
NB= YY(:,2);
NC= YY(:,3);
ND= YY(:,4);
T = YY(:,5);
NE= .45* YY(:,3).* YY(:,2)./YY(:,4);
NT= NA+NB+NC+ND+NE;
plot(zz,NA,'r+',zz,NB,'g-')
title('MOLES/MIN versus REACTOR LENGTH')
xlabel(' Reactor Length')
ylabel('Gram-moles/min')
grid
pause, close
plot(zz,NC,'b-.',zz,ND,'y--',zz,NE,'r+')
title('MOLES/MIN versus REACTOR LENGTH')
xlabel(' Reactor Length')
ylabel('Gram-moles/min')
grid
pause, close
plot(zz,T)
title('TEMPERATURE versus REACTOR LENGTH')
xlabel('Reactor Length')
ylabel('TEMPERATUTE 0 K')
grid
function W =chrlspr3(zz,YY)
global PT S DELH Q CPA CPB CPC CPD NA NB NC ND NE NT T;
%S= 0.01;
NT =YY(1)+YY(2)+YY(3)+YY(4)+(0.45* YY(3)* YY(2)/ YY(4)); % Keq=0.45
NTCP=YY(1)*CPA + YY(2)*CPB + YY(3)*CPC + YY(4)*CPD; % Sigma Ni CP1
W(1)=-1.02*(10^6)*S*(0.10949*PT*YY(1)/NT)/(1+0.239*YY(2)/YY(4)+17.62*YY(3)*PT/NT);
W(2)=-1.02*(10^6)*S*(0.10949*PT*YY(1)/NT)/(1+0.239*YY(2)/YY(4)+17.62*YY(3)*PT/NT);
W(3)=1.02*(10^6)*S*(0.10949*PT*YY(1)/NT)/(1+0.239*YY(2)/YY(4)+17.62*YY(3)*PT/NT);
W(4)=3*1.02*(10^6)*S*(0.10949*PT*YY(1)/NT)/(1+0.239*YY(2)/YY(4)+17.62*YY(3)*PT/NT);
W(5)=(-S*DELH*W(3)+Q)/(NTCP); %DT/Dz equation
end

2 Comments

I get this type of problems frequently in My function(e.g chrlspr3 here) while using ODE. Kindly share any DOC. or link for debugging this . I use Online Matlab
The main file separately and the function separately doesn't throw any error. I have studied the ODE23 from MATLAB docs as well, Appreciate any suggestions on how to Debug this type error in future.
Thanks a Lot

Sign in to comment.

Answers (1)

Cris LaPierre
Cris LaPierre on 22 Dec 2020
Edited: Cris LaPierre on 22 Dec 2020
Read the full error message.
Error using odearguments (line 83)
The last entry in tspan must be different from the first entry.
Error in ode23 (line 114)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
The first error is the one you need to fix. You have not defined tspan correctly. Read more about what the correct inputs can be in the documenation. Also, you'll need to update the syntax used to call your ode function.
[zz,YY] = ode23(@chrlspr3,[zz0,zzf],YY0);
Then you'll get an error that CHRLSPR3 must return a column vector. Include a column index of 1 to each of your assignments to w in your ode function.

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 22 Dec 2020

Edited:

on 22 Dec 2020

Community Treasure Hunt

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

Start Hunting!