Question

In: Computer Science

Use Java (Algebra: solve 2 x 2 linear equations) A linear equation can be solved using...

Use Java

(Algebra: solve 2 x 2 linear equations)

A linear equation can be solved using Cramer’s rule given in Programming Exercise 1.13.

Write a program that prompts the user to enter a, b, c, d, e, and f and displays the result.

If ad - bc is 0, report The equation has no solution.

Sample Run 1

Enter a, b, c, d, e, f: 9.0 4.0 3.0 -5.0 -6.0 -21.0
x is -2.0 and y is 3.0

Sample Run 2

Enter a, b, c, d, e, f: 1.0 2.0 2.0 4.0 4.0 5.0
The equation has no solution

Sample Run 3

Enter a, b, c, d, e, f: 1.0 2.0 2.0 4.0 4.0 5.0 6.0

x is -4.0 and y is 4.5


Class Name: Exercise03_03

If you get a logical or runtime error, please refer https://liveexample.pearsoncmg.com/faq.html.

Solutions

Expert Solution

Program:

import java.util.*;       // import packages

import java.io.*;

import java.math.*;      
public class Exercise03_03   // class name
{
   static double a,b,c,d,e,f,x,y,m;   // variable declaration
   public static void main(String[] args)    // main function
   {
      
       Scanner sc=new Scanner(System.in);   // object for scanner class
       System.out.println("\nEnter a,b,c,d,e,f values");
       a=sc.nextDouble();       // reading input values
       b=sc.nextDouble();       // reading input values
       c=sc.nextDouble();       // reading input values
       d=sc.nextDouble();       // reading input values
       e=sc.nextDouble();       // reading input values
       f=sc.nextDouble();       // reading input values
       m=(a*e-b*d);   // calculate mod
       if(m==0)   // check mod value is Zero
       System.out.println("No Solution");   // if zero No solution
       else       // otherwise
       {
           x=(c*e-f*b)/m;   // calculating x
           y=(a*f-c*d)/m;   // calculating Y          
           System.out.println("x is"+Math.round(x));   // DISPLAY X
           System.out.println("y is"+Math.round(y));   // DISPLAY Y
       }
   }
}

OUTPUT:

Program Screen Shot:

Note:

Program Name: Exercise03_03.java

The above program is done by using jdk1.7 compiler


Related Solutions

Describe at least three distinct ways to solve a system of equations using linear algebra. (Distinct...
Describe at least three distinct ways to solve a system of equations using linear algebra. (Distinct means that the approach is fundamentally different.) Be specific and detailed using linear algebra vocabulary. It might be helpful to pick an example problem and illustrate each of the three methods.   Suppose T1 and T2 are linear transformations from Rn to Rn. Let T(x) = T2(T1(x)) The responses should be very clear like you are writing instructions to someone who doesn’t know the process.  ...
Write the augmented matrix for the following system of linear equations. Solve the equation (x,y,z) by...
Write the augmented matrix for the following system of linear equations. Solve the equation (x,y,z) by row reduction. x+3y-2z=5 3x+5y+6z=7 2x+4y+3z=8
Use MATLAB to solve graphically the planar system of linear equations x +4 y = −4...
Use MATLAB to solve graphically the planar system of linear equations x +4 y = −4 4x +3 y =4 to an accuracy of two decimal points. Hint: The MATLAB command zoom on allows us to view the plot in a window whose axes are one-half those of original. Each time you click with the mouse on a point, the axes’ limits are halved and centered at the designated point. Coupling zoom on with grid on allows you to determine...
Hello. Linear Algebra class. In a linear system of equations, the solution is one of the...
Hello. Linear Algebra class. In a linear system of equations, the solution is one of the possibilities. 1)there is one unique solution(only one) which means the line of the equation interest only one time at a point. 2)there are many solutions (infinity) if the lines of equations lie on one another. 3)there is no solution if the line of the equation are parallel. how to test for each possibility WITHOUT graphing the system of equations using the coefficients in each...
Solve for x,y,z if there if a solution to the given system of linear equations: x...
Solve for x,y,z if there if a solution to the given system of linear equations: x - 3y - 2z = -3 3x + 2y - z = 12 -x - y + 4z = 3
Consider the equation: x2 y''-6y=0 A. Could you solve this ODE using Homogeneous Linear Equations with...
Consider the equation: x2 y''-6y=0 A. Could you solve this ODE using Homogeneous Linear Equations with Constant Coefficients? Explain. B. Note that y1=x3 is a solution of the ODE. Using reduction of order, find a solution y2 such that { y1, y2} is linearly independent. C. Prove that{y1, y2} is linearly independent. D.What is the general solution?
When using Gaussian elimination to solve a system of linear equations, how can you recognize that...
When using Gaussian elimination to solve a system of linear equations, how can you recognize that the system has no solution?
Write a python program that can solve system of linear equations in three variables using input...
Write a python program that can solve system of linear equations in three variables using input function. Paste your program in a word document or notepad. Note that I am using pycharm. please use a not really complex codes, thanks
Solve the following differential equation using Linear operators and the Annihilator approach as needed. y''+2y'+y=x^2-3x
Solve the following differential equation using Linear operators and the Annihilator approach as needed. y''+2y'+y=x^2-3x
ASAP (Algebra: vertex form equations) The equation of a parabola can be expressed in either standard...
ASAP (Algebra: vertex form equations) The equation of a parabola can be expressed in either standard form (y = ax^2 + bx + c) or vertex form (y = a(x-h)^2 + k). Write a program that prompts the user to enter a, b, and c as integers in standard form and displays h and k in the vertex form. Hint: Use the Rational class in LiveExample 13.13 for computing h and k. Use the template at https://liveexample.pearsoncmg.com/test/Exercise13_21Test.txt for your code....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT