I cannot detect an error on Newton Method.

조회 수: 2 (최근 30일)
llucia
llucia 2023년 4월 6일
댓글: llucia 2023년 4월 6일
I am programming the Newton Method, but I doesn´t work. Someone could help me. I would really appreciate it.
I also want to plot the function but it does not work either.
I did the following:
x = a:0.01:x+10
plot (x,f(x))
And it did not work, because no graphic appeared.
I attached the code.

채택된 답변

VBBV
VBBV 2023년 4월 6일
function [x,n,error] = NewtonRaphson(f,a,eps_f,eps_x,df,maxits)
%>> df
% remaining code
x = a:0.01:x+10
plot (x,f(x))
end
Pass the anonymous function df into function NewtonRaphson
  댓글 수: 2
VBBV
VBBV 2023년 4월 6일
편집: VBBV 2023년 4월 6일
Or you can plot it outside the function as below
[x,n,error] = NewtonRaphson(f,a,eps_f,eps_x,df,maxits)
x = a:0.01:x+10;
plot (x,f(x))
%--------------------------------------------------->> df as argument
function [x,n,error] = NewtonRaphson(f,a,eps_f,eps_x,df,maxits)
% code
end
llucia
llucia 2023년 4월 6일
thanks a lot, that was what I needed! Regarding the "plot" part, should I write X instead of x when defining the x = a:0.01:x+10?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by