1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Archy [21]
3 years ago
11

Write a function that solves the matrix equation Ax = b using Gaussian Elimination (book section 6.2). Your function should acce

pt as input a n-by-n matrix A and an n-by-1 vector b, and it should produce a n-by-1 vector x that satisfies Ax = b.
Mathematics
1 answer:
Luba_88 [7]3 years ago
5 0

Answer:

See explaination

Step-by-step explanation:

public class GaussElim{

private static final double eps = 1e-10; % set epsilon value

public static doublic[] fun(double[][] A,double[] b){

int n=b.length; %calculate length of vector b.

for( int j=0;j<n;j++){

int max=j; %find and swap pivot row.

for (int i=j+1;i<n;i++){

if(Math.abs(A[i][j])>Math.abs(A[max][j])){

max=i;

}

}

double[] t1= A[j]; %swap

A[j]=A[max];

A[max]=t1;

double t= b[j]; %swap

b[j]=b[max];

b[max]=t;

if(Math.abs(A[j][j])<=eps){

throw new ArithmeticException("Matrix is singular."); % if matrix A is a singular matrix then throw error.

}

for(int i=j+1;i<n;i++){

double alpha= A[i][j]/A[j][j];

b[i]=b[i]-alpha*b[j];

for(int k=j;k<n;k++){

A[i][k]=A[i][k]-alpha*A[j][k];

}

}

}

double[] x=new double[n]; % back substitution starts here

for(int i=n-1;i>=0;i--){

double sum=0.0;

for(int j=i+1;j<n;j++){

sum=sum+A[i][j]*x[j];

}

x[i]=(b[i]-sum)/A[i][i];

}

return x;

}

public static void main(String[] args){

int n=3;

double[][] A={{1,2,1},{4,2,0},{-1,5,-3}};

double[] b={5,3,21};

double[] x=fun(A,b);

for(int i=0;i<n;i++){

StdOut.println(x[i]);

}

}

}

You might be interested in
What is the quotient
GREYUIT [131]
What you must do for this case is to follow the following steps.
 1) Rewrite the expression completely.
 2) make a double c.
 3) Factor each quadratic expression correctly.
 4) cancel similar terms.
 Answer:
 2n
 See attached images.

3 0
3 years ago
Seventeen is three times the difference between four times a number and five
expeople1 [14]

17 = 3(4x - 5)

<em><u>Distributive property.</u></em>

17 = 12x - 15

<em><u>Add 15 to both sides.</u></em>

32 = 12x

<em><u>Divide both sides by 12.</u></em>

x = 2.67. (This is your answer.)

Let me know if you have any questions.

4 0
2 years ago
Help! Will mark brainliest
Sergeeva-Olga [200]

Answer:

24

Step-by-step explanation:

just multiply 2 on both sides

7 0
3 years ago
Trevor Has $178 in his bank account at the start of the week He makes one withdrawl during the week At the end of the week Trevo
DerKrebs [107]
178-(-62) should get you your answer
4 0
3 years ago
How do you find y = x + 8. x + y = 2 in substitoun form
Arturiano [62]
You plug in x + 8 for y in the second equation.
answer: x + x + 8 = 2
4 0
2 years ago
Other questions:
  • How many two digit whole numbers are increased by 18 when their digits are reversed?
    5·1 answer
  • 4. Which of the following points are solutions to the system of inequalities 2x - 3y &gt; 9 and -x -
    15·1 answer
  • A bag contains 1 blue, 2 green, 3 yellow, and 3 red marbles, as shown.
    13·2 answers
  • −3(y+3)=2y+3 I really need help please will mark brainiest
    11·1 answer
  • Can somebody help me with this question ?? :)
    13·2 answers
  • Question 1
    5·1 answer
  • The measure of an angle is 34 degrees. What is the measure of the supplementary angle.
    12·1 answer
  • Which best describes the range of the function f(x) = 2(3)^x?
    8·2 answers
  • Please help me asap.
    15·1 answer
  • Can someone give an explaination please<br><br>​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!