Sunteți pe pagina 1din 47

NUMERICAL

ANALYSIS
CHAPTER THREE

Programming with
MATLAB
3.1 M-FILES

Assigning Values to Variables

a & A are different variables


The command prompt

>>
, Vs. ;
clc, Clear
i, j … (√-1)
predefined variables
(pi)
format compact
&
format loose
2.2.2 Arrays, Vectors, and Matrices
An array is a collection of values that are
represented by a single variable name.
One- dimensional arrays are called
vectors and two-dimensional arrays are
called
matrices.
Use Brackets [ ] to enter
arrays
Row Vectors
Column Vectors
1. Using ; 2. Using Enter
b = [2;4;6;8;10] b = [2
4
6
8
10]
3.Transposing Row Vectors


>> b = [2 4 6 8 10]'
Matices
A=
1 2 3
4 5 6
7 8 9
1.
>> A = [1 2 3; 4 5 6; 7 8 9]

2.
>> A = [1 2 3
456
7 8 9]
3.
>> A = [[1 4 7]' [2 5 8]' [3 6 9]']
Calling individual elements of an array
ones
&
zeros
2.2.3 The Colon Operator

>> t = 1:5

>> t = 1:0.5:3

>> t = 10:−2:5
Using : to call elements
from vectors and matreces
2.2.4 The linspace and logspace Functions
linspace
linspace(x1, x2, n)

𝑋2 −𝑋1
Interval =
𝑛−1
logspace

logspace(x1, x2, n)
generates n logarithmically equally spaced
points between decades 10x1 and 10x2.

𝑋2 −𝑋1
Power Interval =
𝑛−1
2.2.5 Character Strings
>> f = 'Miles ';
>> s = 'Davis';

>> x = [f s]
ellipsis …
>> a = [1 2 3 4 5 ...
6 7 8]

>> quote = ['Any fool can make a rule, ...


and any fool will mind it'] X Wrong

>> quote = ['Any fool can make a rule,' ...


' and any fool will mind it'] √ Correct
>> disp(sprintf('Ahmed\nOmar'))
2.2.5 Character Strings
Matrix Multiplication

https://www.mathsisfun.com/algebra/matrix-multiplying.html
>> A^2

>> A.^2
>> E = [−1.6 −1.5 −1.4 1.4 1.5 1.6];

>> round(E)
ans =
−2 −2 −1 1 2 2

>> ceil(E)
ans =
−1 −1 −1 2 2 2

>> floor(E)
ans =
−2 −2 −2 1 1 1
>> F = [3 5 4 6 1];

>> sum(F) >> mean(F)


ans = ans =
19 3.8000

>> min(F) >> prod(F)


ans = ans =
1 360

>> max(F) >> sort(F)


ans = ans =
6 13456
Solve Using MATLAB

A bungee jumper with a mass of 68.1 kg jumps off a


stationary plane. Compute his velocity for the first
20 s of the free fall.
Drag coefficient= 0.25 kg/m.
Use a step size of 2 seconds.
Compute the exact solution
>> t = [0:2:20]'

>> g = 9.81; m = 68.1; cd = 0.25;

>> v = sqrt(g*m/cd)*tanh(sqrt(g*cd/m)*t)
2.5 GRAPHICS
>> plot(t, v)
>> plot(t, v)
>> title('Plot of v versus t')
>> xlabel('Values of t')
>> ylabel('Values of v')
>> grid
PROBLEMS
2.1
What is the output when the following commands
are implemented?

A = [1:3;2:2:6;3:−1:1]
A = A'
A(:,3) = []
A = [A(:,1) [4 5 7]' A(:,2)]
A = sum(diag(A))
Ex.1.1

A bungee jumper with a mass of 68.1 kg jumps off a


stationary plane. Compute his velocity for the first
12 s of the free fall. Also determine the terminal
velocity.
(Use Analytical Solution)
(drag coefficient= 0.25 kg/m).
‫مواعيد تسليم الواجبات‬

‫الموعد النهائي‬
‫األسئلة المطلوبة‬ ‫رقم الشابتر‬
‫للتسليم‬

‫الخميس‬
‫‪07/03/2019‬‬ ‫‪7,9 and 17‬‬ ‫‪1‬‬
‫‪11:00 pm‬‬

‫السبت‬
‫‪09/03/2019‬‬ ‫‪1,2,4,7,9,13,18,22 and 26‬‬ ‫‪2‬‬
‫‪11:00 pm‬‬

‫األحد‬
‫‪10/03/2019‬‬ ‫‪1,5,6,8,10,12,14 and 22‬‬ ‫‪3‬‬
‫‪11:00 pm‬‬
‫جدول مناقشات األسبوع القادم‬

‫الموضوع‬ ‫القاعة‬ ‫الموعد‬ ‫اليوم‬

‫التجمع أمام مبنى ‪K‬‬


‫‪Chapter 2‬‬ ‫‪11:00 – 12:00‬‬ ‫السبت‬
‫الساعة ‪ 11:00‬تماما‬

‫التجمع أمام مبنى ‪K‬‬


‫‪Chapter 2‬‬ ‫‪11:00 – 12:00‬‬ ‫األحد‬
‫الساعة ‪ 11:00‬تماما‬

‫‪Chapter 3‬‬ ‫‪K218‬‬ ‫‪08:00 – 09:00‬‬ ‫األربعاء‬

‫‪Chapter 3‬‬ ‫‪K218‬‬ ‫‪09:00 – 10:00‬‬ ‫األربعاء‬

‫‪Chapter 3‬‬ ‫‪K212‬‬ ‫‪10:00 – 11:00‬‬ ‫األربعاء‬

‫التجمع أمام مبنى ‪K‬‬


‫‪Chapter 3‬‬ ‫‪11:00 – 12:00‬‬ ‫األربعاء‬
‫الساعة ‪ 11:00‬تماما‬

S-ar putea să vă placă și