Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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)

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 29 Aug. 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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by