Newton Divided Difference Method

I'm writing a code for interpolation using Newton's method. The code works but it gave me a different value. When I enter f(x) = log(x), x0=1, it gave me y=1 which is wrong. Can anyone help me?
syms x
d = input('enter f(x)= \n')
f=inline(d);
z=diff(f(x));
f1=inline(z);
x0=input('inter x0 = \n')
x=x0
for u=0:inf
y=x
x=y-(f(x)/f1(x));
if x==y
break
end
end
enter f(x)=
log(x)
d =
log(x)
inter x0 =
1
x0 =
1
x =
1
Warning: FOR loop index is too large. Truncating to 9223372036854775807.
y =
1
>>

回答(1 个)

Walter Roberson
Walter Roberson 2012-3-2

0 个投票

1 个评论

It gave me this error.
??? Maximum variable size allowed by the program is exceeded.
So I changed u=0:inf to u=0:n
And this is what I got
enter f(x)=
log(x)
d =
log(x)
enter x0 =
1
x0 =
1
x =
1
u =
0 1
y =
1

请先登录,再进行评论。

类别

提问:

2012-3-2

Community Treasure Hunt

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

Start Hunting!

Translated by