0% found this document useful (0 votes)
17 views

Introduction To Mat Lab

Uploaded by

Dex Tre
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Introduction To Mat Lab

Uploaded by

Dex Tre
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

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

Dx =[(6)(‐2)(‐2) ‐(6)(1)(3)] +[(1)(1)(14) ‐(1)(‐5)(‐2) ] + [(‐1)(‐5)(3)‐ (‐1)(14)(‐2)] =4‐3+1+6‐9‐


2=‐3
x= Dx/D =‐3/‐3= 1
Now let us see how easy matrix manipulation is made easier in matlab
Matlab matric programming
• To declare a matrix variable in matlab, simply type the variable name
and the matrix data as follows:
• D =[ 1 1 ‐1; 3 ‐2 1; 1 3 ‐2] (NB the semicolon means end of row)
• once you press enter the matrix D is displayed
• and you can key in det(D) to get the determinant of D as shown
below
• Similarly you can enter matrix Dx as follows:

• You can then find x = Dx/D = ‐3/‐3 = 1


• Simply by using the command
• x = det(Dx)/det(D)

You might also like