Develop, Debug and Test a MATLAB - Computational Methods - Project 2 | MCEN 3030, Study Guides, Projects, Research of Mechanical Engineering

Material Type: Project; Class: COMPUTATIONAL METHODS; Subject: Mechanical Engineering; University: University of Colorado - Boulder; Term: Unknown 1989;

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 02/10/2009

koofers-user-dfi
koofers-user-dfi 🇺🇸

9 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computational Project # 2
Due February 28
Develop, debug, and test a MATLAB program that finds a root of a nonlinear equation
() 0fx
=
using (a) bisection method, (b) secant method, (c) Newton’s method, and (d) regularized
Newton’s method. The code should be able to solve for an arbitrary function f(x). Stop your
iterations, when 6
()10
n
fx
<. Organize your code such a way that the code has either one or two
input parameters x1 and x2 (initial guess) and the sequence of guesses 123
(,,, ,)
n
x
xx x=x as the
output parameter. For each method generate vectors
(
)
(
)() ()
(
)
123
,,,,
n
f
xfxfx fx=f and
(
123
***
,,,,
n
)
*
x
xxxxx xxΔ= x, plot them vs. the number of iteration using two
subplots within the same window. For both cases use semi-log scale (log scale in y direction and
linear scale in x). The figures you generate will be called convergence plot. Compare the
convergence of each method, i.e. compare how fast they converge (if the method converges).
For some functions f(x) the straightforward Newton’s method could diverge. In order to make
Newton’s method more robust, it is regularized the following way:
11
n
nn1n
x
xx
τ
+
++
=− Δ
where
(
)
()
1'
n
nn
x
x
f
x
+
Δ= and 1
1
2
2
n
nn
n
nn
n
xn
xx
τ
ττ
+
+
<
=Δ
Δ−Δ
.
for n=1,… and . Note that when
10.1
τ
=1
n
τ
=
the regularized Newton’s method reduces to the
original one.
Solve the following nonlinear equations with your own program using four methods:
a)
1/2
23
2cos 0
22
xx
π
⎛⎞
⎛⎞
−=
⎜⎟
⎜⎟
⎝⎠
⎝⎠ b)
(
)
12
tan 3 1 0x
=
Use the following initial guesses for both bisection and secant methods x1=0, x2=1 and x1=1 for
both Newton’s method.
Plot the convergence plots for each case. Discuss the results. Compare the roots you obtain with
the exact values
1/2
*2
3
x⎛⎞
=⎜⎟
⎝⎠ for problem (a) and 12
*3x
= for problem (b).
P.S. Bring your solution to class. Email your code to [email protected]. The program
that you send should be a working program. All the codes will be checked whether they run or
not. If they are erroneous, but run, points will be taken for the errors. If the code does not run (it
has some syntax errors), an additional 25% will be taken off. The goal of this class is for you to
be comfortable solving engineering problems. Please take your time and learn how to trust the
computer.

Partial preview of the text

Download Develop, Debug and Test a MATLAB - Computational Methods - Project 2 | MCEN 3030 and more Study Guides, Projects, Research Mechanical Engineering in PDF only on Docsity!

Computational Project # 2

Due February 28

Develop, debug, and test a MATLAB program that finds a root of a nonlinear equation f ( ) x = 0

using (a) bisection method, (b) secant method, (c) Newton’s method, and (d) regularized Newton’s method. The code should be able to solve for an arbitrary function f(x). Stop your

iterations, when f ( xn ) < 10 −^6. Organize your code such a way that the code has either one or two

input parameters x 1 and x 2 (initial guess) and the sequence of guesses x =( x 1 (^) , x 2 (^) , x 3 , … , xn )as the

output parameter. For each method generate vectors f =( f ( x 1 ) , f ( x 2 ) , f ( x 3 ) , … , f ( xn ))and

Δ x = ( x 1 − x * , x 2 − x * , x 3 − x * , … , xn − x *), plot them vs. the number of iteration using two

subplots within the same window. For both cases use semi-log scale (log scale in y direction and linear scale in x ). The figures you generate will be called convergence plot. Compare the convergence of each method, i.e. compare how fast they converge (if the method converges).

For some functions f(x) the straightforward Newton’s method could diverge. In order to make Newton’s method more robust, it is regularized the following way:

xn + 1 = xn − τ n + 1 Δ xn + 1

where

1 '

n n n

f x x f x

Δ (^) + = and (^1)

1

n n n n n (^) n

n x n x x

⎩ Δ^ − Δ

for n =1,… and τ 1 = 0.1. Note that when τ n = 1 the regularized Newton’s method reduces to the

original one.

Solve the following nonlinear equations with your own program using four methods:

a)

2 1/ 2 3 2 cos 0 2 2

x x

⎜ ⎟ −^ ⎜ ⎟ =

⎝ ⎠ ⎝^ ⎠

b) tan −^1 ( 3 x^2 − 1 ) = 0

Use the following initial guesses for both bisection and secant methods x 1 =0, x 2 =1 and x 1 =1 for both Newton’s method.

Plot the convergence plots for each case. Discuss the results. Compare the roots you obtain with

the exact values

1/ 2

x = ⎛⎜^ ⎞⎟ ⎝ ⎠

for problem (a) and

(^12) x * (^) 3 − = for problem (b).

P.S. Bring your solution to class. Email your code to [email protected]. The program that you send should be a working program. All the codes will be checked whether they run or not. If they are erroneous, but run, points will be taken for the errors. If the code does not run (it has some syntax errors), an additional 25% will be taken off. The goal of this class is for you to be comfortable solving engineering problems. Please take your time and learn how to trust the computer.