필터 지우기
필터 지우기

Stuck at coding newton-Rapson method

조회 수: 3 (최근 30일)
seoung gi Sin
seoung gi Sin 2022년 4월 10일
편집: Stephen23 2022년 4월 10일
I inputed the number exp(-x) into an input and 3 into x0
but the Matlab says that Index exceeds the number of array elements, index must not exceed 1
Could you solve this problem for me, Thanks in advance.
clear all
clc
syms x;
fun=input('Enter the function as a variable of x');
f=inline(fun);
f2=diff(f(x));
x0=input('Enter the initial value of interval');
z=[];
error=10^-8;
tol=inf;
i=0;
z(1)=x0;
while tol>error
i=i+1;
z(i+1)=z(i)-(f(z(i))/f2(z(i)));
error=(z(i+1)-z(i))/z(i+1);
end
  댓글 수: 1
Stephen23
Stephen23 2022년 4월 10일
편집: Stephen23 2022년 4월 10일
Why learn how to code using deprecated functions? https://www.mathworks.com/help/matlab/ref/inline.html

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

답변 (1개)

KSSV
KSSV 2022년 4월 10일
Replace this line:
f2=diff(f(x));
with
f2=inline(diff(f(x)));

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by