Professional Documents
Culture Documents
حاسبات تمارين PDF
حاسبات تمارين PDF
Environment of MATLAB
INTRODUCTION:
The name MATLAB stands for Matrix Laboratory. The basic building block of
MATLAB is the matrix. It is not confined to the solution of Matrix related problems. With
its inbuilt functions, it is an excellent tool for linear algebraic computations, data analysis,
signal processing, optimization, numerical solutions of ordinary differential equations
(ODE), quadrature, 2D & 3D, graphics and many other types of scientific computation.
Therefore, we can say: MATLAB is a software package in high performance language for
technical computing. It integrates computation, visualization and programming in an easy
to use environment where problems and solutions are expressed in familiar mathematical
notation.
Exercises:
1
Experiment (2):
b. = |3 + 4 |
d. = + 4 + 15
e. = cos 30°" − tan 45°" + 3
2.
3. Use [ round , fix , ceil, floor] commands to round the following numbers towards
integer numbers
a. Pi
b. 4.25
c. 6.99
d. 100.001
e. 30.67
2
f. 50.499
g. 60.51
4. Represent the following complex numbers in polar coordinate, and find the
conjugate of them
a. Z= 2 + 5j
b. Y= -3 - 3j
c. D= -2 + 6j
7.
3
Experiment (3):
Matrix Operations
Exercises:
3 2 1 1 3 0
%=& 0 3 4 ' )*+ , = & 2 6 4'
−1 1 −1 −1 0 2
a. A+B
b. A-B
c. A*B
d. B*A
e. A\B
f. B\A
g. A-1
h. B-1
i. 2A
4 −1 1 2 −4 1 4 1 3
2. Let % = & 2 3 0', , = & 1 1 7', / = & 3 2' and 0 = &0'
−2 −3 6 −1 −3 0 −6 0 1
4
3. Generate the following matrices (the size of the generated matrix is 3 by 3 )
a. Magic matrix
b. Zero matrix
c. One matrix
d. Random matrix
e. Diagonal matrix
1 4
4. If 0 = 1 3, find :
8 3
a) the inverse matrix of x .
b) the diagonal of x.
c) the sum of each column and the sum of whole matrix x.
d) the transpose of x.
2 8 5
5. If 0 = 1 3, 5 = 62 4 57 find:
9 7 1
a) find the maximum and minimum of x.
b) find median value over each row of x.
c) add the vector b as a third row to x.
6. For the x=[4 -1 3 5 9], find the mean, median, standard deviation, variance, sum,
product, maximum and minimum.
2 −3 5
7. let 0 = 1 3, then
0 11 0
a) find elements in x that are greater than 2
b) find the number of nonzero elements in x
5
8.
9.
In 50
6
Experiment (4):
Built in Functions and User defined functions
1.
a. Factor the number 322
b. Find the Greatest common denominator 0f 322 and 6
c. Find 10!
d. Find the number of possible ways to choose 3 people from a group of 20
without repetition
2. The Heat index HI, calculated from the air temperature and relative humidity is the
apparent temperature felt by the body. The following equation is used:
89 = −42.379 + 2.04901523; + 10.14333127< − 0.22475541<;
− 6.83783 × 10> ; − 5.481717 × 10> <
+ 1.22874 × 10> ; < + 8.5282 × 10> ;< − 1.9910>? ; <
3.
7
4.
8
7.
9
Experiment (5):
1. A student writes a Matlab program to solve the following exercise, but the
program dose not run, list the errors and fix them to run the program
correctly.
3 2 1 1 3 0
%=& 0 3 4 ' )*+ , = & 2 6 4'
−1 1 −1 −1 0 2
a. A+B
b. A*B
c. A\B
d. A-1
e. 2A
Student’s solution (program is saved in file named (matlab.m)
cls
clears all
A=[3,2,1,0,3,4;-1,1,-1];
B={1,3,0;2,6,4;-1,0,2};
Part a
addAB=A.+B
%part b
mulAB=a*b;
%part c
divAB=A/B;
%part d
Inv =A’;
%part e 2A=A^2;
10
2. A student writes a matlab program to find the solution for the following
Student’s solution
tan(X)+sinx;
lhs=Cos^2(x/2);
x=pi\5;
rhs=lsh;
The program does not run and give correct answer. List all the errors and fix
them.
3. The following program is written to find the results of the following equation
(x3+x2+1) for and x using user defined functions. Find the errors and fix them
to achieve the right answer.
User program
Input (‘enter x)
Y=eq(x);
User function
Function eq=funx(x)
Eq= x3+x2+1;
4.
11
12
Experiment (6)
Looping Instructions (do.. while, for ..next)
1.
2.
3.
13
4.
14
Experiment (7):
Manipulating polynomials and finding polynomials roots
1.
2.
3.
4.
5.
7.
8.
15
9.
16
Experiment (8):
Graphic Plots (Two dimension plots, log-log and semi- log plots)
1.
2.
3.
4.
17
5.
6. Find the locations of the roots of the following equation using plot
7. Find the location of the roots of the following equation using plot
18
Experiment (9): Solve System of Linear Equations by using backslash and Cramer
method
Note: make your own Cramer method function to use it in all following tasks
1. Write a program to solve linear equation using Cramer rule and backslash division
5x= 3y-2z+10
8y+4z= 3x+20
2x+4y-9z=9
2. Write a program to solve linear equation using Cramer rule and backslash division
5x= 5y-8z
9y+3z= x+6
10x+4y-z=7
3. Solve the following system using Cramer rule and backslash division
x+y=1
x-y+z=0
x+y+z=2
4. Solve the following system using Cramer rule and backslash division
x + y - 2z = 3
2x + y = 7
x+y-z=4
5. Solve the linear equations system using Cramer rule and backslash division
6x+2y+8z-26=0
3x-8+2z=-5y
8y+2z=-7
6. Solve the linear equations system using Cramer rule and backslash division
19
7. Solve the linear equations system using Cramer rule and backslash division
8. Solve the linear equations system using Cramer rule and backslash division
9. Solve the linear equations system using Cramer rule and backslash division
20
Experiment (10):
2x+y-3z=5
4x-7y+z=-1
x-y+z=1
3y-2z=-5
2x+y-z=2
3x+2y-4z=7
21
6. Solve the following system using Gauss-Jordan Method
22
Experiment (11):
Graphic Plots (Linear Regression and Curve fitting)
1.
2. Find the straight line, quadratic and cubic equations that fit to the following data
3.
4.
23
5.
6.
24
7.
8.
25
Experiment 12: One- and Two-Dimensions Interpolation
1.
2.
26
3.
4.
27
28
Experiment 13: Roots Finding of Nonlinear Equations (Newton Raphson and Bisection
methods)
1. Using Newton Raphson method
2.
3.
4.
29
5.
6. Using both Newton Raphson and Bisection methods find the roots of the equation
7. Find the roots of f in the interval [-8,8] using both Newton Raphson and Bisection
methods
8. Find the roots of the following expression in the interval [0,1] using both Newton
Raphson and Bisection methods
9. Find the roots of f using Bisection methods do not exceed the tolerance (0.001)
10. Find the roots of the following expression in the interval [1,2] using both Newton
Raphson and Bisection methods
30
Experiment 14: Numerical Integration by Trapezoidal, Simpson and Lobato Rules
1.
What is the difference if you use Simpson’s rule? Find the error between them
2.
Find the error between the Lobato rule and the Trapezoidal rule
3.
Find the error between the results of Simpson rule and the trapezoidal rule
4.
Find the result analytically. What is the difference between the results?
31
5.
6.
7.
32
8.
9.
10.
11.
33
Experiment 15: Ordinary Differential Equations (Numerical Solutions using Modified
Euler method)
1.
2.
3.
34
35
Experiment 16: Ordinary Differential Equations (Numerical Solutions using Runge Kutta
method)
36
Experiment 17: Ordinary Differential Equations systems (Numerical Solutions using
Runge Kutta and Euler methods)
3.
37
Experiment 18: The actual solutions of ODE in Matlab
1. Find the actual solution using dsolve function
38
Experiment 19: Applications
1. Water flows inside a horizontal circular pipe at 25°C. Determine the average
velocity and plot the velocity distribution inside the pipe. The length and the inside
radius of the pipe are 15 and 0.009 m, respectively, the viscosity of water is 8.937
× 10-4 kg/(m · sec), and the pressure drop is ΔP = 520 Pa.
2. Water flows inside a smooth pipeline at 21°C with a flow rate of Q=0.0085 m3/sec. The
length of the pipeline is L=250 m, and the elevation of the upstream point is high
enough to overcome the friction loss Ff= 27.5 J/kg. The Fanning friction factor is given
byf =0.0468 NRe-0.2, and the density and the viscosity of water at 21°C are ρ =
997.91 kg/m3and µ = 0.000982 kg/m/sec, respectively. Determine the diameter of the
pipeline. Note : gc=1, use fzero function to find D.
4. The Figure below shows a series of three well-mixed tanks. From mass balance
equations, we have
39
5. The variation of heat transfer per unit area (q) during the boiling of water under
pressure (p) has been found to be as follows:
Develop a suitable polynomial relation between q and p by trying out curve fitting.
6. A biological process involves the growth of biomass from substrate. The material
balances on this batch process yield
where B and S are the respective biomass and substrate concentrations. The reaction
kinetics are such that k = 0:3 and K = 10-6 in consistent units. Solve this set of
deferential equations starting at t0 = 0, when S = 5 and B = 0:05, to a final time
given by Tf = 20 using Euler method (h=0.2). Assume consistent units. Plot S and
B vs. time.
40
Experiment 23: Linear Programming Optimization
41
2.
42
43
44
Experiment 24 : Multi-objective Optimization
45
Experiment 25: Large-scale Algorithms
46