How can I get the second array value for my newton function
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
RD
le 29 Août 2020
Réponse apportée : Walter Roberson
le 29 Août 2020
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)
0 commentaires
Réponse acceptée
Walter Roberson
le 29 Août 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
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!