This is Using MATLAB: I am trying to store the solution of this matrix because I...

70.2K

Verified Solution

Question

Advance Math

This is Using MATLAB:

I am trying to store the solution of this matrix because I wantto do something with the result like find the norm of that answerhowever I am stuck and cannot seem to be able to. Help would beappreciated!

---------------------------------------------

MATLAB CODE:

close all

clear

clc

A = [1 -1 2 -1;

2 -2 2 -3;

1 1 1 0;

1 -1 4 5];

b = [-8 -20 -2 4]';

x = gauss_elim(A,b)

function x = gauss_elim(A, b)

[nrow, ~] = size(A);

nb = length(b);

x = zeros(1,nrow);

  

% Gaussian elimination

for i = 1:nrow-1

if A(i,i) == 0

t = min(find(A(i+1:nrow,i) ~= 0) + i);

if isempty(t)

disp ('Error: A matrix is singular');

return

end

temp = A(i,:); tb = b(i);

A(i,:) = A(t,:); b(i) = b(t);

A(t,:) = temp; b(t) = tb;

end

for j = i+1:nrow

m = -A(j,i) / A(i,i);

A(j,i) = 0;

A(j,i+1:nrow) = A(j,i+1:nrow) + m*A(i,i+1:nrow);

b(j) = b(j) + m*b(i);

end

end

  

% Back substitution

x(nrow) = b(nrow) / A(nrow,nrow);

fprintf('Has exact solution:')

for i = nrow-1:-1:1

x(i) = (b(i) - sum(x(i+1:nrow) .* A(i,i+1:nrow))) / A(i,i);

end

end

Answer & Explanation Solved by verified expert
4.0 Ratings (745 Votes)
I think you want to say that for different system you will get different solutions but you dont want to lose the previous solution you want to store it you can simply write ax at the end your x vector    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students