Matlab's numeric solution to det of Matrix is incorrect

Click For Summary
SUMMARY

The discussion centers on discrepancies between the determinant calculations of a matrix in Mathematica 11 and Matlab R2017b using the vpasolve function. The user reports that while Mathematica provides a solution of L=4.73004, Matlab returns a significantly different value of approximately 3.94073. The conversation highlights potential issues with Matlab's determinant function, which may be affected by floating-point round-off errors, and suggests that the original Mathematica result may be incorrect or improperly translated into Matlab. Users are encouraged to verify initial guesses and consider the numerical stability of their calculations.

PREREQUISITES
  • Familiarity with Matlab R2017b and its vpasolve function
  • Understanding of symbolic computation in Mathematica 11
  • Knowledge of matrix determinants and LU decomposition
  • Experience with numerical methods and initial guess selection
NEXT STEPS
  • Investigate the differences between Matlab's vpasolve and Mathematica's Findroot functions
  • Learn about the limitations of Matlab's det function and its susceptibility to floating-point errors
  • Explore the use of graphical methods to select initial values for iterative solutions
  • Review the documentation on numerical stability in Matlab and Mathematica
USEFUL FOR

Matlab users, Mathematica users, researchers in numerical analysis, and anyone involved in solving matrix equations or optimizing numerical methods.

Thanos_ST
Messages
2
Reaction score
4
TL;DR
Equation solved numerically with vpasolve does not provide accurate solution. The solution is extracted from a PhD Thesis and was verified with Mathematica's numeric solver.
Hello everyone,

I have an equation derived as the det of a matrix, which I have solved in Mathematica 11 with Findroot and verified with the respective PhD Thesis' data. However, I now try to get more accustomed to Matlab (R2017b) and hence I tried to reproduce the problem and find its solution at this platform with vpasolve.
To my surprise, the Matlab solution is different! I also saw the plot, and it differs as well from the one Mathematica produces (which matches the one on the PhD Thesis). I even specify the solution of Mathematica to define the area (else the initial solution of Matlab is vastly different, see below).

So my code is the following:
Code:
syms L

B = [(-cos(L)+cosh(L))/(2*L^2) (-sin(L)+sinh(L))/(2*L^3); (-L*sin(L)+L*sinh(L))/(2*L^2) (-L*cos(L)+L*cosh(L))/(2*L^3)]

vpasolve (det(B) == 0, L, 4.7000) % L=4.73004 is the initial solution derived from Mathematica %

fplot (det(B), [-10, 10])

And the solution I get is 3.9407331356929149250770292025221 (instead of 4.73004). If I do not specify the area of the initial solution, the answer is -226.94495142003040084517833499812.

What am I doing wrong?

Thank you for reading my post.
 
Last edited:
  • Wow
Likes   Reactions: Wrichik Basu
Physics news on Phys.org
Why not post this on the Matlab website so they can look at it?

You're using Matlab 2017 not their latest product so even if there is an error and it doesn't happen on the latest Matlab they will not likely change it. They may test it themselves on the latest product and then again maybe not.
 
Something interesting is going on here. I could reproduce it on R2020b. Using solve returns the same as vpasolve without an initial condition. I don't think there is an error in MATLAB; probably we are not doing something correctly.

@Thanos_ST, Please let us know if you post it to MATLAB Central. I am interested in this.
 
Wrichik Basu I posted it on MATLAB central, per jedishrfu's suggestion.
EDIT: not on the one you found, I posted it on a different topic. Also, solve does not produce any solution for me.
 
How many solutions of your equation are there? Are you sure that your choice of initial guess will converge to the solution you are looking for?

EDIT: It should be straightforward to plot a graph of \det B(L) against L and see what's going on. This is always a necessary first step if you need to select an initial value for an iterative method; otherwise you may end up at a different solution than the one you expect.

EDIT: I see you did plot it.

Digging further at https://uk.mathworks.com/help/matlab/ref/det.html I found this:
Limitation: det uses the LU decomposition to calculate the determinant, which is susceptible to floating-point round-off errors.
Result: The determinant calculation is sometimes numerically unstable. For example, det can produce a large-magnitude determinant for a singular matrix, even though it should have a magnitude of 0.

However, Wolfram Alpha's symbolic calculation of the determinant (here), appears to agree with your Matlab result; in particular there is no root near 4.7 (detail plot for L=3 to 5).

It does seem like it is the original Mathematica result which is wrong, or else you have made a copying error when converting it to Matlab.
 
Last edited:
  • Like
Likes   Reactions: jedishrfu

Similar threads

  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
7K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K