[scilab-Users] Re: Re: Can u help to write the code scilab to solve the transcendantal equation by Newton Raphson?

Stéphane Mottelet stephane.mottelet at utc.fr
Fri Jan 14 11:25:26 CET 2011


Hi,

Why not use the fsolve primitive of Scilab, which implements a more smarter
method (Powell method) than regular Newton's, and which does approximate
the derivative more precisely ?

function y=F(x)

   y=your formula;

endfunction

x=fsolve(x0,F);


S.

Le 14/01/2011 11:08, JOSE KANTOLE a écrit :
> Thank you for your feedback!
>
> On 1/13/11, Wojciech Artichowicz<w_artichowicz at o2.pl>  wrote:
>> Hello there,
>>
>>
>>
>> Here You have a quite general Newton-Raphson function.
>>
>> Just fill function F(x) and use the code below. :]
>>
>> good luck and best regards.
>>
>>
>>
>> function y=F(x)
>>
>>    y=your formula;
>>
>> endfunction
>>
>>
>>
>> function x1=NewtonRaphson(f,x0,Epsf,Epsx,h)
>>
>>    x1=x0;
>>
>>    if h==[] then, h=1e-10; end; //step for numerical derivative computation
>>
>>    while abs(f(x1))>Epsf | abs(x1-x0)>Epsx do //checking the condition to
>> finish iterations
>>
>>      x0=x1;
>>
>>      df=(f(x0+h)-f(x0-h))/(2.0*h); //numerical derivative (central scheme)
>>
>>      x1=x0-f(x0)/df;
>>
>>    end
>>
>> endfunction
>>
>>
>>
>>
>>
>>
>>
>> x0 = starting value,
>>
>> Epsf=0.0000000001;
>>
>> Epsx=0.00000001;
>>
>> h=0.0000000001;
>>
>> solution=NewtonRaphson(F,x0,Epsf,Epsx,h);
>>
>>




More information about the users mailing list