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

Part 1: In a matlab script create a vector (A using colon operator ranging from

ID: 3729535 • Letter: P

Question

Part 1: In a matlab script create a vector (A using colon operator ranging from 1 and 200 at a step size of 2 and a vector B using linspace command with 251 and 450 as first and last values. Decide the number of elements for vector (B they should be same as the number of elements in A), then write a program to compute the value of C (make use of for loops) where, n-no, of elements in vector tA} or {B). Before computing C, check whether no. of elements in (A and (B are same, if they are not same display the following error message "Size of vectors not consistent" Name the script file as: Team#-8B-P1

Explanation / Answer

ScreenSho

------------------------------------------------------------------------------------------------------------------------------------------------------

Code:-

%Column Matrix with step 2
A = (1:2:200);
%row matrix using linespace
B=linspace(251,450);
%set value of n
n=numel(A);
%variable for calculation
C=0;
%check the number of elements of two vector's equal
if numel(A)==numel(B)
   %for loop for calculation
   for i=1:n
       C=C+(A.*(B.^2));
   end
   %if not equal error message
else
   disp('Size of vectors not consistent.')

end
#print answer
C