Borrar filtros
Borrar filtros

How can I get the second array value for my newton function

1 visualización (últimos 30 días)
I'm trying to modify my code to 'store the initial guess and each of the results of N iterations of Newton's Method in a 1x(N+1) array' but I can't figure out why my second root approximation isn't showing.
This is what I have so far, any help would be appreciated.
clc
clear
% Function nto find root of
f = @(x) 3*x.^4- 2*x.^3 - 3*x.^2 + 2*x - (1/5);
%derivatieve
d = @(x) 12*x.^3 -6*x.^2 - 6*x + 2;
N = 2;
x = -2;
approxArray = [x];
for n = 1 : 1 : N
approxroot = ((x) - (f(x)./d(x)));
x = approxroot;
approxArray(N+1) = x;
end
disp(approxArray)

Respuesta aceptada

Walter Roberson
Walter Roberson el 29 de Ag. de 2020
approxArray(N+1) = x;
N is constant inside the loop, so you are always overwriting the same location. The variable that is keeping track of where you are in the loop is n

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements 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