You are on page 1of 7

HOMEWORK 3 (Numerical Analysis)

Student Name: AYECH Nabil 那比尔


Student ID: LB2115201

EXERCICE 5.2

(a) Calculate fitting a straight line - Curve fitting using least square method

X Y
1 -5
1.2 -3
1.4 -2
1.6 0
1.8 3

Solution:

Straight line equation is y = a+bx.

The normal equations are


∑y = an+b∑x
∑xy = a∑x+b∑x2

The values are calculated using the following table

x y x2 x⋅y
1 -5 1 -5
1.2 -3 1.44 -3.6
1.4 -2 1.96 -2.8
1.6 0 2.56 0
1.8 3 3.24 5.4
--- --- --- ---
2
∑x=7 ∑y=-7 ∑x =10.2 ∑x⋅y=-6

Substituting these values in the normal equations


5a + 7b = -7
7a + 10.2b = -6

Solving these two equations using Elimination method,

5a + 7b = -7
and, 7a + 10.2b = -6

5a + 7b = -7→(1)
7a + 10.2b = -6→(2)

equation (1)×7 ⇒ 35a + 49b = -49

1
equation (2)×5 ⇒ 35a + 51b = -30

Substracting ⇒ -2b = -19


⇒ 2b = 19
⇒ b = 192
⇒ b = 9.5

Putting b = 9.5 in equation (1), we have

5a + 7(9.5) = -7
⇒5a = -7-66.5
⇒5a = -73.5
⇒a = -73.55
⇒a = -14.7

∴a = -14.7and b = 9.5

Now substituting this values in the equation is y = a + bx, we get

y = -14.7 + 9.5x

(b) Calculate Fitting a straight line - Curve fitting using Least square method

X Y
0 3
1 1.2
2 -0.3
3 -1.5

Solution:

Straight line equation is y=a+bx.

The normal equations are


∑y = an + b∑x
∑xy = a∑x + b∑x2

The values are calculated using the following table

x y x2 x⋅y
0 3 0 0
1 1.2 1 1.2
2 -0.3 4 -0.6
3 -1.5 9 -4.5
--- --- --- ---
∑x=6 ∑y=2.4
=2.4 ∑x2=14 ∑x⋅y=-3.9

2
Substituting these values in the normal equations
4a + 6b = 2.4
6a + 14b = -3.9

Solving these two equations using Elimination method,

4a + 6b = 2.4
and, 6a + 14b = -3.9

4a + 6b = 2.4 → (1)
6a + 14b = -3.9 → (2)

equation (1)×3 ⇒ 12a + 18b = 7.2

equation (2)×2 ⇒ 12a + 28b = -7.8

Substracting ⇒-10b = 15
⇒10b = -15
⇒b = -1510
⇒b = -32
⇒b = -1.5

Putting b = -1.5 in equation (1), we have

4a + 6(-1.5) = 2.4
⇒4a = 2.4+9
⇒4a = 11.4
⇒a = 11.44
⇒a = 2.85

∴a = 2.85and b = -1.5

Now substituting this values in the equation is y = a + bx, we get

y = 2.85 - 1.5x

3
EXERCICE 5.5

(a) Graphically determine which guess function suits to fit:

g(x) = αeβx h(x) = αxβ

The following data:

P1(1, 2.3); P2(2, 6.1); P3(3, 10.7); P4(4, 16.0); P5(5, 21.9); P6(6, 28.3)

Graphically the best guess function to suits the data is: h(x) = αxβ

(b) Using Linearization Algorithm to fit g(x) and h(x):

For g(x) = αeβx:

X Y
1 2.3
2 6.1
3 10.7
4 16
5 21.9
6 28.3

4
Solution:

The curve to be fitted is g(x) = αeβx

Taking logarithm on both sides, we get

log10(g(x)) = log10(α) + βxlog10(e)


Y = A + Bx where Y = log10(g(x)), A = log10(α), B = βlog10(e)

Which linear in Y,x

So the corresponding normal equations are

∑Y = nA + B∑x
∑xY = A∑x + B∑x2

The values are calculated using the following table


x g(x) Y=log10(g(x)) x2 x⋅Y
1 2.3 0.3617 1 0.3617
2 6.1 0.7853 4 1.5707
3 10.7 1.0294 9 3.0882
4 16 1.2041 16 4.8165
5 21.9 1.3404 25 6.7022
6 28.3 1.4518 36 8.7107
--- --- --- --- ---
∑x=21 ∑ g(x)=85.3 ∑Y=6.1728 ∑x2=91 ∑x⋅Y=25.25

Substituting these values in the normal equations

6A + 21B = 6.1728
21A + 91B = 25.25

Solving these two equations using Elimination method,


we obtain A = 0.2998 , B = 0.2083

∴ α = antilog10(A) = antilog10(0.2998) = 1.9942

and β = Blog10(e) = 0.20830.4343 = 0.4796

Now substituting this values in the equation is g(x)=αeβx, we get

g(x) = 1.9942e0.4796x

5
For g(x) = αeβx, in which E(g) = ∑[g(xk) – yk]2

xk g(x) [g(xk) – yk]2

1 2.3 0.84915672
2 6.1 0.802454
3 10.7 5.25701071
4 16 5.84927865
5 21.9 0.00162660
6 28.3 51.03299975

∑x=21 ∑ g(x)=85.3 ∑=63.79252643

E(g) = ∑[g(xk) – yk]2 = 63.79252643

For h(x) = αxβ:

X Y
1 2.3
2 6.1
3 10.7
4 16
5 21.9
6 28.3

Solution:

The curve to be fitted is h(x) = αxβ

Taking logarithm on both sides, we get

log10(y) = log10(α) + βlog10(x)


Y = A + βX where Y = log10(h(x)), A = log10(α), X = log10(x)

Which linear in Y, X
So the corresponding normal equations are

∑Y = nA + β∑X
∑XY = A∑X + β∑X2

The values are calculated using the following table


x h(x) X=log10(x) Y=log10(h(x)) X2 X⋅Y

1 2.3 0 0.3617 0 0
2 6.1 0.301 0.7853 0.0906 0.2364
3 10.7 0.4771 1.0294 0.2276 0.4911

6
4 16 0.6021 1.2041 0.3625 0.725
5 21.9 0.699 1.3404 0.4886 0.9369
6 28.3 0.7782 1.4518 0.6055 1.1297

∑x=21 ∑ h(x) =85.3 ∑X=2.8573 ∑Y=6.1728 ∑X2=1.7748 ∑X⋅Y=3.5191

Substituting these values in the normal equations

6A + 2.8573β = 6.1728
2.8573A + 1.7748β = 3.5191

Solving these two equations using Elimination method,

we obtain A = 0.3624, β = 1.3994

:. α = antilog10(A) = antilog10(0.3624) = 2.3034

Now substituting this values in the equation is

h(x) = 2.3034 x1.3994

For h(x) = αxβ, in which E(h) = ∑[h(xk) – yk]2

xk h(x) [h(xk) – yk]2

1 2.3 0.0000101
2 6.1 0.0005754
3 10.7 0.0002755
4 16 0.0008441
5 21.9 0.0001998
6 28.3 0.0008215

∑x=21 ∑ h(x)=85.3 ∑=0.0027264

E(h) = ∑[h(xk) – yk]2 = 0.0027264

From the results of E(g) and E(h), we conclude that h(x) is better guess function to the presented data.

You might also like