Unrecognised function when using ode23 in a live script
Show older comments
The following code is meant to calculate the height of fluid in two tanks using non-linear differential equations.
The line [t,h]=ode23(...) calls the function 't_fun' (listed in the second code block). While the code works in a normal script, I keep getting an 'Unrecognised function or variable 't_fun' error.
Any ideas as to why this may be occurring would be appreciated.
clc;
clear;
close all;
global BETA1 BETA2 AREA1 AREA2 DENSITY IN_OPTION MASSIN;
BETA1=40; % tank 1 outlet valve coefficient
BETA2=50; % tank 2 outlet valve coefficient
AREA1=3; % cross section of tank 1
AREA2=4; % cross section of tank 2
DENSITY=1000; % liquid density
IN_OPTION=1; % (1)=steady; (2)=cycle input off/on (see t_fun.m)
MASSIN=200; % flow rate of liquid into tank 1
t0=0; % start time of simulation
tf=2000; % end time of simulation
h0=[4 30]'; % initial liquid levels in the tanks
[t,h]=ode23('t_fun',[t0 tf],h0);
% plot results
In the live script a section break would be placed here.
function h_dot=t_fun(t,h)
global BETA1 BETA2 AREA1 AREA2 DENSITY IN_OPTION MASSIN;
if h(1)<0; h(1)=0; end; % needed if the integration step empties the tank.
if h(2)<0; h(2)=0; end; % needed if the integration step empties the tank.
% let the mass inflow oscillate between zero and MASSIN
if IN_OPTION==1; mass_in=MASSIN; end;
if IN_OPTION==2
if sin(2*pi*t/300)>0
mass_in=MASSIN;
else
mass_in=0;
end;
end;
h_dot(1)=(-BETA1/(AREA1*DENSITY)).*sqrt(h(1))+mass_in/(AREA1*DENSITY);
h_dot(2)=(BETA1/(AREA2*DENSITY)).*sqrt(h(1))-(BETA2/(AREA2*DENSITY)).*sqrt(h(2));
h_dot=h_dot';
end
Answers (1)
N/A
on 18 Mar 2020
Categories
Find more on Thermal Analysis 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!