Question

Question 1: 1. Figure out what the following MATLAB code does (Notice that R n = 500 for jay - 1:4 ifjoy > 1;oldtime = time;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. This code runs four times. But most of the calculations happen from the second run, i.e. 3 times. In each run, it creates an nxn matrix M. Then performs multiplication between M and its transpose, and stores the value in A. Then it creates Cholesky factorization for 5 times. Then calculates how much time it took the cpu to perform the calculation. Then on the next run, it doubles the dimension of the matrices performs the entire calculation again, and compares how much more time it took for that iteration. And returns the ratio of new time to old time.

2.

The code provides different values each time, and it seems the difference between between 1st ratio and second ratio is not that much, however, in the last ratio, when n is 8 times it original value, difference is more.

Screenshot: i

Editor DAPrograms MATLAB zap.m Command Window > zap n 500; for jay-1 : 4 ratio - if jay>l:oldtime time:end M = randn (n) ; 4·

Screenshot: ii

zap.m X > zap n = 500; for jay-1 : 4 ratio = if jay>l:oldtime time:end M = randn (n) ; 4 . 6667 t cputime for rep 1:5 ratio-

3. I expected the ratio to increase gradually for each iteration, as each time the dimension of the matrices get doubled, that means double or squared the operations, so it should take more than double the time of that of previous time, hence the ratio should be increasing. So the result is somewhat reasonable, but not consistent enough for the first two ratio.

If we increase n (in the following case, n is set to 800, instead of 500), the result is more prominent:

media%2F2e0%2F2e03c7f1-3504-4d37-aab2-74

or if number of times the loop rep is executed is increased (in the following case, rep is executing 8 times, instead of 5):

Editor D:Programs MATLAB zap.m Command Window zap.m > zap n = 500; for jay-1:4 ratio = if jay>l:oldtime time:end M randn (n);

Add a comment
Know the answer?
Add Answer to:
Question 1: 1. Figure out what the following MATLAB code does (Notice that R n =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • stion 1: Figure out what the following MATLAB code does (Notice that R = LT) n=500:...

    stion 1: Figure out what the following MATLAB code does (Notice that R = LT) n=500: for jay- 1:4 if jay > 1; oldtime-time; end M = rand(n) t = cputime; for rep 1: R chol(A); end time-cputime-t if jay > 1; ratio = time/oldtime, end enc If you put these instructions into a file named, say, zap.m, you can run the program by typing zap from the MATLAB command line. The functions randn, cputime, and chol are built-in MATLAB...

  • Using MATLAB please. A = rand(m,n) x = rand(n,1) b = A * x 1. What...

    Using MATLAB please. A = rand(m,n) x = rand(n,1) b = A * x 1. What does the following code compute? Explain what operation the third line is per- forming b = zeros(m, 1); for i = 1:m b(i) = A(i,:) * x; end Make a copy of the relevant MATLAB function you wrote earlier, and use this code in place of the two loops you wrote. Time both codes on a sufficiently large problem. Which performs faster?

  • what is a good matlab code to out put this matrix from question 1 to 3...

    what is a good matlab code to out put this matrix from question 1 to 3 HITA 1)-The general form cf the quadratic equation is a +bx+c 0 Wrte a MATLAB function named quadratic that finds the two roots of this equation and x when given the coeficients a, b and c 2)-Create a random matrix A in MATLAB with 6 rows and 3 oolumns using the rand) function 3)-Now modify quadratic by so that il can take each row...

  • Matlab ( True or False questions ) Statement while - end does not need a "conditional...

    Matlab ( True or False questions ) Statement while - end does not need a "conditional expression" Given a recursive problem, there is only one way to program a while - end loop A while - end loop will run forever unless one statement alters the "conditional expression" The loop while -9 == -9 end will not run forever Counting by one is always done by statement i = i + 1 Dividing 1 by 27 can be accomplished by...

  • 3. Consider the following Matlab code. s-0; clear s.norm for i 1:10000 r-rand(1); % generate a uniform random, numb...

    3. Consider the following Matlab code. s-0; clear s.norm for i 1:10000 r-rand(1); % generate a uniform random, number on [0,1] S-S+(3+rr) s.norm(i)-S/i end plot( 1:10000,s.norm) % make a plot of s.norma) versus i (5 pts) What will the plot look like? (10 pts) Will the function/vector s.norm(n) converge to something as n gets large? If so, what? If not, why not? Justify your answer. (5 pts) If we were to run this code multiple times - overlaying the plots...

  • Can you help me with this question please? For the code, please do it on MATLAB. Thanks

    Can you help me with this question please? For the code, please do it on MATLAB. Thanks 7. Bonus [3+3+4pts] Before answering this question, read the Google page rank article on Pi- azza in the 'General Resources' section. The Google page rank algorithm has a lot to do with the eigenvector corresponding to the largest eigenvalue of a so-called stochastic matrix, which describes the links between websites.2 Stochastic matrices have non-negative entries and each column sums to1, and one can...

  • 1. [12 marks] In the following parts of this question, write a MATLAB code to solve a linear syst...

    1. [12 marks] In the following parts of this question, write a MATLAB code to solve a linear system A b (A is a square nonsingular matrix) using Jacobi and Gauss-Seidel algorithms. Do not use the built-in Matlab functions for solving linear systems (a) Write a Matlab function called Jacobi that consumes a square n x n matrix A, and an n x 1 vector b, and uses the Jacobi technique to solve the system Ax-b, starting with the zero...

  • Please read the instructions carefully and show me the matlab code in detail and the graph...

    Please read the instructions carefully and show me the matlab code in detail and the graph For all the questions below, whenever necessary, use a time resolution of 10ms for your time axis and plot in the range t 10,10]. Matlab hint for time axis: t [0:0.01:101 Remember your script should be self-sufficient and run without any errors to receive any points. Question 1. Find the impulse response h(t) for the LTIC system (1) provided below, using Matlab's built in...

  • matlab help plz Overview: In this exercise, you will write code to compare how two different mumerical methods (a mi...

    matlab help plz Overview: In this exercise, you will write code to compare how two different mumerical methods (a middle Riemann sum, and MATLAB's integral function) evaluate the function fx) and the x-axis. The code should output the error between the two calculated areas. area between a Function Inputs Func- the function to be numerically integrated. a-the lower interval value. b-the upper interval value. N-the number of rectangles to be used. Function Outputs: Area Riemann- the numerical approximation for the...

  • 1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector...

    1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector containing the values of the integral (A) for n= 1,2,3,..., n. The function must use the relation (B) and the value of y(1). Your function must preallocate the array that it returns. Use for loop when writing your code. b) Write MATLAB script that uses your function to calculate the values of the integral (A) using the recurrence relation (B), y(n) for n=1,2,... 19...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT