Experiment # 1
Exercise: 01
a) Extract the fourth row of the matrix generated by magic (6):
In MATLAB or Octave, the magic(6) function generates a 6×6 magic square matrix — a square array
of distinct integers such that the sums of the numbers in each row, each column, and the two main
diagonals are all the same.
MATLAB CODE:
RESULT:
The fourth row of magic(6) is:
b) Show the results of ‘x’ multiply by ‘y’ and ‘y’ divides by ‘x’.
Given x = [0:0.1:1.1] and y = [10:21]
MATLAB CODE:
RESULT:
c) Generate random matrix ‘r’ of size 4 by 5 with number varying between -8 and 9
MATLAB CODE:
Explanation:
randi([min, max], rows, columns) generates a matrix of uniformly distributed random
integers between min and max, inclusive.
Here, [-8, 9] specifies the range.
4, 5 specifies the matrix size.
RESULT:
Exercise: 2
Use the following MATLAB commands to plot the figure and insert it below
x=pi/2:pi/10:2*pi;
y=sin(x);
z=cos(x);
MATLAB CODE:
RESULT:
Exercise:3
Consider the following two polynomials and calculate a, b, c, and d
Roots of p(s) and q(s)
a) P(s)*q(s)=
p(-1)=
b)
q(6)=
c)
d)
a)
MATLAB CODE:
RESULT:
b)
MATLAB CODE:
RESULT:
c)
MATLAB CODE:
RESULT:
d)
MATLAB CODE:
RESULT:
Exercise:4
Use MATLAB command to find the partial fraction of the following
a)
MATLAB CODE:
RESULT:
b)
MATLAB CODE:
RESULT:
Exercise:5
Use MATLAB to generate the first 100 terms in the sequence a(n) define recursively by
a(n+1) = p*a(n)*(1-a(n))
with p=2.9 and a(1) = 0.5.
MATLAB CODE:
RESULT:
Exercise:6
a)
Write a MATLAB M-file function to obtain numerical values of y(t). Your function
must take y(0), ζ , ωn , t and θ as function inputs and y(t) as output argument.
y 0 −ζωnt
sin (ωn √ 1−ζ ∗t +θ)
2
y (t)= e
√1−ζ
b)
Write a second script m-file to obtain the plot for y(t) for 0<t<10 with an increment of
Case 1: y0=0.15 m, ωn = √2 rad/sec, ζ = 3/(2√2 ) and θ = 0;
0.1, by considering the following two cases
Case 2: y0=0.15 m, ωn = √2 rad/sec, ζ = 1/(2√2 ) and θ = 0;
c)
Use ‘for’ or ‘while’ loop to convert degrees Fahrenheit (T f) to degrees Celsius using the
following equation. Use any starting temperature, increment and ending temperature
(example: starting temperature=0, increment=10, ending temperature = 200).
9
T f = ∗T c +32
5
a)
MATLAB CODE:
RESULT:
b)
MATLAB CODE:
RESULT:
c)
MATLAB CODE:
RESULT: