{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Test_Problems

# Test_Problems - matrices P& Q and scalars alpha and beta...

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

1. Consider the following Matlab code written in a script file and answer the questions at the end. Hint, work through the problem by hand and write it out. x=[3 7 -1 4]; for i=1:4 jmax=1; max=x(jmax); for j=2:4 if x(j)>max max=x(j); jmax=j; end end x(jmax)=-100;y(i)=max end After this code is run, what is (a) x? (b) y? (c) in one sentence, explain what is the program doing? 2. Linear Combination a) Given the following matrices P and Q, and scalars α and β , Compute: R= α *P + β *Q 2 1 1 1 2 4 3 2 1 ; 3 1 2 ; 1; 2 1 2 3 2 1 1 P Q α β - - = = - = - = - - b) Write a Matlab function file, called ‘linearcomb.m’ that when sent ANY n×m
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: matrices, P & Q, and scalars alpha and beta, it computes the linear combination, C. You must use loop(s) to perform the linear combination and cannot use any built in MATLAB commands or vectorization (i.e. colon notation for additions). Then, in the MATLAB command window (see below) call the function using matrices and scalars already defined there. ==================MATLAB COMMAND WINDOW=================== >> A= [1 -2 3; -2 1 -2; 3 3 2]; B= [6 1 -2; 3 4 2; 5 6 1]; >> c=4; d=-1; >>...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online