Newton's method in Matlab

1 visualización (últimos 30 días)
piniaw15
piniaw15 el 10 de Nov. de 2015
Comentada: Thorsten el 11 de Nov. de 2015
I need to apply Newton's Method in Matlab to the function f(x)= a-(1/x) to show how a program which cannot do division can be used to compute 1/a for a>0. How would I proceed? Thanks.

Respuestas (1)

Thorsten
Thorsten el 10 de Nov. de 2015
Editada: Thorsten el 10 de Nov. de 2015
Approximation of 1/a by x using a suitable starting value x = 0.1:
a = 14; x = 0.1; while abs(x*a - 1) > eps, x = x*(2-a*x), end
  2 comentarios
piniaw15
piniaw15 el 10 de Nov. de 2015
Hi, I used newtons method to get to x = x*(2-a*x)
But I don't understand what you've done here: abs(x*a - 1) > eps Can you explain please?
Thorsten
Thorsten el 11 de Nov. de 2015
The value x should approximate 1/a, so x*a should approximate 1, or abs(x*a - 1) should approximate 0. I don't check for 0 because this is numerically not stable; instead, I check against the machine precision eps. The loop continuos until this precision is reached. If you need less precision, you could use, e.g.
while abs(x*a - 1) > 1e-6,

Iniciar sesión para comentar.

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by