0% found this document useful (0 votes)
15 views6 pages

NC Ass

The document contains exercises for calculating approximations and actual errors for the functions f(x) = tan x and f(x) = exp(x/3) + x^2. It includes a detailed code implementation in MATLAB for deriving derivatives, calculating errors, and presenting results. The results include actual derivative values, derived derivatives, and the corresponding errors for specified x values.

Uploaded by

alihamza5808062
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views6 pages

NC Ass

The document contains exercises for calculating approximations and actual errors for the functions f(x) = tan x and f(x) = exp(x/3) + x^2. It includes a detailed code implementation in MATLAB for deriving derivatives, calculating errors, and presenting results. The results include actual derivative values, derived derivatives, and the corresponding errors for specified x values.

Uploaded by

alihamza5808062
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Question No 9 and 11

9. Use the formulas given in this section to determine, as accurately as possible, approximations for
each missing entry in the following tables.

11. The data in Exercise 9 were taken from the following functions. Compute the actual errors in
Exercise 9, and find error bounds using the error formulas and Maple.

a. f (x) = tan x
(x) f(x) f’(x)

2.1 −1.709847

2.2 −1.373823

2.3 −1.119214

2.4 −0.9160143

2.5 −0.7470223

2.6 −0.6015966

CODE
clc
clear
format long
syms x

f=@(x) (exp(x/3)) + (x^2)

x0= 2.1
x1= 2.2
x2= 2.3
x3= 2.4
x4= 2.5
x5= 2.6

y0= -1.709847
y1= -1.373823
y2= -1.119214
y3= -0.9160143
y4= -0.7470223
y5= -0.6015966

AD=diff(f(x),x,1)
%ACTUAL DERAVATIVE
ADX0=eval( subs(AD,x,x0))
ADX1=eval( subs(AD,x,x1))
ADX2=eval( subs(AD,x,x2))
ADX3=eval( subs(AD,x,x3))
ADX4=eval( subs(AD,x,x4))
ADX5=eval( subs(AD,x,x5))

h=x1-x0
%DERIVED DERAVATIVE
D0=(1/(2*h))* [-3*(y0)+4*(y1)-(y2)]
D1=(1/(2*h))* [-y0+y2]
D2=(1/(2*h))* [(y0)-4*(y1)+3*(y2)]
D3=(1/(2*h))* [(y1)-4*(y2)+3*(y3)]
D4=(1/(2*h))* [-y3+y5]
D5=(1/(2*h))* [(y3)-4*(y4)+3*(y5)]
%ERRORS
E0=ADX0-D0
E1=ADX1-D1
E2=ADX2-D2
E3=ADX3-D3
E4=ADX4-D4
E5=ADX5-D5

SOLUTION
AD =

2*x + exp(x/3)/3
ADX0 =

4.871250902490159

ADX1 =

5.094003028026152

ADX2 =

5.317526339439862

ADX3 =

5.541846976164155

ADX4 =

5.766991963630941

ADX5 =

5.992989243302212

h = 0.100000000000000

D0 = 3.767314999999994

D1 = 2.953164999999997

D2 = 2.139015000000000

D3 = 1.774950499999999

D4 = 1.572088499999998

D5 = 1.336425499999999

E0 = 1.103935902490165

E1 = 2.140838028026155

E2 = 3.178511339439862

E3 = 3.766896476164156

E4 = 4.194903463630943

E5 = 4.656563743302213
b. f (x) ¿e +x
x /3 2

(x) f(x) f’(x)

−3.0 9.367879

−2.8 8.233241

−2.6 7.180350

−2.4 6.209329

−2.2 5.320305

−2.0 4.513417

CODE
clc
clear
format long
syms x

f=@(x) (exp(x/3)) + (x^2)

x0= -3.0
x1= -2.8
x2= -2.6
x3= -2.4
x4= -2.2
x5= -2.0

y0= 9.367879
y1= 8.233241
y2= 7.180350
y3= 6.209329
y4= 5.320305
y5= 4.513417

AD=diff(f(x),x,1)
%ACTUAL DERAVATIVE
ADX0=eval( subs(AD,x,x0))
ADX1=eval( subs(AD,x,x1))
ADX2=eval( subs(AD,x,x2))
ADX3=eval( subs(AD,x,x3))
ADX4=eval( subs(AD,x,x4))
ADX5=eval( subs(AD,x,x5))

h=x1-x0
%DERIVED DERAVATIVE
D0=(1/(2*h))* [-3*(y0)+4*(y1)-(y2)]
D1=(1/(2*h))* [-y0+y2]
D2=(1/(2*h))* [(y0)-4*(y1)+3*(y2)]
D3=(1/(2*h))* [(y1)-4*(y2)+3*(y3)]
D4=(1/(2*h))* [-y3+y5]
D5=(1/(2*h))* [(y3)-4*(y4)+3*(y5)]
%ERRORS
E0=ADX0-D0
E1=ADX1-D1
E2=ADX2-D2
E3=ADX3-D3
E4=ADX4-D4
E5=ADX5-D5

SOLUTION
AD =

2*x + exp(x/3)/3

ADX0 =

-5.877373519609519

ADX1 =

-5.468919759710467

ADX2 =

-5.059883205163773

ADX3 =

-4.650223678627593

ADX4 =

-4.239898232970067

ADX5 =
-3.828860960322469

h = 0.200000000000000

D0 = -5.877557499999996

D1 = -5.468822499999996

D2 = -5.060087499999990

D3 = -4.650429999999992

D4 = -4.239779999999998

D5 = -3.829100000000004

E0 = 1.839803904770676e-04

E1 = -9.725971047025439e-05

E2 = 2.042948362168673e-04

E3 = 2.063213723992874e-04

E4 = -1.182329700695206e-04

E5 = 2.390396775346915e-04

You might also like