필터 지우기
필터 지우기

i need help to compelete my code

조회 수: 1 (최근 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 CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by