Anda di halaman 1dari 5

MEC2456 Engineering Computational Analysis

MAE2403 Aerospace Computational Mechanics


Laboratory #1
General Instructions:
The tasks of #1 to #4 in this lab are for practice purpose, thus
submission is NOT required.
Submit the solutions for question 1 and 2.
One optional question in this lab session.
Submit your solutions at the beginning of your 3rd
computer lab session (i.e., week 4).
At the end of this lab, your progress on all the tasks
and questions will be assessed.
The solutions will be uploaded on Moodle site after submission.
You are encouraged to refer to my solutions to compare against
yours.
You are advised to try some tutorial examples before the
computer lab (e.g., the appendix included in this file).
The reading material MATLAB 7 Getting started guide
available on Moodle will be very helpful.
Students are strongly encouraged to discuss any problems they may have
had with using MATLAB, and any questions they may have with the
solution set with the laboratory demonstrators (during the laboratory
session) and with the lecturer-in-charge (during laboratory session and/or
during consultation hours).

Note: Task #1 to #4 are for practice purpose and the submission is


NOT required.
Task #1: MATLAB tutorial
Read the appendix and do the tutorial exercises included.

Task #2:
Truncation is the discrepancy introduced by the use of an approximated
expression in place of an exact mathematical expression or formula. For example,
function ln(2+x) can be expressed by Taylor series as:

(1)i1
(1 x)i
i
i1

y(x) ln(2 x)

1
1
1
1
1
(1 x) (1 x)2 (1 x)3 (1 x)4 (1 x)5 (1 x)6 ...
2
3
4
5
6
Write a M-file to implement this formula so that it compute and display the
values as each term in the series is added up. In other words, compute and show
the sequence
ln(2 x) 1 x
1
ln(2 x) (1 x) (1 x)2
2
1
1
ln(2 x) (1 x) (1 x)2 (1 x)3
2
3
1
1
1
ln(2 x) (1 x) (1 x)2 (1 x)3 (1 x)4
2
3
4
1
1
1
1
ln(2 x) (1 x) (1 x)2 (1 x)3 (1 x)4 (1 x)5
2
3
4
5
...
up to the order that you choose. For each term, please compute and display the
percentage truncation error.
As a testing case, please use your program to compute ln(2-0.5) for up to eight
terms.
Note: Please try to draw a flow chart before you program.

Task #3
In mathematics, Fibonacci numbers are the following sequence of numbers

1, 1, 2, 3, 5, 8, 13, 21, 34, ....


By definition, the first two Fibonacci number are two 1s, and each remaining
number is the summation of the previous two. In term of mathematics, the
sequence number Fn is defined by a recurrence relation
Fn = Fn-1 + Fn-2
With two seed number F0=1 and F1=1.
Write a M-file to find all the Fibonacci numbers smaller than 1000.
Note: Please try to draw a flow chart before you program.

Task #4
Piece-wise function is sometimes useful when the relationship between a
dependent and independent variables cannot be adequately represented by a
single equation. For example, the velocity of a rocket might be described by:

11t2 5t

1100 5t

v(t) 50t 2(t 20)2

0.2(t30)
1520e
0.1

0 t 10
10 t 20
20 t 30
t 30
otherwise

(1) Develop a MATLAB code to compute v as a function of t.


(2) Convert your MATLAB code to a MATLAB function and use this function
to calculate the v values from t=-5 to 50 at an increment of 0.5.
Note: Please try to draw a flow chart before you program.

Note: the following two questions will need submission of report.


Question #1: Gauss-Seidel method
The Gauss-Seidel method is a recursive method to solve a matrix problem
[A][x]=[d]
where [x] is a vector of unknowns. See lecture 3 for details of Gauss-Seidel
method. (Note: please check out the example question video posted online to get
instructions.)
(1) Using the Gauss-Seidel method, hand calculate the solution of a matrix
problem. (Note: just do four iterations)

4 1 0 x1 10


1 4 1 x2 10
0 1 4 x 20

3
(2) Write a MATLAB m-file to implement the Gauss-Seidel method. The first line
of the m-file should be written as:
function [x_sol, num_iter]=GaussSeidel(A, d, toler)
where x_sol is the solution, num_iter records the total number of iterations, A
is the coefficient matrix, d is the column vector on the right hand side, and toler
is the tolerance of convergence. (Note: you can start with the Jacobi() code
posted online.)
Note: Please draw a flow chart before you program. Please include your flow
chart in your lab report.
Test your code by typing the following in command window
>>a=ones(59,1);
>>b=4*ones(60,1);
>>c=ones(59,1);
>>d=linspace(100,100,60);
>>A=diag(a,1)+diag(b,0)+diag(c,1);
>>tic;[x_sol,num_iter]=GaussSeidel(A,d',1.e
6);toc;
What are the solutions? How many iterations does it take? Please also try the
Jacobi() code posted online. How many iterations does it take? What are your
conclusions by comparing these two methods?
(3) Optional question. Please implement successive over relaxation method

to redo question (2).


Question #2: False-position method
Write a MATLAB m-file to implement the false position method. The first line of
the m-file should be written as:
function root = false_pos(func,xl,xu,toler)
Here, func is a function file specified by the user (see examples in lecture 4 for
the bisection method); xl and xu are the lower bound and upper bound of the
interval which bracket the root, and toler is a very small number used to
determine when the root is found.
Note: Please draw a flow chart before you program. Please include your flow
chart in your lab report.
Test the code by finding the root of the following functions. Please provide the
roots and the number of iteration taken if toler=1.e12 .
(A) cos(1/x), with xl=0.1 and xu=2.0
(B) (x-1)5,
with xl=0.1 and xu=2.0
(C) 3cos(2*x)ex,
with xl=0.1 and xu=2.0

NOTE : This question requires you to understand the false-position position


method. You may find the following sources helpful.
Lecture notes: Lecture 4.
Chapra & Canale, Numerical methods for Engineers (5 th and 6th Ed.) 5.3.
McGraw-Hill, 2006. Mos 517.5 C467N.
Faires & Burden, Numerical Methods (3rd Ed.) 2.3. Thomson, Brooks/Cole,
2003. Mos 517.5 F165N
You are suggested to modify the mid-piont method code in lecture 4 to get the
answer.

Anda mungkin juga menyukai