Introduction To Mat Lab
Introduction To Mat Lab
glmoyo
What is Matlab ?
• MATLAB stands for MATrixLABoratory
• It was designed to make matrix computations particularly easy
• It is used for handling the calculations involved in scientific and
engineering problems.
• The basic variable in Matlab is the matrix type of variable
• You are familiar with matrices that take this form:
21 10 5
• A= 5 5 15
10 35 5
• While other programming languages mostly work with numbers
(variables) one at a time, MATLAB is designed to operate primarily on
matrices and arrays
• Thus it is good for solving systems of mathematical equations
Power of Matlab
• Is very interactive
• Can solve from very simple problems to more complicated problems
involving differential equations and modelling systems
• rules for writing MATLAB statements – are very familiar for Java and
C, C++ programmers
• logical plan for solving problems from other languages still apply
Using Matlab
• When you open Matlab, you are presented with a command prompt
that allows you to type in the command you desire to be executed.
Typing a command
Clc – clears the screen removing the typed text and commands from
the command window
Simple commands
• Matlab gives the answer there and then , in the above example giving the answer just like a
calculator does
• On the right z=sqrt(y) with a semi‐colon prevent matlab from displaying the answer there and then
• Whos y is a command that ask matlab to display properties of variable y
• It answers that y is a variable of type matrix (1 x1 matrix) able to store a single double number
• typing y makes matlab display the number (84) stored in y typing z and enter shows what z
contains in this case sqrt (y)= sqrt (84) = 9.165
Example: Find the solution to the given 3 × 3 system using Cramer’s
Rule
• x+y−z=6
• 3x−2y+z=−5
• x+3y−2z=14
In Matrix form
1 1 1 𝑥 6
3 2 1 . 𝑦= 5
1 3 2 𝑧 14
Solution6
1 1 1 6 1 1 1 6 1 1 1 6
D= 3 2 1 Dx= 5 2 1 Dy= 3 5 1 Dz= 3 2 5
1 3 2 14 3 2 1 14 2 1 3 14
D =[(1)(‐2)(‐2) ‐(1)(1)(3)] +[(1)(1)(1) ‐(1)(3)(‐2) ] + [(‐1)(3)(3)‐ (‐1)(1)(‐2)] =4‐3+1+6‐9‐2=‐3