Congratulations to all the winners of April 2013, they have won INR 3400 cash and INR 20147 worth prizes !

 Online : 4867 |  Welcome, Guest!   Register  Login
Home > Code Snippets > Others > Scientific Computing (Gauss Method Elimination) ...

# Scientific Computing (Gauss Method Elimination)

Code Snippet posted by: Samratdas1991 | Posted on: 1/26/2010 | Category: Others Codes | Views: 1733 | Status: [Member] |

///////////////////////////////////////////////////////////////////////////////////
// //
// OPEN LICENCE //
// //
///////////////////////////////////////////////////////////////////////////////////
// //
// GAUSS_METHOD //
// (C) Copyright 2008-2012 by SAMRAT DAS (BE/6103/08) //
// B.I.T Mesra (Deoghar Campus) from C.S.E. Dept //
// //
///////////////////////////////////////////////////////////////////////////////////
/******************************************************************************************************************
* wap to solve the following system of equation by gaussian elimination method *
* *
* 4x+y+z = 0 *
* x+4y-2z = 0 *
* 3x+2y-4z = 0 *
* *
*******************************************************************************************************************/

import java.util.Scanner;
import java.lang.*;
class gauss
{
public static void main(String args [])
{
Scanner input = new Scanner (System.in);
int i,j;
float a[][] = new float [3][3];
float b[] = new float [3];
float x1 = 0,x2 = 0,x3 = 0;
System.out.println("Enter the cofficient of the Matrix : ");
for(i = 0;i<3;i++)
{
for(j = 0;j<3;j++)
{
System.out.println("\nEnter the Eliments of the Matrix of" +i+j);
a[j] = input.nextFloat();
}
}
System.out.println("*****The Entered Matrix is *******");
for(i = 0;i<3; i++)
{
for(j = 0; j<3;j++)
{
System.out.print("\t"+a[j]);
}
System.out.print("\n");
}
for(i = 0; i<3;i++)
{
for(j = 0; j<3; j++)
{
a[1][j] = a[1][j] - (a[0][j]*(a[1][0]/a[0][0]));
a[2][j] = a[2][j]-(a[0][j]*(a[2][0]/a[0][0]));
}}
System.out.println("\n@@@@@ The new matrix is @@@@@ \n");

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
System.out.print("\t" + a[j]);
}
System.out.print("\n");
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
a[2][j]=a[2][j]-(a[1][j]*(a[2][1]/a[1][1]));
}
}
System.out.println("+++++The final matrix is+++++");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
System.out.print("\t"+a[j]);
}
System.out.print("\n");
}
System.out.println("\nEnter the fourth Column of Matrix :");
for(i = 0; i<3; i++)
{
System.out.println("Enter the value Matrix : ");
b = input.nextFloat();
}
for(i = 0; i<3; i++)
{
for(j = 0; j<3; j++)
{
x3=(b[2]/a[2][2]);
x2=((b[1]-(a[1][2]*x3))/a[1][1]);
x1=(b[0]-(a[0][2]*x3)-(a[0][1]*x2)/a[0][0]);
}
}
System.out.println("\n\t\t````THE ROOTS ARE``````` \n");
System.out.println("\n\t x1 = " + x1);
System.out.println("\n\t x2 = " + x2);
System.out.println("\n\t x3 = " + x3);
}
}
Found interesting? Add this to:

>> Write Response - Respond to this post and get points

#### More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/19/2013 8:05:46 AM