Question
On Matlab: Use both X=A\b and X=inv(A)∗b to find x,y,z. Use tic toc to time each method.

Then create a general solver to solve any linear system of n equations and n unknowns of the form AX = b. Allow the user to input the n×n matrix A and n×1 column vector b. Use X = A\b to solve the system in your script and display the solution to the user. Try your solver with A = randi(50, 10),
b = randi(20, 10, 1) and A = randi(3, 500), b = randi(7, 500, 1).

Solve the system of equations: z -2y 232 52 Define A as the matrix of coefficients, X y, zl and b is a column vector representing the right- hand side of these equations. 3 7 -61 4 1 2 23 Recall the matrix form of this equation is AX b with solution X A 1b 3 7 -6 1 -2 23 -3 La L-6 0 5
0 0
Add a comment Improve this question Transcribed image text
Answer #1

ex.m

function x=y(A,B)
% Get the size of the matrix A and B
[m,n] = size(A);
[i,j] = size(B);

% Check if the dimension matches
if(n ~= i)
fprintf('Matrix dimension does not match\n');
else
% Start the tic.
tic;
fprintf('Using A\\B \n');
x = A\B
fprintf('Using inv(A)*B\n');
x = inv(A)*B
timeToComplete = toc
end
end

OUTPUT:

>> A = [3 7 6;1 -2 23;-6 0 5];
>> B = [4; -3; 2 ];
>> ex(A,B)

Using A\B

x =

-0.3726
0.7715
-0.0471

Using inv(A)*B

x =

-0.3726
0.7715
-0.0471


timeToComplete =

4.1055e-004


ans =

-0.3726
0.7715
-0.0471

Add a comment
Know the answer?
Add Answer to:
On Matlab: Use both X=A\b and X=inv(A)∗b to find x,y,z. Use tic toc to time each...
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
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