'solve' function always returns zero for the case it should not be zero!!!

33 Ansichten (letzte 30 Tage)
Moteb Alqahtani
Moteb Alqahtani am 31 Mär. 2020
Bearbeitet: John D'Errico am 31 Mär. 2020
Hi there,
In the following code, I have tried to find the solutions for rho1, rho2, rho3, and rho4 by the use of the function "solve" where I already know theoretically what is the solution for all of them should be. the problem is that "solve" always gives zero for all cases.
Here is the code: (Note that, and for example, I have put omega=1, gamma=1, and delta=0. the theoretical solution for rho4=0.1667)
%-------------------------------------------
function BlochEquations2(omega,gamma,delta)
tic
syms rho1 rho2 rho3 rho4
MEs=[0.5 * 1i * omega * (rho2 - rho3) + 2 * gamma * rho4 == 0, ...
0.5 * 1i * omega * (rho1 - rho4) + (1i * delta - gamma) * rho2 == 0, ...
-0.5 * 1i * omega * (rho1 - rho4) - (1i * delta + gamma) * rho3 == 0, ...
-0.5 * 1i * omega * (rho2 - rho3) - 2 * gamma * rho4 == 0];
vars=[rho1 rho2 rho3 rho4];
S=solve(MEs,vars);
rho4_num=(S.rho4)
rho4_th=((0.25*omega^2)/(delta^2+gamma^2+0.5*omega^2)) % the theoretical solution
toc
end
  1 Kommentar
Moteb Alqahtani
Moteb Alqahtani am 31 Mär. 2020
You're right zero is also a solution. My question is then how to get the solution(s) I expect to see. Thanks

Melden Sie sich an, um zu kommentieren.

Antworten (1)

John D'Errico
John D'Errico am 31 Mär. 2020
Bearbeitet: John D'Errico am 31 Mär. 2020
Surely you cannot claim that 0 is not also a solution. The solution you know of may be the solution you want, but that does not invalidate the solution it returns.
Ok, I'll relent, just a bit. You have formulated a homogeneous system. In fact, it appears to be a linear system. In such a case, a homogeneous linear system, if it is full rank, has only a unique solution of all zeros. But is it full rank? Clearly not. In fact the first equation is identically the same as the 4th equation, except that you have multiplied by -1. So we can just drop equation 4 as providing no additional useful information. Equation 1 tells the same story.
As I said, the system must be of less than full rank, else no non-trivial solution can exist anyway. It looks like your system has rank 3, since while the second and third equations look pretty similar, they are indeed distinct. Null will implicitly tell us the rank of your system anyway.
Anyway, the solution is to use null. Lets see how it works.
omega = 1;
gamma = 1;
delta = 0;
syms rho1 rho2 rho3 rho4
MEs=[0.5 * 1i * omega * (rho2 - rho3) + 2 * gamma * rho4 == 0, ...
0.5 * 1i * omega * (rho1 - rho4) + (1i * delta - gamma) * rho2 == 0, ...
-0.5 * 1i * omega * (rho1 - rho4) - (1i * delta + gamma) * rho3 == 0];
[A,b] = equationsToMatrix(MEs,[rho1 rho2 rho3 rho4])
A =
[ 0, 1i/2, -1i/2, 2]
[ 1i/2, -1, 0, -1i/2]
[ -1i/2, 0, -1, 1i/2]
b =
0
0
0
As I said, a homogeneous linear system. It was probably discussed in a linear algebra course, somewhere. But not everybody seems to take them. A useful thing if you are solving linear systems of equations though.
Now the general solution to that problem is given by null.
rhos = null(A)
rhos =
5
2i
-2i
1
Is that a valid solution? TRY IT!
A*rhos
ans =
0
0
0
So, yes, indeed it is a solution.
The 4th element of which is the rho4 result you seem to want. However, you also need to recognize this solution set is normalized to unit norn. So the actual solution can be scaled by ANY constant. That is, rhos*k is also a valid solution, for any constant k.
Remember, this is a HOMOGENEOUS linear system. These are all thing you should know in regards to such a system, if you will be trying to solve them.

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by