Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Large numerical errors in my Mathematica program

Here is a piece of my program. Have a look.

For[m = 1, m <= mode1, m++,
  For[n = 0, n <= mode2, n++,
    A[m, n][t_] = a[m, n]*Cos[\[Omega]*t];
    B[m, n][t_] = b[m, n]*Cos[\[Omega]*t];
  ]
]

temp = 0;
For[m = 1, m <= mode1, m++,
  For[n = 0, n <= mode2, n++,
    temp++;
    equation[temp] = 
      ExpandAll[Integrate[eqC[m, n]*Cos[\[Omega]*t], {t, 0, (2*Pi)/\[Omega]}]];
    equation[temp] = ExpandAll[Simplify[equation[temp]/10^9]];
    Print["\n\nEquation ", temp, "-\n", equation[temp]];
    temp++;
    equation[temp] = 
      ExpandAll[Integrate[eqS[m, n]*Cos[\[Omega]*t], {t, 0, (2*Pi)/\[Omega]}]];
    equation[temp] = ExpandAll[Simplify[equation[temp]/10^9]];
    Print["\n\nEquation ", temp, "-\n", equation[temp]];
  ]
]

After running of this code I am supposed to get few equations and then create a matrix out of it by a series of differentiations. I know that the matrix must come out to be symmetric. The problem is that when I enter simple data i.e. e=1,h=1, etc. I get accurate results and the matrix is symmetric, but as soon as I give the real data which have values like 71.02e9,0.000247 the calculations come out to be wrong and I get an unsymmetric matrix. I have thoroughly checked the code and cannot find a single mistake on my part. I have also checked the results of the program for a simple case with manual calculations.


1 Answers

You can try and increase the precision of your calculations by globally setting, e.g., $MinPrecision=50 and specifying your data values to a high precision using either foo = SetPrecision[0.000247,50] or using the shorthand 0.000247`50.

like image 160
Timo Avatar answered Feb 18 '26 08:02

Timo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!