I use Mathematica version 12.1 on Windows 10.
I have four equations in four unknowns.
Is there a trick to make Mathematica solve these?
I tried Solve
and NSolve
and it is not able to do it. Either it hangs (waited long time) or it says can't solve.
I copied the same equations over to Maple, converted them to Maple using Maple's Mathematica translator, and Maple solved them immediately.
Here is the code
ClearAll[a,b,c,d];
T = 2 Pi;
bt = MatrixExp[{{a, b}, {c, d}}*T];
cmat = {{Sin[1], Cos[1]}, {-Cos[1], Sin[1]}};
eqs = {cmat[[1, 1]] == bt[[1, 1]],
cmat[[1, 2]] == bt[[1, 2]],
cmat[[2, 1]] == bt[[2, 1]],
cmat[[2, 2]] == bt[[2, 2]]};
Solve[eqs, {a, b, c, d}] (* Hangs, and after about 30 minutes I gave up *)
If I do Solve[eqs, {a, b, c, d}, Reals]
it gives
Solve::nsmet This system cannot be solved with the methods available to Solve
I also tried NSolve[eqs, {a, b, c, d}]
, but it seems to hang also.
Here it is in Maple:
restart;
T := 2*Pi;
BT := Matrix([[a,b],[c,d]])*T:
BT := LinearAlgebra[MatrixExponential](BT);
cmat := Matrix([[sin(1), cos(1)], [-cos(1), sin(1)]]);
eqs := [cmat[1,1]=BT[1,1],cmat[1,2]=BT[1,2],cmat[2,1]=BT[2,1],cmat[2,2]=BT[2,2]]:
sol := solve(eqs,[a,b,c,d]);
evalf(sol)
[[a = 0.,
b = 0.09084505695 - (6.571202944*10^(-12))*I,
c = -0.09084505695 + (6.571202944*10^(-12))*I,
d = 0.]]
The answer time is less than one second.
At first I thought the matrix exponentials are different. But I compared them and they are the same. I then copied Mathematica's bt
variable over to Maple, and used that, and Maple gave the same answer:
restart;
with(MmaTranslator); # Used to translate mma code to Maple
T := 2*Pi;
cmat := Matrix([[sin(1), cos(1)], [-cos(1), sin(1)]]);
# This below is bt from Mathematica. This is the result of MatrixExp[{{a, b}, {c, d}}*T];
# done in Mathematica and copied here to see if Maple can solve it
BT := FromMma(`{{-(((a - d - Sqrt[a^2 + 4*b*c - 2*a*d + d^2])*E^((a + d - Sqrt[a^2 + 4*b*c - 2*a*d + d^2])*Pi))/(2*Sqrt[a^2 + 4*b*c - 2*a*d + d^2])) +
((a - d + Sqrt[a^2 + 4*b*c - 2*a*d + d^2])*E^((a + d + Sqrt[a^2 + 4*b*c - 2*a*d + d^2])*Pi))/(2*Sqrt[a^2 + 4*b*c - 2*a*d + d^2]),
-((b*E^((a + d - Sqrt[a^2 + 4*b*c - 2*a*d + d^2])*Pi))/Sqrt[a^2 + 4*b*c - 2*a*d + d^2]) + (b*E^((a + d + Sqrt[a^2 + 4*b*c - 2*a*d + d^2])*Pi))/
Sqrt[a^2 + 4*b*c - 2*a*d + d^2]}, {-((c*E^((a + d - Sqrt[a^2 + 4*b*c - 2*a*d + d^2])*Pi))/Sqrt[a^2 + 4*b*c - 2*a*d + d^2]) +
(c*E^((a + d + Sqrt[a^2 + 4*b*c - 2*a*d + d^2])*Pi))/Sqrt[a^2 + 4*b*c - 2*a*d + d^2],
-(((-a + d - Sqrt[a^2 + 4*b*c - 2*a*d + d^2])*E^((a + d - Sqrt[a^2 + 4*b*c - 2*a*d + d^2])*Pi))/(2*Sqrt[a^2 + 4*b*c - 2*a*d + d^2])) +
((-a + d + Sqrt[a^2 + 4*b*c - 2*a*d + d^2])*E^((a + d + Sqrt[a^2 + 4*b*c - 2*a*d + d^2])*Pi))/(2*Sqrt[a^2 + 4*b*c - 2*a*d + d^2])}}`):
eqs := [cmat[1,1]=BT[1,1],cmat[1,2]=BT[1,2],cmat[2,1]=BT[2,1],cmat[2,2]=BT[2,2]]:
sol := solve(eqs,[a,b,c,d]);
evalf(sol)
gives
[[a = 0.,
b = 0.09084505695 - (6.571202944*10^(-12))*I,
c = -0.09084505695 + (6.571202944*10^(-12))*I,
d = 0.]]
What else should I try to make Mathematica solve these four equations?