the code please for this quastion

5 Kommentare

Steven Lord
Steven Lord am 27 Dez. 2021
Since this is a homework assignment, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
function x = GaussSeidel(A,b,es,maxit)
% GaussSeidel: Gauss Seidel method
% x = GaussSeidel(A,b): Gauss Seidel without relaxation
A = [3 2 9 2 1 ; 1 2 3 1 9 ; 1 0 2 8 4;9 2 5 0 1;1 6 1 3 0]
b = [ 10 ; 35 ; 5 ; 1 ; 14 ]
es = 0.00000001
maxit = 50
x = [0 ;0 ;0 ;0 ;0]
if nargin<2,error(es,x),
end
if nargin<4|isempty(maxit),maxit=50;end
if nargin<3|isempty(es),es=0.00000001;end
[m,n] = size(A);
if m~=n, error('Matrix A must be square'); end
C = A;
for i = 1:n
C(i,i) = 0;
x(i) = 0;
end
x = x';
for i = 1:n
C(i,1:n) = C(i,1:n)/A(i,i);
end
for i = 1:n
d(i) = b(i)/A(i,i);
end
iter = 0;
while (1)
xold = x;
for i = 1:n
x(i) = d(i)-C(i,:)*x;
if x(i) ~= 0
ea(i) = abs((x(i) - xold(i))/x(i)) * 100;
end
end
iter = iter+1;
if max(ea)<=es | iter >= maxit, break, end
end
Image Analyst
Image Analyst am 27 Dez. 2021
OK, We're going to asume that is your solution, and that it works. However since it's your own homework solution, you probably should not post it here, in case other students copy it and turn it in as their own, unless you still have a problem with it. If you do still have a problem with it then you should ask a question or give the error or something, because like I said, lacking that, we'll assume it works perfectly for you.
John D'Errico
John D'Errico am 27 Dez. 2021
Bearbeitet: John D'Errico am 27 Dez. 2021
You wrote the code. At least for Gauss-Seidel. So submit it. What is the problem? If you are asking us to now write code for a Jacobi method, that is not why we re here, to do your assingment. Of course, we could do that. Would you like that? If so, then please tell us the name and address of your instructor. We will contact them directly, because we need to get credit for work that we do.
It might come up in idle conversation that you just posted your homework assignment online, and asked others to do your work for you, but I'm sure your instructor won't care. Or, would they? I might point out that many students who have done what you did, then asked to have their questions taken down, removed from Answers. One recent student said they might be kicked out of school if their questions were not removed. But your teacher would never do that to you, right?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 27 Dez. 2021

0 Stimmen

(1) initialize the given linear system entries: A = [ ]; b = [];
(2) solve it using one of the following MATLAB's fcns: x = linsolve(A, b) or x = A\b or ...
(3) write a code to employ the task iterative methods - see an example https://www.mathworks.com/matlabcentral/fileexchange/73488-gauss-seidel-iterative-method
(4) compare their accuracy using MATLAB's fcn: norm()

Kategorien

Gefragt:

am 27 Dez. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by