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]
4 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]4 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
Marking brainliest<br> Please help
solmaris [256]

Answer:

D

Step-by-step explanation:

That's the answer.......

5 0
3 years ago
Read 2 more answers
Determine the factors of x2 − 8x − 12.
Mila [183]
This polynomial cannot be factored because it is prime. Hope this helps. :)
5 0
3 years ago
Read 2 more answers
PLZ HELP ME WITH THIS!! 5/2 c = 8 1/3 *
TiliK225 [7]

Answer:

its is 3 1/3 becuae i solved it and also it has to do with step by step

4 0
3 years ago
The braking time of a car is it discrete or continuous?
Rom4ik [11]

Answer:

IT'S DISCRETE

Step-by-step explanation:

I looked it up-

So be grateful

3 0
3 years ago
Read 2 more answers
How do you work out this problem?<br><br>3x+15=66
vivado [14]

3x + 15 = 66

<u>      -15    -15</u>

3x =  51

Divide 51 by 3 which equals 17.

4 0
4 years ago
Read 2 more answers
Other questions:
  • Adrienne answered all 21 multiple choice questions correctly. If her teacher decided to let one of the questions count as bonus,
    5·1 answer
  • Last year, a certain company began producing soup A and sold all of the soup A that it produced. To make all of the soup A produ
    6·1 answer
  • ¿Alguien sabe donde puedo descargar estos libros?
    5·1 answer
  • 2) If 20 workers can build a house in 45 days, how many more workers are needed
    5·2 answers
  • Factor completely x 3 + 2x 2 – 15x
    8·1 answer
  • Kerry is looking foward to a skiing trip this weekend she checked the tempature yesterday and today, and overnigjt is dropped fr
    15·1 answer
  • Lily charges $60 for 5 tutoring sessions. What is the cost PER session?
    9·2 answers
  • Can you help me with my question​
    12·1 answer
  • What is the solution to the system of equations graphed below?
    10·1 answer
  • Please help me with this question
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!