Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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)

Risposta accettata

Walter Roberson
Walter Roberson il 29 Ago 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

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by