0
votes

Hi I am new to scilab and don't have much mathematical background. I have been following code for another example and am being shown error 10000 for the following code:

function [z]=f(x,y)
    z=0.026*(1.0-(y/ym))*y;
endfunction;

ym=12000;
x0=1950;y0=2555;xn=5;h=10;

x=[x0:h:xn];

y=ode("rk",y0,x0,x,f);

disp("x      y")
disp("--------")
disp([x'y']);

function z=fe(x)
z=ym/(1-(1-ym/y0)*e^(-k*(t-t0)));
endfunction;

xe=(x0:h/10:xn);

n=length(xe)
for i=1:n
    ye(i)=fe(xe(i));
end;

plot (x,y,'ro',xe, ye,'-b');legend ('rk4','Exact',3);
xtitle('solving dy/dx=k(1-y/ym)y','x','y');

I have worked through several other error messages. I am lost and don't know if the problem is in the code or the way I set up the problem. The following is the current error message:

!--error 10000 
plot: Wrong size for input argument #2: A non empty matrix expected.
at line      57 of function checkXYPair called by :  
at line     235 of function plot called by :  
plot (x,y,'ro',xe, ye,'-b');legend ('rk4','Exact',3);
at line      25 of exec file called by : 

I would appreciate any help. Thanks

1

1 Answers

0
votes

Start by adding clear as first statement, this will erase all variables before running your function. In the above script you don't declare ye.

Also the statement x=[x0:h:xn]; is strange with those values for x0,h and xn. You are now trying to get a list of x-values starting at 1950 and with positive steps of 10 up until 5 is reached.

I would recommend to try each line and see if the outcome is as expected. You do not need to know everything about the code, but probaly x and y should contain at least some values. The error is telling you that it expected a non-empty matrix for argument 2. This is y, so essentially it is telling you y is empty.