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
Formulate the indicated conclusion in nontechnical terms. Be sure to address the original claim.
Art [367]

Answer:

The claim made by the motor company was true. The old sedan, the Libra, would average less than 19 miles per gallon in the city.

Step-by-step explanation:

In this case we need to test the claim made by the Carter Motor Company, that their old sedan, the Libra, would average less than 19 miles per gallon in the city.

The hypothesis to test the claim is as follows:

<em>H₀</em>: The old sedan, the Libra, would average not less than 19 miles per gallon in the city, i.e. <em>μ</em> ≥ 19.

<em>Hₐ</em>: The old sedan, the Libra, would average less than 19 miles per gallon in the city, i.e. <em>μ</em> < 19.

It is provided that the conclusion is to reject the null hypothesis.

This implies that, it was concluded that the old sedan, the Libra, would average less than 19 miles per gallon in the city.

Hence, the claim made by the motor company was true.

7 0
3 years ago
The radius AND height of a cylinder are each doubled. What is the new volume?
Naya [18.7K]

The volume of a cylinder is given by

V = \pi hr^2

Let h\mapsto 2h and r\mapsto 2r

The new volume becomes

V = \pi(2h)(2r)^2 = \pi\cdot 2h \cdot 4r^2 = 8\pi hr^2

So, the new volume is 8 times the original volume. In fact, volume scales linearly with the height and quadratically with the radius.

7 0
3 years ago
Find the surface area of a cube with 4.1 in. edges.
spin [16.1K]
4.1*4.1*6=100.86 inches^2
5 0
3 years ago
Read 2 more answers
Which ordered pair is a solution to the system of inequalities?
Vinil7 [7]
A! Because 9 is greater than 2 and 9 is greater than 7






5 0
2 years ago
Read 2 more answers
Henry had 5 grapes. He mutiplys the five by 80, just because he was courious. How much did he get?
lina2011 [118]
<h2>B)</h2>

It is <em><u>400</u></em>. Since 5 x 8 = 40 add the 0 to the end its 400!!

Hope this helps <33!!

8 0
2 years ago
Read 2 more answers
Other questions:
  • Which is the equation of a line that passes through the point (3.-4
    9·1 answer
  • Que es fraccion conbinadas
    14·1 answer
  • What is the equation of the graphed line in point -slope form (0,3) (-3,3)
    13·1 answer
  • Ruth has 7 more brown pencils than blue pencils, and 11 more blue pencils than red pencils. She has 5 red pencils. How many brow
    11·1 answer
  • -2/3x= -12 solve for x
    13·1 answer
  • angle a and angle C are vertical angles if the measure of angle a equals 3x + 7° and measure of angle C equals x + 53° what is t
    9·1 answer
  • A 16-fl oz bottle of juice cost 2.00 what is the unit cost
    5·2 answers
  • 6 less than a number is -4 what is the number?
    14·2 answers
  • Q1) In a right tringle the hypotenuse is 5, the one of the legs is 3, find the other leg.
    12·2 answers
  • Help test due tonight ! *no links please *
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!