Assignment 1 - FW03

Question 5

>    restart;

>    Digits:=6;

Digits := 6

>    g:=diff((x+1)*ln(x-1),x);

g := ln(x-1)+(x+1)/(x-1)

Forward difference formula

>    fdf:=((x+h+1)*ln(x+h-1)-(x+1)*ln(x-1))/h;

fdf := ((x+h+1)*ln(x+h-1)-(x+1)*ln(x-1))/h

Central difference formula

>    cdf:=((x+h+1)*ln(x+h-1)-(x-h+1)*ln(x-h-1))/2/h;

cdf := 1/2*((x+h+1)*ln(x+h-1)-(x-h+1)*ln(x-h-1))/h

>    x:=1.2;

x := 1.2

Exact result

>    g;

9.39056

Values from foward difference formula

>    for n from 1 to 6 do

>    h:=10^(-n);

>    fdf;

>    od;

h := 1/10

7.71640

h := 1/100

9.17300

h := 1/1000

9.38000

h := 1/10000

9.40000

h := 1/100000

10.0000

h := 1/1000000

0.

The most accurate value is obtained fopr h = 0.0001.  For smaller vaues the results get worse.

Values from central difference formula

>    for n from 1 to 6 do

>    h:=10^(-n);

>    cdf;

>    od;

h := 1/10

10.3316

h := 1/100

9.39800

h := 1/1000

9.39500

h := 1/10000

9.40000

h := 1/100000

9.50000

h := 1/1000000

0.

The most accurate value is for h = 0.001.

>