Question

Take any system of 3x3 matrix equation which is linear Solve the system using generic algorithm...

Take any system of 3x3 matrix equation which is linear

Solve the system using generic algorithm for the Gauss Seidel method

The code must take the matrix input by the user

It should be solvable for any nxn system

Give only a working proper MATLAB code

if you dont know do not answer or i will dislike badly

compare with original solution and then break.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The MATLAB CODE is shown, it works for all inputs

A sample solution is shown

clc;clear all
%takes a sample matrix and solves the system AX=B
a=[9 -2 3 2;2 8 -2 3;-3 2 11 -4;-2 3 2 10]; %%Sample matrix A
b=[54.5;-14;12.5;-21]; %%RHS vector
ans1=GaussSeidelm(a,b) %%Function call
function X=GaussSeidelm(A,B) %%Function implementing GS method
[r c]=size(A); %%Finds dimension
X(1:r,1)=0; %%Initialises to 0
k=1;
act=A\B; %%Actual solution
while(true) %%GS method starts till the time loop is true
for(i=1:r)
sum=0;
for(j=1:c)
if(i==j)
continue
end
sum=sum+A(i,j)*X(j,1); %%Sums all elements
end
X(i,1)=(B(i)-sum)/A(i,i);
end
if(act-X<=0.0001)
break %breaks if error is less
end
end
end

1 - w N 3 - 4- 5 - 6 7 - 8 9- 0 - 1 - 2- 3 - clc;clear all Stakes a sample matrix and solves the system AX=B a=[9 -2 32;2 8 -Command Window ans1 5.0001 -2.0000 2.5000 -1.0000 fx >>

Add a comment
Know the answer?
Add Answer to:
Take any system of 3x3 matrix equation which is linear Solve the system using generic algorithm...
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
  • 1. [12 marks] In the following parts of this question, write a MATLAB code to solve a linear syst...

    1. [12 marks] In the following parts of this question, write a MATLAB code to solve a linear system A b (A is a square nonsingular matrix) using Jacobi and Gauss-Seidel algorithms. Do not use the built-in Matlab functions for solving linear systems (a) Write a Matlab function called Jacobi that consumes a square n x n matrix A, and an n x 1 vector b, and uses the Jacobi technique to solve the system Ax-b, starting with the zero...

  • Dijkstra’s Algorithm: You have to implement the Dijkstra’s algorithm and apply it on the graph provided below. You have to take the input from the user as an adjacency matrix representing the graph,...

    Dijkstra’s Algorithm: You have to implement the Dijkstra’s algorithm and apply it on the graph provided below. You have to take the input from the user as an adjacency matrix representing the graph, the source, the destination. Then you have to apply the Dijkstra’s algorithm to find the shortest path from the source and the destination, and  find the shortest route between the source and the destination. For the input you have to read it from a file. It will...

  • A state space linear system is shown below. Use Matlab to solve the following problems. Requirement...

    A state space linear system is shown below. Use Matlab to solve the following problems. Requirement for project report: (1) Results; (2) Matlab code. dx1/dt=-x1(t)+u(t) dx2/dt=x1(t)-2x2(t)-x3(t)+3u(t) dx3/dt=-3x3(t) y(t)=-x1(t)+2x2(t)+x3(t)+u(t) (1) Assume the system has input u(t)=e-3t if t>t0 and zero initial state x(0)=[0;0;0]. Using the transition matrix obtained, compute the system’s output (analytical solution), and plot the output as a function of time (t within 0 to 10). (2) Using the function lsim to simulate the system’s output (analytical solution), and...

  • Using MATLAB Linear Interpolation: The following equation illustrates how to calculate an output for any input,...

    Using MATLAB Linear Interpolation: The following equation illustrates how to calculate an output for any input, using linear interpolation. The input must be within the bounds of the data set. The constants come from the data set; they are the nearest data points that bound the original input. (constants from data set--> y1, x1, y2) (output--> y) (input--> x) Create a MATLAB function file that calculates the linearly interpolated y-value (output) provided an x-value (input). The function should linearly interpolate...

  • 6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you...

    6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you will practice working with arrays. Your program will read lines of text from the keyboard and use an array to track the number of times each letter occurs in the input text. You will use the contents of this array to generate a histogram (bar graph) indicating the relative frequencies of each letter entered. Test cases are available in this document. Remember, in addition...

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