You are on page 1of 17

TECHNICAL COMPUTING

Qasim Habib
Today’s Content

1. Arrays

2. Polynomial Roots

3. Working with files

4. Plotting with MATLAB

5. Linear Algebraic Equations


Concept of Arrays
● We have seen how scalar variables can be
defined in MATLAB.
>> a = 4
● MATLAB can handle collections of numbers,
called arrays, as if they were single variable.
● A numerical array is an ordered collection f
numbers (a set of numbers arranged in a
specific order)
Defining arrays
● a = [1,5,73,5];
● b = [1 5 73 5];
● c = [1:100];
● d = [1:2:100];
● e = [1 3 [4:20] 7 9]
● f = a + c;
● g = 4*sin(d)
Important commands for arrays

● w = [1:.01:100];
● w(44)
● m = length(w) ???
● Row Arrays
x = [1 2 3 4]
● Column Arrays
x = [1;2;3;4]
Polynomial Roots
● Polynomials can be described in MATLAB with
the help of arrays, starting with the coefficients of the
highest power of x.
● f(x) = 4x3 – 8x2 + 7x – 5
● In MATLAB
● >> f = [4 -8 7 -5];
● For finding roots
● >> roots (f)
Task 2
● Solve these problems
● T1.3-1
● T1.3-2
Working with Files
● Mat-files have the extension .mat and are used
to save the names and values of variables
created during a MATLAB session.
● MATLAB function files and program files are
saved with the extension .m and thus called
M-files.
● M-files are ASCII files.
Plotting with MATLAB
● MATLAB has very powerful functions for
creating different kind of plots.
● e.g. Plot
y = 5sinx for x < 0 < 10
● MATLAB Commands
>> x = [0 : 0.02 : 10];
>> y = 5 * sin (x) ;
>> plot (x , y), xlabel (`x`), ylabel(`y`)
Overlay plots
● We can also create multiple plots in MATLAB.
>>x = [0:0.01:5];
>>y = 2*sqrt(x);
>>z = 4*sin(3*x);
>>plot (x,y,x,z),xlabel(`x`),gtext(`y`),gtext(`z`)
Linear Algebraic Equations
● Left division operator (\) in MATLAB is used to solve
sets of linear algebraic equations.
● Example to solve
6x + 12y + 4z = 70
7x – 2y 3z = 5
2x + 8y - 9z = 64
● MATLAB Commands
>>A = [6,12,4;7,-2,3;2,8,-9];
>>B = [70;5;64];
>>Solution = A\B
Solution =
3 5 -2
Task 3
● Solve these problems
● T1.3-3
● T1.3-4
● T1.3-5
Reference

This lecture is from pg 19-28 of your main MATLAB book


Topic 1.3 Computing with MATLAB
INTRODUCTION TO MATLAB 7
FOR ENGINEERS
by
WILLIAM J. PALM III
Task 4
● Solve these problems from exercise
Section 1.1
1, 2, 3, 4, 5, 6, 7, 8, 11, 12
Section 1.3
13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26

You might also like