HW2prob3 - % built-in Matlab function to calculate the...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 clear clc %========================================================================== % PROBLEM 3. Functions to use with Vectors %-------------------------------------------------------------------------- % % You are given a vector "vec", defined as: vec = [45 8 2 6 98 55 45 -48 75] % (a) Create a variable called "vLength" that holds the length of the % vector "vec" modified in Problem 2. Do not just enter the value. You % should use a built-in Matlab function to calculate the value based on % the vector itself. vLength = length(vec) % (b) Create a variable called "vSum" that holds the sum of the elements % in vector "vec". Do not just enter the value. You should use a
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % built-in Matlab function to calculate the value based on the vector % itself. vSum = sum(vec) % (c) Calculate the mean of the vector "vec" two ways. First, use a % built-in Matlab function to find the mean of "vec", and store your % answer in a variable called "mean1". Then, use the results from % parts (a) and (b) to calculate the mean of "vec", and store your % answer in the variable "mean2". mean1 = mean(vec) mean2 = vSum/vLength % (d) Create a variable called "vProd" that holds the product of the % elements in vector "vec". You should use a built-in Matlab function % to calculate the value based on the vector itself. vProd = prod(vec)...
View Full Document

Ask a homework question - tutors are online