'How to define a function for ode in Scilab?
It shows that function f is not defined when executing u1 = ode
How can I define f correctly?
function xp,f(r,x,E)
e = 3.795;
m = 0.5111 * 10 ^ 6;
h = 1973;
xp(1) = x(2);
xp(2) = (((2*m) / (h*h)) * (-((e*e/r) - E))) * x(1);
endfunction
E1 = input ("Enter the 1st guess for energy :");
E2 = input ("Enter the 2nd guess for energy :");
rmin = 0.01;
rmax = 20;
h = 0.01;
for i = 1:100
r = rmin : h : rmax;
u1 = ode([0.01 ; 1], rmin, r, list(f,E1));
u2 = ode([0.01 ; 1], rmin, r, list(f,E2));
E3 = (E1 + E2)/2;
u3 = ode([0.01 ; 1], rmin, r, list(f,E3));
Solution 1:[1]
The definition of the function has to be fixed like this : output argument = f(input arguments)
function xp = f(r,x,E)
e = 3.795;
m = 0.5111 * 10 ^ 6;
h = 1973;
xp(1) = x(2);
xp(2) = (((2*m) / (h*h)) * (-((e*e/r) - E))) * x(1);
endfunction
and add an end to close your loop at the end. BW, the endfunction shows and the argument list for ode() show that you are using Scilab, not Octave (title and tags have been edited accordingly).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
