Question: 4) Working with Vectors: a) A column vector x of size n is usually represented, in C++, by a 1-dimensional array. Adding two vectors x
4) Working with Vectors: a) A column vector x of size n is usually represented, in C++, by a 1-dimensional array. Adding two vectors x and y then reduces to adding the corresponding elements x[0]+y[0], x[1]+y[1], etc. Write a C++ function called addVectors() that has four parameters: three integer arrays x, y and z and their size, n. Let your function store the sum of x and y in the array z.
Write a driver program to test your function using the following data: = [ ] and b [ ] Sample output b) The norm of a vector x, written as ?x?, is a measure of its size (a scalar quantity).
One of the simple vector norms is the Euclidean norm, defined as ?x? =? . Add to your program of Question (4a) a function called norm2() that takes as parameters an integer array, x, and its size, n. Let the function return the double value representing the Euclidean norm of x.
Add to your program statements to print the norms of the vectors and given above. Sample output
4) Working with Vectors: a) A column vector x of size n is usually represented, in C+, by a 1-dimensional array. Adding two vectors x and y then reduces to adding the corresponding elements x[0Hy[0,xHy[1l], ...etc Write a Ct+ function called addVectors) that has four parameters: three integer arrays x, y and z and their size, n. Let your function store the sum of x and y in the array z. Write a driver program to test your function using the following data: 1and b-5 -2 Sample output 2 ress any key to continue - - - - b) The norm of a vector x, written as llxll, is a measure of its size (a scalar quantity). One of the simple vector norms is the Euclidean norm, defined as Ikl,-Jaf + +--+ . Add to your program of Question (4a) a function called norm2 () that takes as parameters an integer array, x, and its size, n. Let the function return the double value representing the Euclidean norm of x. Add to your program statements to print the norms of the vectors a and b given above. Sample output 2 orms of Uector a-3.87298 orms of Uector b-5.562776 Press any key to continue-_
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
