简易MatLab Q-ode15s

简易MatLab Q-ode15s,matlab,ode,Matlab,Ode,我试图解一个微分代数方程,并不断得到以下错误: 脚本中的函数定义必须显示在文件末尾。 将“pscalc”函数定义之后的所有语句移动到第一个本地函数之前 定义 %prompt = 'Enter the radius of the sphere (m): '; %R = input(prompt); %prompt = 'Enter the area of the outlet of the sphere (m): '; %A = input(prompt); g = 9.81; % m2

我试图解一个微分代数方程,并不断得到以下错误:

脚本中的函数定义必须显示在文件末尾。 将“pscalc”函数定义之后的所有语句移动到第一个本地函数之前 定义

%prompt = 'Enter the radius of the sphere (m): ';
%R =  input(prompt);

%prompt = 'Enter the area of the outlet of the sphere (m): ';
%A =  input(prompt);

g = 9.81;  % m2/s
R = 10;    %radius
A = 0.1; % outlet area m^2

y0 = [0; 19.99];
tspan = [0 3600];

function out=pscalc(t,y)
out = [y(1)*((pi/A)*y(2)-(R/A)-g*y(2))
      (A/(pi*((y(2))^2 - (2*R*y(2))))*((y(1))^2+ 2*g*y(2)))];
end

[t,y]=ode15s(@pscalc, tspan, y0);
我不知道怎么修


需要任何帮助。

错误很明显。移动脚本末尾的
pscalc
函数定义不确定如何修复。-->将“pscalc”函数定义之后的所有语句移动到第一个本地函数定义之前。