Professional Documents
Culture Documents
Qasim Habib
Today’s Content
1. Arrays
2. Polynomial Roots
● 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