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
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
0.2(t30)
1520e
0.1
0 t 10
10 t 20
20 t 30
t 30
otherwise
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