In: Electrical Engineering
Instructions:
1. Solve the following problems in a MATLAB script. You will be allowed to submit only one script, please work all the problems in the same script (Hint: careful with variables names)
2. Show your work and make comments in the same script (Use %). Please write your name in the first line of the scrip with %
3. It is OK to work with other students, but what you submit should be your own work – not something copied from someone else.
P1: For the following matrices ? = [ 2.3 7.6 3.4 −5.8 ] and ? = [2.4 5.9 −6.7 9.0 ] find:
a. Matrix A time matrix B
b. Every element of matrix A times every element of matrix B
c. Determinant of matrix A
d. Transpose of matrix A
e. Subtract A from B
f. Inverse of matrix B
g. Square matrix A
h. Square every element in matrix A
i. R=inv(A)*B
j. S=A\B
P2: Let’s consider a system of 3 equations X+Y-2Z=0, X+Y+Z=1 and 2Y-Z+5=0.
a. Find the matrix of coefficients (A)
b. Find the matrix of outputs (B)
c. Solve to find the values of the variables inv(A)*B
d. Solve to find the values using equationToMatrix command (Note: you will need the symbolic library)
e. Solve using linsolve command (Note: you will need the symbolic library)
P3: For the following control system polynomial 2P3+P+P5-2P4+3P2+4=0 find the solution (roots of the polynomial)
P4: For X=-3π up to 3πin intervals of π/100.
a. Plot Y1=sin(X) as a magenta line
b. Plot Y2=cos(X) as a black double dotted line c. Plot Y1 and Y2 in the same plot without using the hold on/off command.
d. For Y3= Y1 times Y2, plot Y1, Y2 and Y3 in the same graph. Y3 will be green line. Add title, axis label and a legend.
P5: For X=0 up to 2πin intervals of π/100 with the following equations
Y4=sin(X), Y5=sin(X-0.25), Y6=sin (X-0.5), Y7=sin(X-0.75), Y8=sin(X)sin(X-0.75)
a. Plot Y4, Y5 and Y6 in the same plot. Add title, labels, legend. Plot them with different colors and line styles
b. Plot Y4, Y5, Y6 and Y7 as subplots. Add title, labels. Plot them with different colors and line styles
c. Plot Y4 and Y8 in the same plot using the hold on/off. Add title, labels. Plot them with different colors and line styles
d. Plot Y5*Y6 and Y8 in the same plot without using the hold on/off. Add title, labels. Plot them with different colors and line styles
e. Plot one of the Y equations as a 3D graph. Please add title and labels
MATLAB code is given below in bold letters.
clc;
close all;
clear all;
% Question P1
A = [2.3 7.6;3.4 -5.8];
B = [2.4 5.9;-6.7 9.0];
A*B
A.*B
det(A)
transpose(A)
A-B
inv(B)
A^2
A.^2
R = inv(A)*B
S = A\B
% Question P2
A = [1 1 -2;1 1 1;0 2 -5]
B = [0;1;0]
inv(A)*B
syms x y z
eqns = [x+y-2*z == 0,
x+y+z == 1,
2*y-z == -5];
[A,B] = equationsToMatrix(eqns)
solution = linsolve(A,B)
% Question P3
roots([1 -2 2 3 1 4])
% Question P4
X = -3*pi:pi/100:3*pi;
Y1 = sin(X);
Y2 = cos(X);
Y3 = Y1.*Y2;
figure;plot(X,Y1,'m',X,Y2,'--k',X,Y3,'g');
title('Y1(t) Y2(t) and Y3(t)');xlabel('t');
ylabel('Amplitude');legend('Y1','Y2','Y3');
% Question P5
X = 0:pi/100:2*pi;
Y4 = sin(X);
Y5 = sin(X-0.25);
Y6 = sin(X-0.5);
Y7 = sin(X-0.75);
Y8 = sin(X).*sin(X-0.75);
figure;plot(X,Y4,'m',X,Y5,'--k',X,Y6,'g');
title('Y1(t) Y2(t) and Y3(t)');xlabel('t');
ylabel('Amplitude');legend('Y1','Y2','Y3');
figure;
subplot(221);
plot(X,Y4,'m');
title('Y4(t)');xlabel('t');
ylabel('Amplitude');
subplot(222);
plot(X,Y5,'--k');
title('Y5(t)');xlabel('t');
ylabel('Amplitude');
subplot(223);
plot(X,Y6,'-g');
title('Y6(t)');xlabel('t');
ylabel('Amplitude');
subplot(224);
plot(X,Y7,'r');
title('Y7(t)');xlabel('t');
ylabel('Amplitude');