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

Use the documentation links provided to answer the following questions: a) The n

ID: 3566418 • Letter: U

Question

Use the documentation links provided to answer the following questions: a) The ntbrool function allows one to specify the degree of the root they wish to take (e.g., a cube root would have a degree of 3, square 2, etc.). Write the MATLAB code to take the 5th root of 187. b) The length function can be used to return the length of a vector. Write the MATLAB code to return the length of a vector x = [1 2 4 5]. What is the output? c) The load function can be used to import data from a file into a vector. Write the MATLAB code to load a file named "myfile.txt" into a vector. Suppose we have a vector x = [1 3 5 7 9], and we want to find the sum and product of all the elements in the vector without using the 'sum' or 'prod' built-in functions. This can be done using for-loops. a) Using a loop, and without using the sum function, write the MATLAB code to add all of the elements of x together. What is the output? b) Using a loop, and without using the prod function, write the MATLAB code to multiply all of the elements of x together. What is the output?

Explanation / Answer

nthroot documentation: http://www.mathworks.com/help/matlab/ref/nthroot.html
length documentation: http://www.mathworks.com/help/matlab/ref/length.html

a) The nthroot function allows one to specify the degree of the root they wish to take (e.g., a cube root would have a degree of 3, square 2, etc.).
Write the MATLAB code to take the 5th root of 187.

nthroot(187, 5)

b) The length function can be used to return the length of a vector. Write the MATLAB code to return the length of a vector x = [1 2 4 5]. What is the output?

length(x)

OUTPUT : 4

c) The load function can be used to import data from a file into a vector. Write the MATLAB code to load a file named "myfile.txt" into a vector.

x = load("myfile.txt");

2) given vector x = [1 3 5 7 9];

a) sum = 0;
   for i=1:length(x)
       sum = sum + x(i);
   end
   sum

OUTPUT:
sum = 25

b) product = 1;
   for i=1:length(x)
       product = product*x(i);
   end
   product

OUTPUT:
product = 945

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