Only do Problem #2 EE 221 Computing for Engineers Homework #16 Problem #1/20 poi
ID: 2304314 • Letter: O
Question
Only do Problem #2
EE 221 Computing for Engineers Homework #16 Problem #1/20 points) Write a script in Matlab and save it as.m file with name HW16 1. The script will execute the following tasks: a) Let the mathematical function fx) be defined as f(x) - exp 0.5x) cos(10x) Use fzero) to find the zero of f(x) x0-0.1. b) Find the roots of the following polynomial using roots command g(x)-2x+x -5 Submit the script as a.m file. (Note: Script is a list of commands which is different from functions) Problem #2(30 points) Let the two vectors x & y and the matrix z be defined as follows 2.4 x2.21.5z2.13.2 1.9 3.1 1.2 3.2 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??12 3- Evaluate L1 4- Evaluate Linf lll S- Evaluate the dot product N-x.y) 6- Evaluated the angle in degrees between the vectors x & y 7- Evaluate M2zllz 8- Evaluate M1 zll 9- Evaluate Minf-11zlloExplanation / Answer
I am giving you a code which contain the solution of all the parts of problem 2.
clear all
close all
clc
%% For Problem #2
% part 1
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]
% now L2 = ||x||_2 = norm(vector) return norm2
% part 2
L2 = norm(x)
% part 3
% now for general norm, norm(vector,p) returns p-norm of vector
L1 = norm(x,1)
% part 4
%now calculating L_inf
Linf = norm(x,Inf)
% part 5
% now evaluating dot product of x and y
N = dot(x,y)
% part 6
% angle between x and y
% angle is given by, angle = Inverse__cos(dot(x,Y)/(norm(x)*norm(y)))
% this return angle in Degrees
angle = acos(dot(x,y)/(norm(x)*norm(y)))
% part 7
% similarly norm of matrix z
M2 = norm(z)
%part 8
% 1-norm of matrix z
M1 = norm(z,1)
% part 9
% Inf-norm of matrix z
Minf = norm(z,Inf)
Just copy and paste the program and run it. You will get the desired answer.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.