Newton's Method for finding zeros

19 visualizaciones (últimos 30 días)
Lucas Brockman
Lucas Brockman el 6 de Feb. de 2019
Respondida: Geoff Hayes el 7 de Feb. de 2019
I am trying to divide the function f(x0) by its derivitive df(x0), but Matlab keeps giving me errors about dividing by df(x0). My code is the following:
clear;
syms x f(x) f df(x) df
f = @(x) x.^2 - 3;
df = diff(f,x);
x0 = 1;
N = 6;
epsilon = 0.000001;
for t = 1:N
j = x0;
x0 = x0 - f(x0)/df(x0);
end
disp(x0)

Respuestas (1)

Geoff Hayes
Geoff Hayes el 7 de Feb. de 2019
Lucas - what errors are you observing? Please copy and paste the full error message to your question. Do you need to use the Symbolic Toolbox? Can't you define df as just
df = @(x)2*x;
Note how your code isn't using epsilon. How are you supposed to be using this value?

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by