Question
DO NOT GIVE ME A STEP BY STEP SOLUTION ON PAPER.

JUST GIVE ME THE MATLAB FUNCTION FILE (code) TO BE USED IN MATLAB. ONLY


(a) use the Gauss-Seidel method to solve the following system until the percent relative error falls below s a. 5%. 10x1 + 2x
0 0
Add a comment Improve this question Transcribed image text
Answer #1

MATLAB CODE

clear;clc
format compact
%% Read or Input any square Matrix
A = [10 2 -1;
-3 -6 2;
1 1 5];% coefficients matrix
C = [27;-61.5;-21.5];% constants vector
n = length(C);
X = zeros(n,1);
Error_eval = ones(n,1);
%% Check if the matrix A is diagonally dominant
for i = 1:n
j = 1:n;
j(i) = [];
B = abs(A(i,j));
Check(i) = abs(A(i,i)) - sum(B); % Is the diagonal value greater than the remaining row values combined?
if Check(i) < 0
fprintf('The matrix is not strictly diagonally dominant at row %2i\n\n',i)
end
end
%% Start the Iterative method
iteration = 0;
while max(Error_eval) > 0.05
iteration = iteration + 1;
Z = X; % save current values to calculate error later
for i = 1:n
j = 1:n; % define an array of the coefficients' elements
j(i) = []; % eliminate the unknow's coefficient from the remaining coefficients
Xtemp = X; % copy the unknows to a new variable
Xtemp(i) = []; % eliminate the unknown under question from the set of values
X(i) = (C(i) - sum(A(i,j) * Xtemp)) / A(i,i);
end
Xsolution(:,iteration) = X;
Error_eval = sqrt((X - Z).^2);
end
%% Display Results
GaussSeidelTable = [1:iteration;Xsolution]'
Coeff_Mat_Contant_Mat_X_value= [A C X]

OUTPUT

GaussSeidelTable =
1.0000 2.7000 8.9000 -6.6200
2.0000 0.2580 7.9143 -5.9345
3.0000 0.5237 8.0100 -6.0067
4.0000 0.4973 7.9991 -5.9993
Coeff_Mat_Contant_Mat_X

_value =
10.0000 2.0000 -1.0000 27.0000 0.4973
-3.0000 -6.0000 2.0000 -61.5000 7.9991
1.0000 1.0000 5.0000 -21.5000 -5.9993
>>

:n, 古 ae l ine an array the coelllClents elements j (1)-[]; % eliminate the unknows coefficient from the remaining coefficiGaussSeide!Table = 1.0000 2.0000 3.0000 4.0000 2.7000 0.2580 0.5237 0.4973 8.9000 -6.6200 7.9143 5.9345 8.0100 6.0067 7.99915

Add a comment
Know the answer?
Add Answer to:
DO NOT GIVE ME A STEP BY STEP SOLUTION ON PAPER. JUST GIVE ME THE MATLAB FUNCTION FILE (code) TO...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (a) use the Gauss-Seidel method to solve the following system until the percent relative error fa...

    In matlab, what is the code for the problem. (a) use the Gauss-Seidel method to solve the following system until the percent relative error falls below s a. 5%. 10x1 + 2x2-x,-27 3x1 -6x2 + 2x3 61.5 25x321.5 b. (b) write an M-file to implement the Gauss-Seidel method using the above system as a test case (a) use the Gauss-Seidel method to solve the following system until the percent relative error falls below s a. 5%. 10x1 + 2x2-x,-27 3x1...

  • Given the equations write a Matlab Function File (code) for 10x1 + 2x2 - x3 =...

    Given the equations write a Matlab Function File (code) for 10x1 + 2x2 - x3 = 27 -3x1 -5x2 +2x3 = -61.5 x1 +x2 +6x3 = -21.5 (A) Compute the determinant (B) Use Cramer's rule to solve for the x's (C) Solve by naive Gauss elimination. Show all steps of the computation.

  • Using MATLAB, develop an M-file to determine LU factorization of a square matrix with partial pivoting....

    Using MATLAB, develop an M-file to determine LU factorization of a square matrix with partial pivoting. That is, develop a function called mylu that is passed the square matrix [A] and returns the triangular matrices [L] and [U] and the permutation P. You are not to use MATLAB built-in function lu in your codes. Test your function by using it to solve a system of equations listed below in part 3. Confirm that your function is working properly by verifying...

  • helpp I'm this exam 2) Use the Gauss-Seidel method to solve the following system until the...

    helpp I'm this exam 2) Use the Gauss-Seidel method to solve the following system until the percentage relative error is below 0.5% -2x1 + 2x2 – X3 = 25 - 3x1 - 6x2 + 2x3 = -40.5 X1 + x2 + 5x3 = -25.5 a) Record the table-style values. (Iteration, X1, X2, X3, Error X1, Error X2, Error X3). х iteration error X1 x2 x3

  • Could someone explain these four promblems on matlab and if you do, could you write what...

    Could someone explain these four promblems on matlab and if you do, could you write what you wrote on matlab I.e. on the command window or script. Also if you have written anything by hand can you write neatly. Also an explain of how you did it would be greatly appreciated. 1] 5 points) Write the following set of equations in Matrix form and use Matlab to find the solution. 50 -5x3-6x2 2x2 + 7x3-30 x1-7x3-50-3x2 + 5x1 [2] (10...

  • Solve the following system of equations using Gauss-Seidel method. 3x1 +6x2 +2x3 = 9 12% +...

    Solve the following system of equations using Gauss-Seidel method. 3x1 +6x2 +2x3 = 9 12% + 7x2 +3x,-17 2x, +7x2 -11x, 49 Conduct 3 iterations. Calculate the maximum absolute relative approximate error at the end of each iteration, and Choose [x, ]-l 3 5las your initial guess.

  • Test II. ITERATIVE SOLUTION OF SYSTEMS OF LINEAR EQUATIONS Solve the following linear system using Gauss-Seidel...

    Test II. ITERATIVE SOLUTION OF SYSTEMS OF LINEAR EQUATIONS Solve the following linear system using Gauss-Seidel iterative method. Use x = x; = x; =0 as initial guesses. Perform two iterations of the method to find xị, xį and xſ and fill the following table. Show all the calculation steps. 10x, + 2x2 - X3 = 27 -3x, - 6x2 + 2xz = -61.5 X1 + x2 + 5x3 = -21.5

  • Homework4 Solve the following problems in form of report using Microsoft word format. Three students per...

    Homework4 Solve the following problems in form of report using Microsoft word format. Three students per report. The names and student no. are to be declared. Due date Mo. 26.03.2020 12:00 PM Solve the following system of linear equations: [ 0.8 -0.4 011 (41 -0.4 0.8 -0.41*2} = 25 0 -0.4 0.8 |(x3) (105) (1) Using the Gauss-Seidel iterative method until the percent relative error falls below Ea < 5% (2) With Gauss-Seidel using overrelaxation (1 = 1.2)until En 5%...

  • DO THIS IN MATLAB PLEASE DO THIS IN MATLAB Create a script file that performs the...

    DO THIS IN MATLAB PLEASE DO THIS IN MATLAB Create a script file that performs the following calculations. Your script will use the functions you create. Label all graphs appropriately. For this project, do not have your homemade functions fprintf anything, instead have all your fprintf commands within your script. Attach your published script file along with .m files for your functions. Exercise 1. A fundamental iterative method for finding the roots of equations of one-variable is known as Newton's...

  • help me with this. Im done with task 1 and on the way to do task...

    help me with this. Im done with task 1 and on the way to do task 2. but I don't know how to do it. I attach 2 file function of rksys and ode45 ( the first is rksys and second is ode 45) . thank for your help Consider the spring-mass damper that can be used to model many dynamic systems -- ----- ------- m Applying Newton's Second Law to a free-body diagram of the mass m yields the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT