Matlab's numeric solution to det of Matrix is incorrect

47 views (last 30 days)
Hello everyone,
I have an equation derived as the det of a matrix, which I have already solved in another software numerically and verified with the respective PhD Thesis' data. However, I now try to get more accustomed to Matlab 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 the other software produces (which matches the one on the PhD Thesis). I even specify the solution of the textbook to define the area (else the initial solution of Matlab is vastly different, see below).
So my code is the following:
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)]
B = 
vpasolve (det(B) == 0, L, 4.7000) % L=4.73004 is the initial solution from PhD Thesis %
ans = 
3.9407331356929149250770292025221
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.
  3 Comments
Torsten
Torsten on 1 Jul 2023
As you can see from the last line of Paul's code, det(B) = -0.05757... for L = 4.73004 and det(B) = 1.2645e-37 for L = 3.940733. So either your definition of B is wrong or the other software is wrong. Nothing else is possible.

Sign in to comment.

Answers (4)

Paul
Paul on 1 Jul 2023
Hi ThanosST,
Are you sure the expressions in B are entered correctly? Asking because it sure looks like L = 3.9407 is the solution closest to 4.7. How did you get the solution L = 4.7304 in the other software?
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)]
B = 
vpasolve (det(B) == 0, L, 4.7000) % L=4.73004 is the initial solution from PhD Thesis %
ans = 
3.9407331356929149250770292025221
fplot (det(B), [-10, 10]),grid,xline(double(ans))
vpa(subs(det(B),L,[4.73004 ans]))
ans = 
  1 Comment
ThanosST
ThanosST on 1 Jul 2023
Thank you i will look at it again, at least my use of vpasolve in the code is correct from what I understand.

Sign in to comment.


Steven Lord
Steven Lord on 1 Jul 2023
Let's plot your solution from the thesis and the solution returned by MATLAB.
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)];
sol = vpasolve (det(B) == 0, L, 4.7000); % L=4.73004 is the initial solution from PhD Thesis %
fplot (det(B), [-10, 10])
yline(0, 'r')
hold on
f = @(x) double(subs(det(B), L, x)); % Evaluate the determinant at a specified point
plot(double(sol), f(sol), 'ko')
plot(4.73004, f(4.73004), 'kx')
It certainly looks to me like the black circle is at the intersection of the blue curve of the determinant and the red line y = 0. To my eye, the solution you said was given in the thesis (the black x) is one of the values of L for which the determinant is (roughly) -0.05.
The fact that the common factor of L was not cancelled out in the numerator and denominator of the elements in the second row of B makes me a little suspicious that you made an error converting the expression in the thesis into code. I suppose it could have been left in to demonstrate a pattern in the elements down the columns of B, but I'd still double-check to be safe.
  1 Comment
ThanosST
ThanosST on 1 Jul 2023
Thank you for your time I will look at it again. At least I verified after your post that there is nothing wrong with my code or sth that I am missing with vpasolve's functionality.

Sign in to comment.


Andreas
Andreas on 14 Oct 2025 at 10:30
The number 3.94073313569... is one solution of the equation e^(-x) = cos(x) - sin(x). Does this help or make sense?
  2 Comments
Andreas
Andreas on 15 Oct 2025 at 9:52
I just found by Google search of the solution to the above equality that the same number was a result of this thread. See below my second comment. I only wanted to know what is the reason for this

Sign in to comment.


Andreas
Andreas on 14 Oct 2025 at 12:23
This answer was flagged by Dyuman Joshi
The number 3.9407331356929149250770292025221… is not random. It is the exact solution to the equation:
ex=cos(x)sin(x)e^{-x} = \cos(x) - \sin(x)ex=cos(x)sin(x)
This equation has a root at that value, which can be verified numerically to extremely high precision. The fact that this same number appears as the result of a determinant calculation in MATLAB suggests that the matrix or the numerical method used may be implicitly linked to this equation — possibly through rounding behavior, algorithmic structure, or hidden mathematical resonance.
If anyone can confirm or further explore this connection, it would be greatly appreciated.

Products


Release

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!