i need help to compelete my code

2 ビュー (過去 30 日間)
Neno Nano
Neno Nano 2020 年 4 月 4 日
回答済み: Prasad Reddy 2020 年 4 月 26 日
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 件のコメント
John D'Errico
John D'Errico 2020 年 4 月 4 日
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 2020 年 4 月 4 日
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

サインインしてコメントする。

回答 (1 件)

Prasad Reddy
Prasad Reddy 2020 年 4 月 26 日
% 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

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by