Unrecognised function when using ode23 in a live script
显示 更早的评论
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
回答(1 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Thermal Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!