Lab IAT 03
Lab IAT 03
Claudia Zoccarato
E-mail: [email protected]
June, 06 2017
Claudia Zoccarato MATLAB Programming for Engineers ENSTP Yaounde Camerun - 05/06/2017
Introduction to vectors and matrices
Claudia Zoccarato MATLAB Programming for Engineers ENSTP Yaounde Camerun - 05/06/2017
Introduction to vectors and matrices
Claudia Zoccarato MATLAB Programming for Engineers ENSTP Yaounde Camerun - 05/06/2017
Introduction to vectors and matrices
To transform a row vector in a column vector and vice versa, you can use
the apex symbol, which correspond to the TRANSPOSE operation.
Claudia Zoccarato MATLAB Programming for Engineers ENSTP Yaounde Camerun - 05/06/2017
MATLAB predefined function
Claudia Zoccarato MATLAB Programming for Engineers ENSTP Yaounde Camerun - 05/06/2017
Vectors in MATLAB
Claudia Zoccarato MATLAB Programming for Engineers ENSTP Yaounde Camerun - 05/06/2017
Vectors in MATLAB
Claudia Zoccarato MATLAB Programming for Engineers ENSTP Yaounde Camerun - 05/06/2017
Vectors in MATLAB - the colon notation
Claudia Zoccarato MATLAB Programming for Engineers ENSTP Yaounde Camerun - 05/06/2017
Plot of a function: command plot
Claudia Zoccarato MATLAB Programming for Engineers ENSTP Yaounde Camerun - 05/06/2017
Plot of a function: command plot
r red
g green
b blue
c cyan
m magenta
y yellow
k black
w white
Claudia Zoccarato MATLAB Programming for Engineers ENSTP Yaounde Camerun - 05/06/2017
Plot of a function: command plot
Claudia Zoccarato MATLAB Programming for Engineers ENSTP Yaounde Camerun - 05/06/2017
The anonymous functions
Claudia Zoccarato MATLAB Programming for Engineers ENSTP Yaounde Camerun - 05/06/2017
Exercises
Claudia Zoccarato MATLAB Programming for Engineers ENSTP Yaounde Camerun - 05/06/2017
The bisection method
The bisection method in mathematics is a root-finding method that
repeatedly bisects an interval and then selects a subinterval in which a
root must lie for further processing. It is a very simple and robust method,
but it is also relatively slow.
Implement the bisection method using a scrip to find the roots of the
function f (x) = ln(x) + x2 − sin(πx) in the interval [0.1, 2π]. Use the
following hints:
1 Start from the interval [a0 , b0 ] = [a, b] and calculate the midpoint c0
2 Check the following cases:
if f (c0 )f (a0 ) > 0 then [a1 , b1 ] = [c0 , b0 ]
if f (c0 )f (b0 ) > 0 then [a1 , b1 ] = [a0 , c0 ]
3 This procedure is repeated each time subdividing the interval. The
procedure will end when a certain accuracy is reached.
4 The while loop is repeated until convergence. The criterion has to be
defined such that τk+1 > toll and iter < itmax
Claudia Zoccarato MATLAB Programming for Engineers ENSTP Yaounde Camerun - 05/06/2017
The bisection method
Claudia Zoccarato MATLAB Programming for Engineers ENSTP Yaounde Camerun - 05/06/2017
The bisection method
1 clear
2 close all
3 % The b i s e c t i o n method i n MATLAB
4 a = 0.1;
5 b = 2∗ p i ;
6 t o l l = 10ˆ −6;
7 itmax = 100;
8 t a u = a b s ( a−b ) ;
9 f=@( x ) l o g ( x )+x .ˆ2− s i n ( p i ∗x ) ;
10 i t e r = 0;
11 while . . .
12 ...
13 if ...
14 ...
15 else
16 ...
17 end
18 ...
19 fprintf ( ’ ... ’)
20 end
Claudia Zoccarato MATLAB Programming for Engineers ENSTP Yaounde Camerun - 05/06/2017