matlab - Developing a Secant Method Program for root finding -


so have been trying develop secant method program can used finding root of

f(x) = tanh(x) - (x / 3)

however answer output close. every solution have found seems more complex way solve it.

    x = 2; prevx = x;  = 1:20      x = x - (tanh(x)-(x/3))*((x-(prevx))/((tanh(x)-(x/3))-(tanh(prevx))-((prevx/3))));     prevx = prevx + x;     x end 

the answer should 2.987. getting negative number though reason.

you suppose add terms replace minus in line:

x = x - (tanh(x)-(x/3))*((x-(prevx))/((tanh(x)-(x/3))-(tanh(prevx))-((prevx/3)))); 

to plus:

x = x + (tanh(x)-(x/3))*((x-(prevx))/((tanh(x)-(x/3))-(tanh(prevx))-((prevx/3)))); 

to desired result of 2.987 x. remove x before end of loop.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -