i need help to compelete my code
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Use Gauss elimination method to solve the following system:
%% Gauss Elimination
% Get augmented matrix
AB = [A, B];
% With A(1,1) as pivot xelement
alpha = AB(2,1)/AB(1,1);
Ab(2,:) = AB(2,:) - alpha*AB(1,:);
alpha = AB(3,1)/AB(1,1);
AB(3,:) = AB(3,:) - alpha*AB(1,:);
% With A(2,2) as pivot Element
alpha = AB(3,2)/AB(2,2);
AB(3,:) = AB(3,:) - alpha*AB(2,:);
any help am stack
3 Kommentare
John D'Errico
am 4 Apr. 2020
What you do not want to do is write the elimination in a hard coded form, thus explicitly subtracting some multiple of row 1 from row 2, etc.
This will be pure hell one day, when you are then asked to solve a 4 or 5 variable problem. What you need to learn to do is how to write it in the form of a loop. So now you would have a loop that runs over the other rows. Now you need only write the row operation ONCE.
Then you will need to learn other things, like pivoting, which will be important when it turns out that you have a zero pivot element, so you would otherwise be forced to divide by zero. (That is, what would happen if AB(1,1) were zero?)
One thing at a time though. Start with a loop.
Antworten (1)
Prasad Reddy
am 26 Apr. 2020
% Bro This code will work, if you have any more doubts please feel free to message me.
clc
clear all
A=[2 1 1
3 2 3
1 4 9];
b=[10
18
16];
Ab=[A,b]
Ab(1,:)=Ab(1,:)/Ab(1,1); % this is to make the element Ab(1,1)=1
Ab(2,:)=Ab(2,:)-Ab(2,1)*Ab(1,:); % this is to make the element Ab(2,1)=0
Ab(3,:)=Ab(3,:)-Ab(3,1)*Ab(1,:);% his is to make the element Ab(3,1)=0
Ab(2,:)=Ab(2,:)/Ab(2,2); % this is to make the element Ab(2,2)=1
Ab(3,:)=Ab(3,:)-Ab(3,2)*Ab(2,:); % this is to make the element Ab(3,2)=0
Ab(3,:)=Ab(3,:)/Ab(3,3);
z=Ab(3,4);
y=Ab(2,4)-Ab(2,3)*z;
x=Ab(1,4)-Ab(1,2)*y-Ab(1,3)*z;
x
y
z
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!