Please provide a code that will run. Thank you for your help. Problem #2 (30 poi
ID: 2291015 • Letter: P
Question
Please provide a code that will run. Thank you for your help.
Problem #2 (30 points) Let the two vectors x & y and the matrix z be defined as follows: 1.2 2.2 4.1 x2.2y1.5z2. -3.2 1.9 3.1 1.2 3.2 2.4 1.35 0.35 Write a script in Matlab and save it as .m file with name HW16_2. The script will execute the following tasks: 1- Enter the vectors x &y; and the Matrix z into the script. 2- Evaluate L2=11x112 3- Evaluate L1xll 4- evaluate Linf=llxlloo 5 Evaluate the dot product N-(x,y) 6- Evaluated the angle in degrees between the vectors x & y 7- Evaluate M2=I 2 8- Evaluate M1 Iz 9- Evaluate Minf=Izlo Submit the script as a.m file. (Note: Script is a list of commands which is different from functions)Explanation / Answer
MATLAB code is pasted below in bold letters.copy that in a script file and execute.
clc;
close all;
clear all;
x = [1;2.2;-1.35]
y = [-2.4;1.5;0.35]
z = [-1.2 2.2 4.1; 2.1 -3.2 1.9;3.1 1.2 3.2]
L2 = norm(x,2)
L1 = norm(x,1)
Linf = norm(x,inf)
N = x .* y
CosTheta = dot(x,y)/(norm(x)*norm(y));
ThetaInDegrees = acosd(CosTheta);
M2 = norm(z,2)
M1 = norm(z,1)
Minf = norm(z,inf)
Results:
x =
1.0000
2.2000
-1.3500
y =
-2.4000
1.5000
0.3500
z =
-1.2000 2.2000 4.1000
2.1000 -3.2000 1.9000
3.1000 1.2000 3.2000
L2 =
2.7681
L1 =
4.5500
Linf =
2.2000
N =
-2.4000
3.3000
-0.4725
M2 =
5.9743
M1 =
9.2000
Minf =
7.5000
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.