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


ADVERTISEMENT

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

Finite Element In Java - Computing Stiffness Matrix For ISOTROPIC Case

Apr 2, 2014

I build some finite element in java. I try to optimize my running time. I do some double loop and use inside the loop in if else statement and also in switch case .

The loop is very long, sometimes become ~500 X 500.

You think that if i avoid from the if statement and the switch case inside the loop i will improve the time calculation by at least 10%?There is something that i must to avoid ?

// Computing stiffness matrix.
switch (materialType) {
case ISOTROPIC:
// Computing stiffness matrix for ISOTROPIC case.
for (int row = 0, nvfi2 = nvfi * 2, index = 0, fieldsNvf = fields * nvfi; row < fieldsNvf; row++) {
if (row == nvfi) {
leftZeroMatrix = 3;

[Code] ....

View Replies View Related

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

Servlets :: Large File Upload From Client To Content Management System

Sep 3, 2009

I have a requirement where a large file (100 -200MB) is uploaded from the client to a content management system. I am using a servlet with Apache Commons File Upload API. Apache FileUpload has 2 ways of handling files,

1) Non-Streaming
2) Streaming

Currently I use the Non-Streaming approach where the servlet stores the file in a temp location and upload the same into the content management system - This is taking lot of time so I am trying to implement Streaming API.

Content Management API supports streaming in 2 methods,

a) SetContent - Takes the file's ByteArrayOutputStream as input -> This gives OutOfMemoryException because the file being large
b) AppendContent - Takes the file's ByteArrayOutputStream as input -> This method can be called multiple times to upload the large file but I dont know how to do this. The Apache File Upload gives InputStream of the file and I need to split that into chuncks and append into the content management system.

How to convert InputStream to 4KB ByteArrayOutputStream so that I can use the AppendContent method in content management API?

View Replies View Related

Java Program To Find Index Of Greater Element Whose Value Is Sum Of Remaining Elements

Aug 25, 2014

I need to write a java program to find the index of the element whose value is the sum of the remaining elements. Recently I have been asked this question in an Interview which I couldnt solve properly.

View Replies View Related

Create A Program To Calculate Roots For 2 Degree Equation

Oct 14, 2014

I just created a program to calculate the roots for a 2. degree equation, When I first created my program, I defined the r1 and r2 as double, but got an error saying they needed to be defined as String, why is that?When should I be using string? I am new to java and I have mostly only used int, double and Boolean so far.

import java.util.Scanner;
import java.text.DecimalFormat;
public class c3e1 {
public static void main(String[]args){

[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

Java - Compute PI Using Equation

Oct 24, 2014

Part 1: USING A WHILE OR A DO-WHILE LOOP write a program to compute PI using the following equation:

PI = 3 + 4/(2*3*4) - 4/(4*5*6) + 4/(6*7*8) - 4/(8*9*10) + ...

Allow the user to specify the number of terms (5 terms are shown) to use in the computation. Each time around the loop only one extra term should be added to the estimate for PI.

Alter your solution from part one so that the user is allowed to specify the precision required between 1 and 8 digits (i.e. the number of digits which are correct; e.g. to 5 digits PI is 3.14159), rather than the number of terms. The condition on the loop should be altered so that it continues until the required precision is obtained. Note that you need only submit this second version of the program (assuming you have it working).

My output for part 1 is :

Enter number of wanted terms for value of PI
100
PI = 3.1666666666666665 Number of Term = 2
PI = 3.1333333333333333 Number of Term = 3
PI = 3.145238095238095 Number of Term = 4
PI = 3.1396825396825396 Number of Term = 5
PI = 3.1427128427128426 Number of Term = 6
PI = 3.1408813408813407 Number of Term = 7
PI = 3.142071817071817 Number of Term = 8
PI = 3.1412548236077646 Number of Term = 9
PI = 3.141839618929402 Number of Term = 10 ................ and so on

I know you have to compare value of current Pi to the previous one but I'm stuck.

View Replies View Related

Program To Scrape All Title Tags From Large Sites

Apr 9, 2015

I am familiar with php, but I don't know Java. We need a program, that will be able to scrape large amount of title tags from large sites, fast. I've been trying Seo Spider by Screaming Frog, and Xenu's Link Sleuth, but these programs are not good enough. They hang up, they save all the data in RAM, I think, and after a relatively short period of scraping, they stop working, become unresponsive, and so on.

Somebody recommended me getting a custom made program in Java, which would be able to scrape title tags only, from large sites (I am talking 25 - 50 million pages or more). I was told that it would not have a graphic interface, or anything like that. Nothing like this is needed too, we just need to have title tags.

View Replies View Related

Getting NaN For Roots (Quadratic Solver)

Nov 18, 2014

This was the way I was supposed to write it (every thing separated). Any way, I was wondering why when ever I try to run I only get NaN for roots, and my discriminant is off

/**
* Find roots of quadratic equations
*/
import java.util.Scanner;
public class QuadraticProject {
public static void main(String[] args) {

[Code] ....

View Replies View Related

Add Element As Third Element Of Stack Without Changing Rankings

Jun 1, 2014

I want to run a program to add an element as the third element of stack without changing rankings, I am trying to use two stack and I don't know how to push the top of first stack in the second: push(top(); this line

public void ADD(int element,int i ){
if(isEmpty(true)){
push(element);}
else{ makeNull();
while((i<=3) && (isEmpty(false))){
push(top();
}

View Replies View Related

Sudoku Solver Backtracking Algorithm

Dec 5, 2014

It's about a backtracking algorithm trying to solve a sudoku, represented by an array of integer arrays. For testing matters, the start field is empty.

static boolean solve(int[][] field, int i, int j) {
if (filled(field)) {
return legal(field);
} else {
for (int k = 1; k <= 9; k++) {
field[i][j] = k;

[Code] ....

View Replies View Related

Sudoku Solver - Scanner Isn't Functioning Properly

Nov 19, 2014

I am working on a program that should take an input file as a command line argument and check if that file contains a valid sudoku solution. Right now the main error I am getting is my scanner isn't functioning properly and is throwing inputMismatchexceptions, but Im also not sure about the validity of my functions, and i cannot test them because my scanner isn't working.

import java.util.Scanner;
 
//This class will read in a possible sudoku solution and test it for validity. If it is invalid, return at least one reason why.

public class SudokuVerifier {
//this function checks a row to see if it contains the numbers 1-9
public static boolean checkRow(int sudoku[][], int i) {
boolean contains=false; // keeps track if the line contains a certain number
for(int k=1; k<=9; k++) { //goes through every number from 1 to 9
for(int j=1; j<sudoku[i].length; j++) { //checks every element in the row to see if it is equal to k

[code]...

View Replies View Related

Reading A Large JSON File In Java

Jan 5, 2014

reading a large json file which is really huge and it contains pair of id and URL in a array as shown below.. i need to get this all id and URL from this file in my java code and need to perform operations . how to read such a big file and store the contents in java code to process it further.

{
"Array": [
{
"id": "1test",
"URL": "http://servername/test/1test.html"
},
{
"id": "2test",
"URL": "http://servername/test/2test.html"
}
....................many id and URL in the same Array which makes the file Huge..
]
}

View Replies View Related

Java Servlet :: How To Download Large Files

May 21, 2013

I need to download large amount files, what should I care, Is the following code have problem on download large files

private static byte[] load(String filename) throws IOException {
        FileInputStream fis = new FileInputStream(filename);
        byte[] data = new byte[fis.available()];
        fis.read(data);
        fis.close();
        return data;
    }

View Replies View Related

Grading System Program

Aug 20, 2014

Ok so this is a grading program. I have it so the user can input 2 students and then at the end using an if statement it is suppose to compare them and print out who had the higher grade. Seems simple but it never runs the line of code to print out whos grade is higher:

if (stuAverage > stuAverage2 ){
System.out.println(student + " has the highest grade of all students entered!");
}
else if (stuAverage2> stuAverage){
System.out.println(student2 + " has the highest grade of all students entered!!");
}

Here is the Main class:

import java.util.Scanner;
public class Main2 {
int stuAverage;
static String student;
 
[code]....

View Replies View Related

Take Two Matrices And Add Them Together

Nov 23, 2014

I had to make a program that would take two matrices and add them together but I get red lines under certain parts causing me not able to run the program . Here is my code :

import java.util.Scanner;
public class Matrix {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
final int N = 3;
System.out.print("Enter Matrix 1: ");

[Code] ....

And here are the segments that are showing red lines :

if (i == m1.length / 2);
System.out.print(" = ");
else
System.out.print(" ");

And here

System.out.println("
The Matrix are added as followed ");
printResult(matrix1, matrix2, resultMatrix, " + ");

View Replies View Related

How To Make The Program Understand 10 Number System

Oct 24, 2014

I want to create a program where i can output a number. ex. 3452 And the program will output 3000: three thousand 5: five 53: fifty-three

How can i make the program understand the 10-number system?

View Replies View Related

Adding Defined Matrices Together

May 23, 2015

I am trying to create a simple programme that adds two defined matrices together,

public class Question4 {
int [][] numeros1 = { {1,2,3},
{4,5,6}
};
int [][] numeros2 = {{2,5,8},
{3,7,9}

[Code] ....

View Replies View Related

Adding Two Matrices Using JTextFields

Sep 18, 2014

I was assigned to create a program that opens up a window that asked the user for an input of 0-10. This input will create three windows with the correct number of rows and columns of JTextFields in the form of a matrix. the third window has a button that adds the two matrices (which also take user input) and adds them together and prints them in the correct matrix fields. I am having trouble declaring the 2d array from the user input and creating the windows with the correct amount of jtextfields to move on with my program.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Matrices implements ActionListener {
private JFrame win1, win2, win3, win4;
private JButton button1, button2;

[Code] .....

View Replies View Related

Populating Two Matrices With Method?

Sep 4, 2014

This is the method public void populateMatrices(int [][]mat1, int [][]mat2). I know how to do it for one matrix, but what do we do for the additional matrix? Here is the code I have so far.

for (int row =0; row<mat1.length;row++){
for (int column = 0; column<mat1[row].length;column++){
mat1[row][column]=1 + (int)(Math.random()*5);

View Replies View Related

Java Heap Memory Error While Writing Large Data To Excel

Mar 6, 2014

i have to write more than 100000 rows in a excel sheet (file size more than 20 MB) via java.

when i use XSSF, i am getting below Error.

java.lang.OutOfMemoryError: Java heap space
at org.apache.xmlbeans.impl.store.Saver$TextSaver.resize(Saver.java:1592)
at org.apache.xmlbeans.impl.store.Saver$TextSaver.preEmit(Saver.java:1223)
at org.apache.xmlbeans.impl.store.Saver$TextSaver.emit(Saver.java:1144)

[Code]....

when i use HSSF , i am getting the below Error.
java.lang.OutOfMemoryError: Java heap space

I have tried increasing the java heap size , by giving upto -Xms1500m -Xmx2048m

View Replies View Related

Program Deals With Variation Of Geographic Coordinate System

Aug 22, 2014

This program deals with a variation of the geographic coordinate system with Greenwich at 51° 28' 38" N. The program will be adding the three values of one coordinate to the three values of the second coordinate. Though the maximum value for seconds and minutes is 59, the user can enter values greater than that number when prompted. The maximum degree is 360 for this assignment though the user can enter values greater than that number.

View Replies View Related

How To Extract First Digit From Int Array Element (java)

Nov 18, 2014

How do you extract first int digit from an int array element (java)?

if a[3] = 45, how do I extract 4 out of 45?

View Replies View Related

Java Runtime Get Result Output From Prompt / Large File - Process Will Hang

Aug 13, 2014

I am using java process to start a system command in windows

Runtime r = Runtime.getRuntime();
Process pr = r.exec(cmdString);

I want to get the prompt out put from cmdString = "cmd /c type fileSmallSize"->>>> It is ok the have the content of the file when file is small.

However, for a large file java process will hang and no Exception occurred, what is the problem?

The easiest testing you can try on the logging.properties file in java.

public static String executeCmdAndReturnPromptResult(String cmdString)
throws Exception {
LOGGER.entering(CLASSNAME,
"Entering executeCmdAndReturnPromptResult()", cmdString);
String cmd = cmdString;

[Code] ....

It seemed to me that the bufferSize is limited so that I can only have it less than a default one, how to increase it?

My question now is how to increase the size of buffer in order to read a larger InputStream ?
BufferedInputStream() default size is
private static int defaultCharBufferSize = 8192;
private static int defaultExpectedLineLength = 80;

How to make it larger and working? I tried to increase the defaultCharBufferSize to 500000000 but it did not work!

View Replies View Related







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