Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

One of the best features of MATLAB is that arithmetic can be done between lists

ID: 1718135 • Letter: O

Question

One of the best features of MATLAB is that arithmetic can be done between lists of numbers just as easily as between scalars. All of the operations below are to be contained within a single m-file that is to be turned in as part of your homework. Your m-file should produce output that can be printed and handed in also. Consider the column vectors: u= and v= Demonstrate how to create vectors u and v each of the following three ways: -directly between square brackets [] -using MATLAB's "." notation -using the line space command compute the inner (dot) product between the vectors perform each of the following term-by-term vector operations: u+v u-v 2u*v u/v u+v

Explanation / Answer

The matlab script file has been written below. Please save and run.

clear all;
clc;
%% Creating column vector using square brackets
u = [1; 2; 3; 4; 5];
v = [3; 5; 7 ; 9; 11];
%% Creating column vector using ':' command
u = transpose(1:1:5);
v = transpose(3:2:11);
%% Creatin column matrix using linspace
u = transpose(linspace(1,5,5));
v = transpose(linspace(3,11,5));
%% Displaying result
disp('u = ');
disp(u);
disp('v = ');
disp(v);
%% Dot product of vectors in matlab
dot_product = dot(u,v);
disp('Dot Product is ');
disp(dot_product);
%% Term by Term vector operations
a = u + v;
b = u - v;
c = 2*u.*v;
d = u./v;
disp('u + v = '); disp(a);
disp('u - v = '); disp (b);
disp('2u*v = '); disp(c);
disp('u /v = '); disp(d);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote