You are on page 1of 10

LINEAR SYSTEMS AND MATLAB

PROGRAMMING

L. Kanock
Graduate Civil Engineer
+265 295 519
lkanock@gmail.com
Solving Linear Systems
• Linear systems are linear equations
with a number of unknowns

• They can be presented on a Matrix

• Basic linear system in the form of

Ax = b
Solving Linear Systems
• Example: • Present it in Matrix Form:

3 2 −1 𝑥 1
3x + 2y – z = 1
2 −2 4 𝑦 = −2
2x – 2y + 4z = -2 1
−1 2 −1 𝑧 0
-x + ½ y – z = 0
Solving Linear Systems
• To solve the linear system in MATLAB syntax
MATLAB

• Use one of the following


expressions:
x = A\b
x = linsolve(A,b)
x = Inv(A)*b
MATLAB Programming

Rules of Naming the script:


• MATLAB programming
is usually done in a
Script. • Start the script name with a
letter
• A code is written In the
script and run.
• Name can contain
• Your save the script in underscores and numbers
your working folder.
MATLAB Programming – if - else
statements

• The if-else statements


are used as logical
operators to help the
computer make
decisions.
MATLAB Programming - For loops
• The for Loop: • syntax
for i = [ 1 2 3 4 5 6 9]
The for loop is used to disp(i)
iterate a command for a end
finite number of times.
• This will display the
numbers
• You can use the colon
operator to create the
preferable range.
MATLAB Programming – while loops
The while loop: • The basic syntax is as
follows:
• This is used to iterate
a command while a n = 10
statement is true
total = 0
• While loops are
dangerous they can while total < n
run to infinity. total = total + 2
End
MATLAB Programming – while loops
• Application:
END

You might also like