Java and Matlab - URGENT

Posted on 2006-04-19
Last Modified: 2016-02-10

There was this program in matlab which was converted to java. My problem is that I am not getting the exact results like the matlab version .  For example, if I were to run it 5 iterations , it is somewhat similar..and If i were to run it for 500 iterations..the result is not really similar...

My question is that lets  say I use  the Java's nextGaussian, nextFloat to replace the Matlab randn,rand..

Would the result be different because I am using different languange.....
Matlab              Java
randn              nextGaussian()
rand                nextFloat()
Question by:Jasbir21

    Author Comment

    Is it possible to have a program converted and display the exact same results....
    LVL 6

    Expert Comment

    Hi ,

    The methods you are using are random number generators.
    So the results may not be the same.

    If you can tell more details abt your class requirement then we can help you

    LVL 30

    Expert Comment

    Random numbers generated will anyway always change, that is why they are 'random'. Did you expect to see the same numbers getting generated everytime?

    Author Comment

    actually, the random generators are the core of the program and is used to simulate a simulation. My question, lets say i program is converted from matlab to java, does it behave the same way....

    For example,in Matlab i use rand, but in java is nextFloat()...both are random generators...but would the values produced by the exact same...i know that if it is random generators, it is not going to produce the values at that same time..

    I mean lets say Matlab produces value 0.789 and the number of times it produces it would be different than java right ?? pls advice..
    LVL 30

    Expert Comment

    >> but would the values produced by the exact same

    I guess not.

    >> I mean lets say Matlab produces value 0.789 and the number of times it produces it would be different than java right

    I think so.

    Author Comment

    Is there a way to confirm coz I need to run tests to explain why is it not similar ?
    LVL 6

    Accepted Solution

    when you run your application in matlab, even then u cant predict what rand function is going to return.
    random number generation is the same, regardless of any language.
    one cant predict the number that would be generated.

    i think this explaination would be more convincing. :)
    LVL 30

    Assisted Solution

    >> Is there a way to confirm coz I need to run tests to explain why is it not similar ?

    The simple means to do it is to run 2 simple programs (one random number generator in Java and one in MatLab) a number of times and see the output for yourself.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    Annotation to do Dependency injection in spring 3 30
    sameEnds challenge 25 55
    array220 challenge 8 30
    strCount chalenge 3 34
    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    The viewer will learn how to implement Singleton Design Pattern in Java.

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now