Latest Tutorials
|
Questions and Answers
|
Ask Questions?
|
Site Map
Home
Java
Frameworks
Database
Technology
Web Development
Build/Test Tools
Servers
PHP
Home
Answers
Viewqa
Java-Beginners
deteminant
Login
Question
Ask Questions?
Binay Shah
deteminant
1 Answer(s)
3 years and 8 months ago
Posted in :
Java Beginners
View Answers
November 7, 2009 at 11:24 AM
Hi Friend,
We are providing you a code that will find the determinant of 2x2 matrix.
public class Detrminant{
public double determinant(double[][] mat) {
double result = 0;
if(mat.length == 1) {
result = mat[0][0];
return result;
}
if(mat.length == 2) {
result = mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0];
return result;
}
for(int i = 0; i < mat[0].length; i++) {
double temp[][] = new double[mat.length - 1][mat[0].length - 1];
for(int j = 1; j < mat.length; j++) {
for(int k = 0; k < mat[0].length; k++) {
if(k < i) {
temp[j - 1][k] = mat[j][k];
} else if(k > i) {
temp[j - 1][k - 1] = mat[j][k];
}
}
}
result += mat[0][i] * Math.pow(-1, (double)i) * determinant(temp);
}
return result;
}
public static void main(String []args){
double array[][]= {{5,6},{8,9}};
Detrminant d=new Detrminant();
double result= d.determinant(array);
System.out.println(result);
}
}
Thanks
Post Answer
Preview:
Related Pages:
deteminant - Java Beginners
deteminant - Java Beginners
Latest
Frameworks
Category
Google Ranking Update for Spammy Queries
Google Penguin Algorithm update issues and How to Recover
change database values when click next button on jsp page
Java
Creating Array in PHP
for-each loop in java
Iterator in java
Java Array declaration
What is Virtual Appliance?
Creating multiple Threads
Hibernate
Struts 1.x
Struts 2
JSF
JavaFX
Ajax
Spring 2.5
Spring 3
DOJO
iBatis
Flex 3
Flex 4
Hibernate Framework
( 1057 )
Struts Framework
( 836 )
Spring Framework
( 567 )
XML
( 196 )
Ajax
( 528 )
JavaScript
( 109 )
Java
( 1806 )
Web Services
( 71 )
Database
( 145 )
Technology
( 90 )
Web Development
( 503 )
PHP
( 406 )