Help with Matlab: Solving System of Equations

Click For Summary
SUMMARY

This discussion focuses on solving a system of equations using Matlab, specifically employing the Gauss-Seidel method. The user seeks assistance with setting up the matrix and vector for the equations, represented as A and b, respectively. The correct setup involves defining the coefficient matrix A and the solution vector b, which can then be utilized in the Gauss-Seidel function for iterative solving. The user successfully understands part (b) of the task but requires clarification on part (a), which involves creating the appropriate M-file structure.

PREREQUISITES
  • Understanding of Matlab syntax and functions
  • Familiarity with the Gauss-Seidel method for solving linear equations
  • Basic knowledge of matrix operations in Matlab
  • Ability to create and execute M-files in Matlab
NEXT STEPS
  • Learn how to implement matrix operations in Matlab
  • Study the Gauss-Seidel method in detail, including convergence criteria
  • Explore advanced Matlab functions for numerical methods
  • Practice writing and debugging M-files for various mathematical problems
USEFUL FOR

Students learning numerical methods, Matlab programmers, and anyone interested in solving systems of equations using iterative techniques.

Benjamin#1
Messages
1
Reaction score
0
Help with Matlab!

Hi,
I've just started learning how to use the Matlab and came across this question in the textbook:
Consider the following system of equations:
[-1 2 4 1 0]
[ 5 4 0 0 0]
[ 0 6 1 0 4] x =
[ 0 -1 0 -1 4]
[ 1 0 -2 -5 1]

[ 1 ]
[ 1 ]
[ 1 ]
[ 1 ]
[ 1 ]


Write a Matlab script file, using the Matlab function gauss seidel that:
(a) Sets up the matrix and the vector in the system of equations
(b) Applies 5 iterations of the gauss seidel method using x(0)=[0,0,0,0,0]T

Now I know how to part (b) but can't seem to get my head around part (a). I have attached a copy of the gauss seidel function I wrote. I know for part (b) I have to put in the values of the inputs: A,b,y,N and then simply execute the function. I really don't know how to solve part (a). Help Please!:cry:

Edit to say: I honestly don't really understand part (a) of the question. If they are simply asking me to write up the matrix and the vector to calculate the x vector then I know how to do that but I don't know if the question is asking me to actually set it up as x1+x2+x3+...=some no.
If so, do I simply create an M-file like the one below?
A=[-1 2 4 1 0;5 4 0 0 0;0 6 1 0 4;0 -1 0 -1 4;1 0 -2 -5 1]
b=[1;1;1;1;1]
x = A\b

Gauss Seidel function:
function x = gs (A,b,y,N)

n = length(y);

x = y;

for k=1:N
for i=1:n
sum = b(i);
for j=1:i-1
sum = sum - A(i,j)*x(j);
end
for j = i+1:n
sum = sum - A(i,j)*y(j);
end
x(i) = sum/A(i,i);
end
y = x';
end
 
Last edited:
Physics news on Phys.org


What an opportune moment to have joined!

From my reading of part a, your interpretation is correct. Make a matrix of coefficients (what you have as A) and a vector of equation solutions (what you have as b). This allows you to use it with part b. Sometimes questions really are as easy as you think they are. ;-)
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K