Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB program results discrepancy...

  1. May 12, 2015 #1

    I'm using MATLAB R2011a in my project, involving matrices of dimensions up to (70 × 20). I had good results, a time ago. Currently, poor results are generated using the very same code -(of good results)- with same parameters settings & relatively smaller matrices (30 × 20) !
    I tried:

    1. before running my code, at command line:

    clear import;

    2. inside my script, at the very beginning:

    clear all; clear classes; clear java;
    close all;

    3. running the same code, on two different computers (that I was using).

    Unfortunately, I ended up with the same poor results. It looks like the extensively repeatative code run (through my experiments), did some bad accumulation effect !
    Other than clearing memory & variables space, is there another aspect/issue that needs my attention?

    Appreciate your advice/help.

  2. jcsd
  3. May 12, 2015 #2


    Staff: Mentor

    Welcome to PF!

    Not much we can say without seeing your code. However, having said that I have one question:

    Have you tried doing what you did to clear things and then running it with the original size for your matrices?

    If you get the same results as before then it may have something to do with how your code works with the reduced matrices.
  4. May 15, 2015 #3


    User Avatar
    Gold Member

    There are a number of possibilities for why the results would be different, and as jedishrfu said it's hard to say much without seeing the code.

    That said, you just need to ask yourself what has changed:

    1. Was the script originally written and run using R2011a? Are you using that same release of MATLAB? If not, some of the functionality might have changed between releases. To investigate, check the release notes for the versions of MATLAB in between: http://www.mathworks.com/help/matlab/release-notes.html

    2. Are you using a new computer? If so, sometimes the exact processor that is used can affect the results of linear algebra operations.

    3. What validation techniques are you using to confirm good and bad results?
  5. May 15, 2015 #4


    Staff: Mentor

    Dont forget switching from windows to macos or linux could cause issues.
  6. May 16, 2015 #5


    User Avatar
    Science Advisor
    Gold Member
    2017 Award

    Calculations involving ill-conditioned matrices can be very sensitive to tiny changes. The new results may be just as valid as the original results even if they are very different. You may want to take a look at the characteristics of the matrices involved. Look for a large ratio of largest to smallest eigenvalue.
  7. May 16, 2015 #6
    kreil, jedishrfu, and FactChecker:
    Deeply appreciate your help & responses.

    I've just spotted the root cause (after about 12 days of investigation... :frown:), and resolved the issue :smile:.
    I'd like to share it with you and all viewers here:

    Part of my computations, involves a parameter. Before, this parameter was set manually to a given number of certain factor (say: delta = 0.3 * 1e-7).
    I had changed the way of setting this parameter to be computed using two other parameters "par1 & par2" as follows:

    delta = f(par1, par2) * 1e-7; where "f" denotes a function.

    "par1" is aleady set to a fixed value with the same factor (say: par1 = 0.002 * 1e-7). Hence, delta facor changed to a value < 1e-7 !
    Both delta & par1 must be of the same factor (in our example: 1e-7). So, omitting the factor "1e-7" from delta formula:

    delta = f(par1, par2);

    fixed the issue, and results were obtained as expected.

  8. May 16, 2015 #7


    Staff: Mentor

    The wonders of programming a little change here and nothing happens, a little change there and everything breaks and the world will never be the same.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook