0

I'm trying to solve a differential algebraic equation and keep getting the following error:

Function definitions in a script must appear at the end of the file. Move all statements after the "pscalc" function definition to before the first local function definition.

%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);

Not sure how to fix it.

Any help is apppreciated.

mo farah
  • 23
  • 5
  • The error is pretty clear. Move the function definition of `pscalc` at the end of the script – Sardar Usama Apr 14 '18 at 13:27
  • *Not sure how to fix it.* ---> *Move all statements after the "pscalc" function definition to before the first local function definition.* – CroCo Apr 16 '18 at 16:49

0 Answers0