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

Learn built-in MATLAB functions that will be useful in the upcoming lab Learn ho

ID: 3817726 • Letter: L

Question

Learn built-in MATLAB functions that will be useful in the upcoming lab Learn how to calculate the sum and product of a vector using loops Submit your pre-lab answers in Bbleam under the Lab 9 pre-lab assignment area prior to the start of class. Use the documentation links provided to answer the following questions: nthroot documentation: length documentation: 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. 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? 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. 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? 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

2)

function fsum = getsum(x)

ln = size(x,2);

fsum=0;

for i = 1:ln

fsum = fsum + x(i);

end

end

function fprod = getprod(x)

ln = size(x,2);

fprod=1;

for i = 1:ln

fprod = fprod * x(i);

end

end

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