i need help to compelete my code

3 Ansichten (letzte 30 Tage)
Neno Nano
Neno Nano am 4 Apr. 2020
Beantwortet: Prasad Reddy am 26 Apr. 2020
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
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.
Neno Nano
Neno Nano am 4 Apr. 2020
hello first of all am not that code for matlab
i try to solve this qustion but it is not correct so i post it here to see if you guys can help me
and am not use it before so please if any one can write the code or tell me if my code if wrong

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Prasad Reddy
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

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by