Newton Divided Difference Method

3 views (last 30 days)
Akmal
Akmal on 2 Mar 2012
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
>>

Answers (1)

Walter Roberson
Walter Roberson on 2 Mar 2012
  1 Comment
Akmal
Akmal on 2 Mar 2012
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

Sign in to comment.

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!