Algebra 2x2 Linear Equations?

Mar 15, 2015

Design a class named LinearEquation for a 2 X 2 system of linear equations:

ax + by = e
cx + dy = f
Where
x =
ed − bf/ad − bc
y =
af − ec/ad − bc

The class contains:

- Private data fields a, b, c, d, e, and f.
- A constructor with the arguments for a, b, c, d, e, and f.
- Six get methods for a, b, c, d, e, and f.
- A method named isSolvable() that returns true if ad−bc is not 0.
- Methods getX() and getY() that return the solution for the equation.

[code].....

how to display the information I need to display. Also I am not so sure that I wrote the code properly, I do not get any errors when I compile it.

View Replies


ADVERTISEMENT

Writing A Program For System Of Linear Equations

Sep 22, 2013

So i was assigned to write a program that would print the answer to the system of two linear equation. the form of ax+by=c and dx+ey=f..I wrote this program, but it is incorrect since I tried it out on my terminal and I keep getting incorrect values.

import java.util.Scanner;
public class Quest4 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

[code]....

View Replies View Related

Matrix Algebra - Number Of Rows And Columns

Mar 19, 2015

I am continuing on in trying to build up the basics of matrix algebra from scratch.

I have created an object class called Matrix

import java.util.ArrayList;
public class Matrix {
public int NumRows;
public int NumColumns;
 
// This array contains the entries of our matrix.
ArrayList<Double> entry = new ArrayList<Double>();
 
[Code] ......

Bottom line: a matrix has a number of rows and a number of columns, and for each pair of row and column, we have a number in our matrix. The DisplayMatrix method prints my matrix to the screen, and the GetEntry method returns a particular value. This all works fine and dandy as far as I can tell.

A fundamental operation done to matrices to obtain a special matrix called the RREF is the process of switching 2 rows. Here is a method I have written that switches two rows of a matrix, and outputs the result as a new matrix. Note that I want the original matrix to be unchanged.

// Switch two rows
public static Matrix SwapRows(Matrix A, int r1, int r2){
if(r1<1 || r1>A.NumRows || r2<1 || r2>A.NumRows)
PRINTLN("illegally switching rows");
Matrix C = A;
double dummy[] = new double[A.NumColumns];

[Code] ....

How I call this, inside a public static void main(String[] args), is as follows:

// Declares that A is a 2 by 2 matrix.
Matrix A = new Matrix(2,2);
 
// We now add values in. The top left entry of A is 4, the top right entry of A is 1, the bottom left entry of A is 2, and the bottom right entry of A is 6.

double pony[]= new double[4];
pony[0]=4;
pony[1]=1;
pony[2]=2;
pony[3]=6;
A.AddEntries(pony);
 
// We can display the matrix in the output, and it looks exactly as expected!

A.DisplayMatrix();

// I am now going to create a new matrix called B. It is going to be obtained by flipping the first and second rows of A.

//Note that I want A is stay as I initialized it.

//I dont want A to have it's 2 rows switched. I want B to the matrix obtained by switching two rows of A.

Matrix B=SwapRows(A,1,2);
B.DisplayMatrix();

// Displaying B gives me the desired result. However, if I now display A again, it is the same as B.
 
A.DisplayMatrix();

Why is my matrix A being modified? Of course, I am more than capable of providing more details/comments if requested. I suspect that this is a super silly mistake.

View Replies View Related

Software For Minimizing Boolean Algebra Using Quine Mccluskey Method

May 21, 2014

I've been trying to program a software for minimizing (sum of products and products of sum) a boolean algebra using Quine mccluskey method... I've created the GUI and I got stuck in the process... I need a code for minimizing a 10 variable function ....

View Replies View Related

Algebra - Perfect Square Java Program / Find Smaller Integer N

Sep 22, 2014

Write a program that prompts the user to enter an integer m and find the smallest integer n such that m * n is a perfect square. (Hint: Store all smallest factors of m into an array list. n is the product of the factors that appear an odd number of times in the array list. For example, consider m = 90, store the factors 2, 3, 3, 5 in an array list. 2 and 5 appear an odd number of time in the array list. So, n is 10.)

so far my program is just like this.

import java.lang.Math;
import java.util.Scanner;
public class PerfectSquare {
public static void main(String[] args) {
Scanner m = new Scanner(System.in);
int Fint;

[Code] .....

how do i make the program find the smallest integer n?

View Replies View Related

Linear Search Of Arraylist By Last Name

Nov 5, 2014

I am having some trouble with linear search of a customers last name. I can't seem to get it to work. I have looked up examples but cant find many with Array Lists. Here is my code.

import java.util.ArrayList;
import java.util.Scanner;
public class AccountDriver {
public static void main(String[] args) {
ArrayList<Account> al = new ArrayList<Account>();
ArrayList<Customer> cust = new ArrayList<Customer>();
Scanner scan = new Scanner(System.in);

[code]....

View Replies View Related

Creating Java Linear Algorithm

Oct 13, 2014

I'm finding common elements in a collection of arrays. This is my code so far.

import java.util.ArrayList;
import java.util.List;
public class CommonElements //< T extends Comparable<T> >
{
Comparable[] comparable;
Comparable[] tempArr;
Comparable[] tempArr1;
Comparable[] newArray = new Comparable[tempArr.length];
int comparisonCount;
 
 [code]....

I'm using this method to sort through my array. The method accepts a collection of arrays (of varying length and of any type) as input, the algorithm input should be no greater than n(k-1). I know I can solve it using a quadratic algorithm, but it won't meet the requirement of the assignment. I did have an idea of storing all my algorithm in one giant array. After storing as one giant array I was going to sort it. After sorting I was going to compare each array side by side and see if they are the same. Here is note my teacher provided.

Note About Testing You will need to develop several sets of test collections for testing your algorithm. The grading rubric mentions covering the case where all the test collections have the same length, as well as covering the case where the test collections are of different lengths. You will also need to think about what constitutes the worst case scenario for this algorithm, since only that scenario will make your analysis of total comparisons performed a meaningful one. You can use the formulas in the grading rubric to tell you how many comparisons you should expect in the quadratic and linear cases. For example, if you have 5 total collections (1 query collection and 4 test collections), each of which contains 10 elements, the total number of comparisons performed in the worst case should be: (k - 1)N2, which for k = 10 and N = 10 is: (5 - 1)102, or 400 comparisons. For the linear algorithm, you should only have N*(k - 1), which is 10*(5 - 1), or 40 comparisons.

Here is Q/A that my teacher provided:

1. Are the elements in the collections already sorted?The input collections may or may not be sorted. Don’t assume that they are sorted.

2. Can I sort the elements in the collections? Am I supposed to sort the elements in thecollections?Yes, you can sort the elements in the collections. It is not required that you do so, however..

3. If I sort the collections, should I count the element comparisons that are performed by the sorting algorithm?No. The only element comparisons you should count are the ones that are directly used to find the common elements. Ignore comparisons performed by any sorting algorithms you use.

4. How do I extract an individual collection from the Object[] collections argument of the findCommonElements method?You will need to typecast each collection as type Comparable[]. For example:Comparable[] currentCollection = (Comparable[])collections[i];

5. Why are we using a one-dimensional Object array instead of a two-dimensional array of type Comparable (e.g., Comparable[][])?In Java, arrays are treated as objects, so only a variable of type Object[] can contain arrays. A variable of type Comparable[] can only contain Comparable elements, not arrays. A variable of type Comparable[][] also can only store Comparable elements. Although it is possible to organize the elements such that all the elements at indexes [1][i], for example, are considered to comprise a collection, this is not the same as having an array that contains other arrays. The additional bookkeeping is required to keep a 2D array organized is more complex than simply performing the typecast described above.

6. Can I use other data structures besides arrays; e.g., HashMaps?No. Although it is easier from a programming perspective to use higher order data structures like HashMaps to find common elements, using these structures simply hides the details. If you were to examine the implementations of those structures, you would probably find that they use relatively inefficient algorithms such as sequential searches to find elements. Additionally, if you use library components, you have no way of counting the number of comparisons performed, since you don’t have access to the source code of those components.

7. Is this a trick question? I can’t think of any way to get below NlogN comparisons.It is not a trick question. It is possible to solve this problem using a number of comparisons proportional to (k – 1) * N.

View Replies View Related

Finding Lowest Value In Array Using Linear Search?

Apr 5, 2014

I am attempting to find the element that holds the lowest time ( i have used System.currentMillisTime ) in the array using a linear search and to then print the times held by the array in lowest to highest order . While i understand how to do a linear search using user input as the key i am not to sure how to do it by initializing a search key in the program to the lowest number and have little experience in using a search in a program that is not a simply linear search. i have attempted to code this, as seen below, but i know i am definitely wrong and i have tried another of different ways even Array.sort and then a binary search .

static long store_MAX[]; // Now an ‘array’ of ints
static int deptSize; // Holds the length of the buffer
private int shopper_MAX; // Holds the number of items in the buffer

[Code].....

View Replies View Related

Roots Of Nonlinear System Of Equations

Oct 10, 2014

I am in search of a library that has been created in JAVA that can be utilized to solve for roots of a nonlinear system of equations. Each equation has 2 variables, x and y, and will need a library that uses higher calculus equations. No ones that just solve for x.

Most of the libraries that have been created to solve nonlinear equations are either in Fortran, C, or Python. There are a few libraries such minpack/scipy. The only libraries that I have been able to find or programming solutions that are in JAVA either require additional programs such as Matlab or are commercial products

I did find one library put together by a professor in Colorado State, but am unsure how to use it. There does not seem to be a way to enter your functions in the code.

Newton Raphson Method - Multivariable(x and y)

[URL] .....

How to use this library or find a library that can be used in an android application would be amazing.

View Replies View Related

Solve Quadratic Equations With Arrays

Feb 14, 2014

I am suppose to write a method for solving a quadratic equation using the following header:

public static int solveQuadratic(double[] eqn, double[] roots)

I have entered 1, -3 and -4. The answer I get is "The solution is:0.0" .

import java.util.Scanner;
public class QuadratilEq {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner (System.in);
double[] eqn = new double[3];
double[] roots = new double[4];

[Code] .....

View Replies View Related

Java Objects And Classes - System Of Linear Equation

Mar 15, 2015

The question states: Design a class named LinearEquation

for a 2 x 2 system of linear equations:

ax + by = e

cx + dy = f

Where

x =

ed − bf/ad − bc

y =

af − ec/ad − bc

The class contains:

- Private data fields a, b, c, d, e, and f.
- A constructor with the arguments for a, b, c, d, e, and f.
- Six get methods for a, b, c, d, e, and f.
- A method named isSolvable() that returns true if ad−bc is not 0.
- Methods getX() and getY() that return the solution for the equation.

Write a test program that prompts the user to enter a, b, c, d, e, and f and displays the result. If ad − bc is 0, report that "The equation has no solution."

I believe that my program is correct because I am able to compile it and get no errors, however I have no clue how to display the information for x and y or display this equation has no solution if ad-bc=0.

Java Code:

import java.util.Scanner;
public class Exer911 {
public static void main(String[] args){
// Create a scanner system to hold the numbers for each variable
Scanner input = new Scanner(System.in);
// Prompt the user to enter a number for each of the variables

[Code] ....

How to get the information to display ....

View Replies View Related

Solving Roots Of Nonlinear System Of Equations

Oct 10, 2014

I am in search of a library that has been created in JAVA that can be utilized to solve for roots of a nonlinear system of equations. Each equation has 2 variables, x and y, and will need a library that uses higher calculus equations. No ones that just solve for x.

Most of the libraries that have been created to solve nonlinear equations are either in Fortran, C, or Python. There are a few libraries such minpack/scipy. The only libraries that I have been able to find or programming solutions that are in JAVA either require additional programs such as Matlab or are commercial products

I did find one library, but am unsure how to use it. There does not seem to be a way to enter your functions in the code.

Newton Raphson Method - Multivariable(x and y)
www(.)math.colostate(.edu)/~benoi...s/solvers.html

How to use this library or find a library that can be used in an android application.

View Replies View Related

Splitting Numbers From TXT File In Order To Create Equations

Nov 7, 2014

I have a .txt file which i am currently using Scanner to input into the console, the text file contains the names of football games followed by their scores:

E.g. Man U : Liverpool : 2 : 1

I need to create an equation to add together all scores to create a string reading something like "total goals: 28" ....

View Replies View Related

Swing/AWT/SWT :: How To Rotate 2D Square Using Maths Equations Through OpenGL

Feb 23, 2015

So I need to create a square and make it rotate when the letter R is pressed and then make it stop when the letter R is pressed again. I need make it rotate using a maths equation that I can't figure it out myself right this moment.

Code for square:

package lab2;
public class Square {
public double [][] vertices = new double[4][2]; //not good to make this public
public Square(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
vertices[0][0]=x1;
vertices[0][1]=y1;
vertices[1][0]=x2;

[Code] ....

In the Square code there is a method to write an equation to rotate it but I can't figure that part out ....

View Replies View Related

Make Linear Search Method To Check If Number N Is Included In Array

Jun 8, 2014

im trying to make a linear search method to check if a number 'n' is included in an array.

PHP Code:

package test;
public class Recursion {
public static void main(String[] args) {
}
static int linearSearch(int n, int[] array)

[code]....

Im getting the following error: this method must have a result type of type int ?? i already have a return type of type int...

View Replies View Related

Solving / Roots Of Nonlinear System Of Equations - Java / Android

Oct 11, 2014

I am in search of a library that has been created in JAVA that can be utilized to solve for roots of a nonlinear system of equations. Each equation has 2 variables, x and y, and will need a library that uses higher calculus equations. No ones that just solve for x.

Most of the libraries that have been created to solve nonlinear equations are either in Fortran, C, or Python. There are a few libraries such minpack/scipy. The only libraries that I have been able to find or programming solutions that are in JAVA either require additional programs such as Matlab or are commercial products

I did find one library put together by a professor in Colorado State, but am unsure how to use it. There does not seem to be a way to enter your functions in the code.

Newton Raphson Method - Multivariable(x and y) Page Not Found

How to use this library or find a library that can be used in an android application would be amazing.

View Replies View Related

Physics Calculator - Manipulate Equations To Find Unknown Variable

May 4, 2014

There are a lot of variables in physics and it is easy to manipulate equations to find the unknown variable. Well, in my program I have the problem of determining which equation to solve for an unknown. You can see I have a timeF, timeI, time, distanceI, distanceF, distance...etc...variables. The way that I have written the code, it will scan for an empty() JTF and assign it as the unknown variable (not sure I can do it this way anymore). At that point, the value is passed into the correct calculation method to process the equation based on a series of case statements in each method...

I know the button arrays I have set up will process correctly in the checkJTF method...and I will need to account for that...but right now my focus is on getting the program to properly calculate the kinematics equations and display the result in the JPanel.

public class PhysicsFrame extends JFrame {
//Kinematic variables
private static float distanceI, distanceF, velocityI, velocityF,
velocityAverage, acceleration, time, timeF, timeI, result;
//Power variables

[Code] .....

View Replies View Related

Solver For System Of Linear Equation In Java For Large Matrices (finite Element Program)

Jan 16, 2014

I develop a finite element code at java. I am looking for efficiency solver and fast for large, sparse , symmetric and positive define matrices .

i used in jblas but i encounter in problem when the matrix has high condition number(ill condition number) and i get error for singular matrix while in mathematica i succeed to solve that system without problems...

Any good solver and fast solver package in java can i use for solving that system?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved