필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
RD
RD 2020년 8월 29일
답변: Walter Roberson 2020년 8월 29일
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)

채택된 답변

Walter Roberson
Walter Roberson 2020년 8월 29일
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개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by