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
What is 2(5-3v)+9v=28?
almond37 [142]
10-6v+9v=28
10+3v=28
-10 -10
3v=18
3 3
v=6
7 0
3 years ago
Read 2 more answers
Evaluate ^3 sqrt 0.008- need answer asap!!
Ann [662]
∛0.008 = ∛(0.2)^3
= 0.2

hope it helps
7 0
3 years ago
a builder could get 6 sheets of sheetrock for $9 if he bought 12 sheets how much money would he have spent
SashulF [63]
He spent $18.
6=$9
12=$18

8 0
3 years ago
These trapezoids are similar. Which of the following is the correct similarity statement
LuckyWell [14K]

Check the picture below.

4 0
3 years ago
Krystal needs at least $130 to go on a trip. Her father has given her $45. Which equality could be used to determine e, the rema
lina2011 [118]

The Least amount of money we need is 130

She already has 45

She needs "e" more

Therefore:

45 + e ≥ 130

4 0
4 years ago
Other questions:
  • What is the area of a regual octagon with sides five times as long?
    6·1 answer
  • Will mark brainliest if right and you show your work!
    5·1 answer
  • Please help. I’ll mark you as brainliest if correct!
    5·1 answer
  • A museum groundskeeper is creating a semicircular statuary garden with a diameter of 21 feet. There will be a fence around the g
    9·1 answer
  • The graph shows the calling charges of two cell phone companies. At how many minutes do the two companies charge the same amount
    11·2 answers
  • PLSSSS HELPPPPPP I WIIILLLL GIVEEE BRAINLIEST!!!!!! PLSSSS HELPPPPPP I WIIILLLL GIVEEE BRAINLIEST!!!!!!
    14·1 answer
  • URGENT DUE SOON!! IF ANYONE COULD PLEASE ANSWER THE QUESTIONS ON MY PROFILE THAT WOULD BE AMAZING!!!
    9·1 answer
  • At a basketball game, a vender sold a combined total of 101 sodas and hot dogs. The number of sodas sold was 37 more than the nu
    11·1 answer
  • What are the coefficients in the problem: 392 + 4x - 5y + x
    14·1 answer
  • 10. Jan purchased 140 shares of stock in the ABC Company at a price of $18.75 per share. During the
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!