Matlab's numeric solution to det of Matrix is incorrect

Click For Summary

Discussion Overview

The discussion revolves around discrepancies observed between the numerical solutions for the determinant of a matrix calculated using Matlab and Mathematica. Participants explore the implications of these differences, particularly focusing on the use of the vpasolve function in Matlab and the initial conditions provided.

Discussion Character

  • Debate/contested
  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant reports a significant difference in the solution for the determinant of a matrix when using Matlab's vpasolve compared to Mathematica's Findroot, questioning the accuracy of Matlab's output.
  • Another participant suggests that the issue may not be a bug in Matlab, as they were able to reproduce the same results in a newer version, indicating a potential misunderstanding in the setup or execution of the problem.
  • Concerns are raised about the choice of initial guess for the iterative method, with a suggestion that this could affect convergence to the expected solution.
  • A participant points out that the determinant calculation in Matlab may be numerically unstable due to floating-point round-off errors, which could explain the discrepancies observed.
  • There is mention of a similar thread found on MATLAB Central, indicating that this issue may not be unique to the current discussion.
  • One participant references Wolfram Alpha's symbolic calculation, which appears to agree with Matlab's result, suggesting that the original Mathematica result might be incorrect or that there was an error in translating the problem to Matlab.

Areas of Agreement / Disagreement

Participants express differing views on the reliability of the solutions provided by Matlab versus Mathematica, with no consensus reached on the correctness of either platform's output. The discussion remains unresolved regarding the root cause of the discrepancies.

Contextual Notes

Participants note potential limitations related to the numerical stability of determinant calculations in Matlab, as well as the importance of selecting appropriate initial guesses for iterative methods. There is also an acknowledgment of the possibility of errors in translating the problem from Mathematica to Matlab.

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