Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

1-Introduction to MATLAB

This document outlines a Control Systems Lab report for a MATLAB introduction, detailing various exercises and code examples for matrix manipulation, plotting functions, and solving equations. The report is submitted by a group of students and includes specific tasks such as extracting matrix rows, performing arithmetic operations, and plotting graphs of functions. The deadline for submission is set for October 25, 2024.

Uploaded by

Dua Naseem
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

1-Introduction to MATLAB

This document outlines a Control Systems Lab report for a MATLAB introduction, detailing various exercises and code examples for matrix manipulation, plotting functions, and solving equations. The report is submitted by a group of students and includes specific tasks such as extracting matrix rows, performing arithmetic operations, and plotting graphs of functions. The deadline for submission is set for October 25, 2024.

Uploaded by

Dua Naseem
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

_________________________________________________________________________

DEPARTMENT OF AVIONICS ENGINEERING

SUBJECT : CONTROL SYSTEMS LAB


SUBJECT CODE : 305312
LAB NO : 01

TITLE : INTRODUCTION TO MATLAB

SUBMITTED TO : Ms. Anila Ali Ahmed


SEMESTER : 5th
SECTION : B

Marks Obtained
Group Member Group Member Group Member
1 2 3
NAME DUA NASEEM
REGISTRATION # 220701014
LAB REPORT MARKS
PERFORMANCE MARKS
TOTAL MARKS

DEADLINE: 1100Hrs, 25th October 2024


DATE OF SUBMISSION: 24th October 2024

________________________________________________________________________
Experiment # 01 Page 1 of 9
Control Systems Lab
_________________________________________________________________________

Questions For Lab Report

Exercise 1:

Use Matlab command to obtain the following


a) Extract the fourth row of the matrix generated by magic(6)
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]
c) Generate random matrix ‘r’ of size 4 by 5 with number varying between -8 and 9

CODE:

a) m=magic(6)
m4=m(4,:)
disp(m4)

OUTPUT:

CODE:

b) x = [0:0.1:1.1]
y = [10:21]
mul=x.*y
div=y./x
disp(mul)
disp(div)

OUTPUT:

________________________________________________________________________
Experiment # 01 Page 2 of 9
Control Systems Lab
_________________________________________________________________________

CODE:
c) r=randi([-8,9],4,5)
disp(r)
OUTPUT:

Exercise 2:

Use MATLAB commands to get exactly as the figure shown below

x=pi/2:pi/10:2*pi;
y=sin(x);
z=cos(x);

________________________________________________________________________
Experiment # 01 Page 3 of 9
Control Systems Lab
_________________________________________________________________________

CODE:

x=pi/2:pi/10:2*pi ; y=sin(x); z=cos(x)


subplot(2,1,1)
plot(x,y,'--+b' % Plot the x and z values with red '*'
%markers and a dashed linxlim([1.5,6.5]) % Set the x-axis

limits between 1.5 and 6.5


title("sine curve")
xlabel("angle")
ylabel("sinx")
ax = gca % Get the current axes object
grid on
ax.GridLineStyle = '--' % Set the grid line style to dashed
subplot(2,1,2)
plot(x,z,'--*r') % Plot the x and z values with red '*'
%markers and a dashed line

title("cos curve")
xlabel("angle")
ylabel("cosx")
ax = gca
grid on
ax.GridLineStyle = '--'

OUTPUT:

________________________________________________________________________
Experiment # 01 Page 4 of 9
Control Systems Lab
_________________________________________________________________________

sine curve
1

0.5
sinx
0

-0.5

-1
1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 6.5
angle
cos curve
1

0.5
cosx

-0.5

-1
1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 6.5
angle

Exercise 3:

Define Following Matrices in MATLAB

[ ]
1.2 3.04 7.3 3.2
−1 −12 1.2 5
A= 2.7 1 −2 4 ,
6.6 4.51 0 1
−3 −2.2 1 6

[]
1.3
−1
B=
2.5
1.6

a. Compute the size of A.


b. Compute AB.
c. Extract elements of A that are in 2nd to 4th row and 1st & 3rd coloumn.
d. Solve Ax=B for

CODE:

A=[1.2,3.04,7.3,3.2;
-1,-12,1.2,5;
2.7,1,-2,4;
________________________________________________________________________
Experiment # 01 Page 5 of 9
Control Systems Lab
_________________________________________________________________________

6.6,4.51,0,1;
-3,-2.2,1,6]

B=[1.3;-1;2.5;1.6]

size(A)
mult=A*B
disp(mult)
A(2:4,[1,3])

% to solve the linear equation AX=B matrix dimensions must


agree so ;
A = [1.2, 3.04, 7.3, 3.2;
-1, -12, 1.2, 5;
2.7, 1, -2, 4;
6.6, 4.51, 0, 1]
B = [1.3; -1; 2.5; 1.6]
x = A \ B
disp('Solution x for Ax = B:')
disp(x)

OUTPUT:

________________________________________________________________________
Experiment # 01 Page 6 of 9
Control Systems Lab
_________________________________________________________________________

Exercise 4:

a. Draw the graph of following function:

𝑧 = 𝑒−2𝑡 cos(3𝑡 + 1) − 𝜋 ≤ 𝑡 ≤ 5𝜋
________________________________________________________________________
Experiment # 01 Page 7 of 9
Control Systems Lab
_________________________________________________________________________

CODE:

t = linspace(-pi, 5*pi, 1000)


z = exp(-2*t) .* cos(3*t + 1)
plot(t, z, 'b-', 'LineWidth', 1)
title('Graph of z = e^{-2t} * cos(3t + 1)')
xlabel('t')
ylabel('z')
grid on

OUTPUT:
-2t
Graph of z = e * cos(3t + 1)
200

150

100

50

-50
z

-100

-150

-200

-250

-300
-5 0 5 10 15 20
t

b. The deflection of a cantilever beam is the distance its end moves in response to a
force applied at the end. The following table gives the deflection 𝑥 that was
produced in a particular beam by the given applied force 𝑓. Plot the graph:

Force 𝑓 (pound) 0 100 200 300 400 500 600 700 800
Deflection 𝑥 0 0.09 0.18 0.28 0.37 0.46 0.55 0.65 0.74
(inches)

CODE:

force = [0, 100, 200, 300, 400, 500, 600, 700,


800] % in pounds

________________________________________________________________________
Experiment # 01 Page 8 of 9
Control Systems Lab
_________________________________________________________________________

deflection = [0, 0.09, 0.18, 0.28, 0.37, 0.46,


0.55, 0.65, 0.74] % in inches
plot(force, deflection, 'm-o', 'LineWidth', 2,
'MarkerSize', 6)
title('Deflection of Cantilever Beam')
xlabel('Force (pounds)')
ylabel('Deflection (inches)')
grid on

OUTPUT:

Deflection of Cantilever Beam


0.8

0.7

0.6
Deflection (inches)

0.5

0.4

0.3

0.2

0.1

0
0 100 200 300 400 500 600 700 800
Force (pounds)

________________________________________________________________________
Experiment # 01 Page 9 of 9
Control Systems Lab

You might also like