Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Compare matrix

Posted on 2011-04-24
6
Medium Priority
?
207 Views
Last Modified: 2012-06-27
Hi all
I have this matrix

double[][] arrayInput = {{1,0,1}};
double [][] arrayWeight = {{0.2,1.5,2.}};

arrayWeight = arrayInput
arrayWeight < arrayInput
arrayWeight > arrayInput


I am looking for a method that can help me compare both values
and return the result

public static double getEculideanDistance(double [][]arrayInput, double [][] arrayWeight)
{
retrun result;
}

Thanks in Advance
0
Comment
Question by:ZURINET
  • 3
  • 2
6 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 35457055
I'm not sure there is one general definition in math - what
matrix is bigger than another, or what os the distance between matrices
if you want to compare them element by element and
calculate sum of squares of the distances that is how you do it:


public static double getEculideanDistance(double [][]arrayInput, double [][] arrayWeight) {

double output = 0.0;

    for (int row = 0; row < arrayInput.length; row++) {
            for (int col = 0; col < arrayInput[row].length; col++) {
                output += (arrayInput[row][col]-arrayWeight[row][col])*(arrayInput[row][col]-arrayWeight[row][col]);
            }
         
        }
     return Math.sqrt(output);
}
I'm not quite sure though that to the method it passes dimensions of two dimnsional array correctly,
you can then pass dimensions as integers

0
 
LVL 47

Accepted Solution

by:
for_yan earned 2000 total points
ID: 35457071


I checked (modified your input for simplicity and this
code worked for me
public class AnyName {
  static  double[][] arrayInput = {{4,0,5}};
    static  double [][] arrayWeight = {{1,0,1}};

     public static double getEculideanDistance(double [][]arrayInput, double [][] arrayWeight) {

     double output = 0.0;

         for (int row = 0; row < arrayInput.length; row++) {
                 for (int col = 0; col < arrayInput[row].length; col++) {
                     output += (arrayInput[row][col]-arrayWeight[row][col])*(arrayInput[row][col]-arrayWeight[row][col]);
                 }

             }
          return Math.sqrt(output);
     }
  public static void main(String[] args) {


          System.out.println("result: " + getEculideanDistance(arrayInput, arrayWeight));
 }
}

Open in new window



result: 5.0

Open in new window

0
 
LVL 85

Expert Comment

by:ozo
ID: 35457439
what does arrayWeight < arrayInput mean?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:ZURINET
ID: 35458286
Hallo Van

Thanks a lot

regards
0
 

Author Closing Comment

by:ZURINET
ID: 35458287
Perfect
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35458292
You are always welcome
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Nicole
This is a research brief on the potential colonization of humans on Mars.
When there is a disconnect between the intentions of their creator and the recipient, when algorithms go awry, they can have disastrous consequences.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Suggested Courses
Course of the Month21 days, 1 hour left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question