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
Which are correct representations of the inequality –3(2x-5) &lt; 5(2 - x)? Select two options.​
Igoryamba

Answer:  All the ways I solved this the answer is the same,

x>5 or (5,∞) That being the Interval Notation {The second one}

Step-by-step explanation:

3 0
3 years ago
Suppose the diameter of a circle is 4 units. What is its circumference?
Murrr4er [49]
12.5663706144 or yes, 12.57
3 0
3 years ago
What is the solution of the equation x^2 + 6x + 6 = 0?
ICE Princess25 [194]
I hope it will help you.

6 0
3 years ago
Jia is tiling a floor. The floor is a square with side
NNADVOKAT [17]

Answer:

36 tiles

Step-by-step explanation:

First, find area of the square floor knowing the formula as;

Area= s^{2}

where s= side of a square.

If one side of the floor is 12 feet, then Area= 12^{2} = 144ft^{2}

Next, find the area of each tile using the same formula and given s=2 feet;

Area(tile) = 2^{2} = 4ft^{2}

To find the number of tiles needed to cover entire floor, divide area of the floor by area of one tile; 144 / 4 = 36 tiles

5 0
3 years ago
HELP ASAP 50 POINTS
Nastasia [14]

Answer: x = the quantity of 5 plus or minus the square root of 29 all over 2

Step-by-step explanation:

The given quadratic equation is expressed as

x² - 5x - 1 = 0

The equation is already in the standard form of ax² + bx + c

The general formula for solving quadratic equations is expressed as

x = [- b ± √(b² - 4ac)]/2a

From the given quadratic equation,

a = 1

b = - 5

c = - 1

Therefore,

x = [- - 5 ± √(- 5² - 4 × 1 × - 1)]/2 × 1

x = [5 ± √(25- - 4)]/2

x = [5 ± √29]/ 2

x = ( 5 + √29)/- 2 or x = (5 - √29)/2

4 0
3 years ago
Read 2 more answers
Other questions:
  • PLEASE HELP!! iTS ALGEBRA
    8·1 answer
  • Una avioneta despega con un ángulo de elevación de 12° respecto al suelo si ha recorrido 48 metros en la misma dirección ¿a que
    12·1 answer
  • in spencers garden the number of rose bushes is 7 less than 1.5 times the number of carnation bushes. If the number of carnation
    11·1 answer
  • can someone show me the steps and process to this problem im about to show you.......if x=3 and y=8 what is y2-3x
    14·1 answer
  • Given a conditional statement p<br> 9, which statement is logically equivalent?
    13·1 answer
  • Which of the following is most likely the next step in the series?
    13·1 answer
  • Ms. Gartland bought x number of shirts for the new members of her chorus. The cost for x number of shirts including $3.99 shippi
    5·2 answers
  • There are two rectangles Jared is examining. He knows the width of the first rectangle measures
    9·1 answer
  • X + 7 = 33 inverse operation
    12·1 answer
  • PLEASE ANSWER ASAP WILL MARK BRAINLIEST!!
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!