Week 4:
Question 1:
3
3.842 8.6x 24.4 0
=
x
-
-
+
a) f(x) 3x2
=
+
7.6X -
8.6 0 =
initiallyx 2 =
x (0) 2
=
we know x(n +1) x(n) =
-
f(x(n)) /f(x(n))
SO
1) x, 2
=
-
f(2)/f1(2)
2
=
-
(2 +
3.8(2)- 8.6(2) -
24.4)/(3(2)" 7.6(2) 8.6)
+
-
2.9892
=
2) x2 2.9892
=
- f(2.9892)/f(2.9892) 2.9892
=
-
10.5585/40.9251 2.7313
=
f(2.7312)/f(2.7512) 08327/34.5357 2.7071
3) X3 2.7312 2.7312 =
= -
-
=
2.7069
S
xx = 2.7071 -
f(27071)/f(2.7071) 2.7071
=
-
0007/33.9601 =
x5 2.7009
=
-
f(2.7069)/f(2.1069) 2.7069
=
out:
xs working
f(2.7069) 2.70693 3.8(2.7069)2
=
+
-
8.6(2.7069) -
24.4 0
=
f(2.7069) 3(2.7069)2
=
7.6(2.7069)
+
-
8.6 33.9553
=
45
599553
2.7069 2.7069.
=
so the approximate rootofthe equation
using Newton Raphson method is 1.2009
b) Graph:
continues on next page
1) I chose 40 = 2 and x = 3
f(x) 18.4, + (x) 11
=
=
-
...
X2 x1
= -
f(x,).xi -
40
f(X,) -
.)(X0)
x c 3 (11).3-2
= -
7.6259
=
11 ( 18(4) - -
f(x) 2.52593 3.8(2.6259)2
= +
-
8.6(2.6259) -
24.4 =
-
2.6755
2)x, 3,x2 2.6259,f(X,) 11,f(x)
=
=
=
=
-
2.6755
3 2.699
x
3 2.6259 1 2.6755).2.6259
=
- =
- -
-
2.6755 -
11
f(X3) (2.699(3 3.8(2.699)"
= +
-
8.6(2.699) -
24.4 =
- 0.267)
3) x2 2.6259,x3 2.699,f(x)
=
=
=
-
2.6755,f(y3) =
= 0.2671
x 4 2.699
=
-
1- 0.2671).2699 -
2.6259 2.7072
=
0.2671 -
1 2.6755)
-
f(xy) (2.7072)3 3.8(2.2072)"
=
+ -
8.5(2.7072) -
24.4 0.0018
=
4) x3
=
2699,xy 2.7072,f(xz) =
= -
0.252),f(x+) 0.0078
=
x5 2.7072 = -
0.0078.27072 -
2699 2.7009
=
0.0078 -
( 0.2671)
-
f(x5) (2.2069)3
=
3.8(2.7069)"
+
-
8.6(2.2069) -
24.4 = =
0.00002
5) xy 2.7072,x3
= =
2.2069, f(x) 0.0028,
=
f(x) = -0.0000)
x0 2.7069 000002.2.7069 2.7072 2.7069
-
=
-
=
-0.000022
-
0.001
f(x0) (2.7069)3
=
3.8(2.706972
+ -
8.6(2.7069) -
24.4 0 =
so the approximate (smallest) rootofthe equation
using the secant method
is
1.7069
The result
using both methods is equal (2.7009). Yet, itseems
through this
example that the method faster during the iteration f(x) = 0
secant
converges as ith
and f(x) is then exacty 0. However itseems thatthe
rate of
convergence depends on many
factors like the function and initial estimates chosen.
Question 2:
2rsin0
z
x
=
x =
30
SO 1 2usinG
=
2 30
&rSinG 30r =
4 sino-38 0 =
1) I sin (1) -
3 0.36588394
=
↑sin (2) - 6
-
=
2.36281029
40 = 1 2
+
1.5
=
&sin (15) -
3(1.5) = -
0.51002005 <0
so b 1.5
=
a 1
=
I
2)
1
x, 1
=
+
1.5 1.25
=
error =
1.25 -
1.5 = 0.1667
2
15
4 sin (1.25) -
3(125) 0.04593848)8
=
to| 11.5
=
-
1.251/2 0.125 =
a 1.25 b 1.5
=
1.25 15 = 1.375
3)
5-125
0.1
+
x2 =
error =
=
↑sin (1.575) -
3(1375) =
-
0.2014272770 +01 11375
=
-
1.251/2 =
0.0625
b 1.375 =
a 1.25
=
4) x3 1.25 1.375
=
+
1.3125
=
error 1.3125
= - 1.375 =
0.04545
2
1.375
4 sin (1.3125) -
3(13125) = -0.07019377 <0 (0) (1.3125 1.25)/2
=
- =
b 1.3125
=
a = 1.25 0.03125
5) 1.25 1.28125
1.3125
xp =
+ 1.28125
=
error =
- 13125 0.0238
=
1.3125
4 sin (1.28125) -
3(1.22125) = -
0.01025598 < o
b =
1.28125 a 1.25
=
t0 =
11.28125 -
1.25)/2 =
0.015625
6) x5 1.25
=
128125 1.265625
+
=
error: 1.265613 -
1.28125 =
2 120125 0.01219
4 sin (12656(5) -
3(1.2656(5) 0.01830696>
=
a
1265625b 1.28125
=
=
128125
tolerance:
1265625
-
0.0078125
=
2) X6 1.265675 1.28/251.2734375
=
+
error 1.2734751.2656(5 0.00617
=
= =
2 1.265625
4 sin (12734375) -
3(1.2734375) 0.0041422
=
> 0
a 1.2734375
=
b 1.28145
=
1.28125-1.273455 0.00390625)
tolerance = =
0.002 so we continue
8) xy 1.2734575 128125 1.27734375
= +
=
error 127734375
= -
1.2734375 =0.00306
2 1.273+ 375
↑sin (127734375) -
3(127734375) =
=
0.003027670
b 127734375
=
a =
1.2734375
0.00195 (0.00)
STESTS
tolerance: = which is
so we stop here.
②
is 1.2773 +375
Description of the method: Question 3:
Inputs:
f: function handle for the equation to find the root
x1: lower bracket
x2: upper bracket
er : estimated relative error (default is 0.0001)
Outputs:
root: approximate root
fx: function value at the root
ea: relative error
The function checks if there are at least 3 inputs, and sets a default value for the relative error tolerance if it's
not provided. The function also sets the maximum number of iterations to 100. It uses a while loop to
iteratively find the root using the Regula Falsi modification 1 method. It also calculates the approximate
relative error. The loop stops when either the relative error is less than or equal to the tolerance, the number of
iterations has reached the maximum of 100, or the function value is 0 at the root. A counter is used to keep
track of repeated endpoints. If the solution is not found within 100 iterations, the function gives an error.
Here are the results obtained using RegulaFalsiMod1, fzero, and roots:
continue on
the next
page
As can be seen when we compare the value it turns out they are very close. It is important to
note that the closeness of the values depends on the estimated relative error tolerance as
can be seen when I set the error in RegulaFalsiMod and when I left it at the default value.
In order to compare the values I will calculate the relative error between them:
As seen, the relative errors are tiny! This supports the fact that the results obtained are very
very close and similar. This is expected since all 3 methods are designed to find roots of a
function.