Please show the code for the following questions using basic MATLAB operations .
ID: 3786200 • Letter: P
Question
Please show the code for the following questions using basic MATLAB operations. Please also include step by step comments explaining all processes and functions. I am new to the MATLAB language. Thanks in advance.
Problems In this lab, we will use MATLAB to solve a variety of problems. 1. Vector Manipulation (40 points) Use MATLAB to generate a row vector A and a column vector B of the same size specified by the user. Both A and B contain as elements random integers from 0 to 100. Calculate the following quantities (a) The sum of A and B (b) A minus B (c) The inner product of A and B (d) The outer product of A and B For a b, implement the calculations using both a for loop and MATLAB vector operations. For d, implement using MATLAB vector operations. 2. Solving a linear system of equations (20 points) Use MATLAB to solve the following system of linear equations: 118a2+ 451TA+ 176r3+ 28rit 103r3+ 31313+ 112 224rit 470r2+ 626r3+ 1688r4 3. Graphing Functions (40 points) Use MATLAB to graph the following functions: (a) r2 T 1 from r 2 to r 2 (b) -2a3 10r2 3r 4 from z -2 to r 2 pi pm (c) tan(r) from r tor (d) ln(r) from r 0 to r 10 Hint: use log(r) in MATLAB for natural log Display each plot in a separate window, and use your judgment to make the plots look continuousExplanation / Answer
1. x=input("enter no. of elements ") ; %this will take input from user
A=randi([1 100],1,x) ; %randi will generate random integer between 1 to 100 of matrix 1 by 5
B=randi([1 100)],x,1) ; % randi will generate random integer between 1 to 100 of matrix 5 by 1
C=A+B;
D=A-B;
disp(C);
disp(D);
E=dot(A,B); %we use dot(a,b) for dot product alternatvely we can use A*B
disp(E);
F=B*A % SINCE A is 1 by 4 matrix and B is 4 by 1 for outer product e will have to do B*A this will give 4*4 matrix
--------0------
2.
syms x1 x2 x3 x4 x5 % declare system of equations
%defining the equations
eqn1=28*x1+58*x2+34*x3+92*x4+2*x5==1;
eqn2=56*x1+118*x2+176*x3+451*x4+236*x5==2;
eqn3=28*x1+59*x2+103*x3+271*x4+120*x5==3;
eqn4=112*x1+235*x2+313*x3+874*x4+398*x5=4;
eqn5=224*x1+479*x2+626*x3+1688*x4+733*x5=5;
---------0-----------
3.
b)
x = [-2:2];
y=-2*x.^3 + 10*x.^2+3*x+4;
plot(x,y)
c)
x=[-pi/2:pi/2];
y=tan(x);
plot(x,y)
d)
x=[0:10];
y=log(x);
plot(x,y)