# solve 4 equations with some unknowns parameters.

19 views (last 30 days)
Skill93 on 2 Nov 2018
Commented: Bruno Luong on 4 Nov 2018
I'm attempting to solve this problem which is attached. But I faced ERROR. Any suggestions?

Skill93 on 2 Nov 2018
Thnks all the version of my windows is 10. Is it related to the version of windows?
Star Strider on 2 Nov 2018
The ver output disagrees with you:
MATLAB Version 7.11.0.584 (R2010b)
Operating System: Microsoft Windows 7 Version 6.2 (Build 9200)
...
Symbolic Math Toolbox Version 5.5 (R2010b)
...
Skill93 on 2 Nov 2018
Thanks a lot. So, what should I do? Should I run another version of MATLAB?

Bruno Luong on 3 Nov 2018
Edited: Bruno Luong on 3 Nov 2018
Your problem looks like you find the EM field with 3 layers and 2 interfaces. The coefficients A, B, C, D gives the strength of different field components, they are linearly related because EM is linear. In order to solve with without getting trivial solution
A=B=C=D=0
You must for example fix one of them arbitrary, e.g.
A = 1
That left you with 4 linear equations and 3 unknowns. Then in order such system to have solution, you must have the linear system to have dependent equation, meaning determinant of the matrix is 0.
Write it down this probably gives the equation you looks for.
I don't have symbolic tbx to do this kind of calculation to confirm, it would be possible to carry out numerically me think.

Show 1 older comment
Walter Roberson on 3 Nov 2018
If you solve the first three equations for B, C, D, then you are left with
-A*(-(eps1*k3+eps3*k1)*(eps1*k2+eps2*k1)*exp(a*(2*k1-k3))+exp(-a*(2*k1+k3))*(-eps1*k3+eps3*k1)*(-eps1*k2+eps2*k1))/(2*eps3*k1*eps2*eps1) == 0
The obvious solution is A == 0, which then causes B, C, D to all be 0. If, on the other hand, (-(eps1*k3+eps3*k1)*(eps1*k2+eps2*k1)*exp(a*(2*k1-k3))+exp(-a*(2*k1+k3))*(-eps1*k3+eps3*k1)*(-eps1*k2+eps2*k1))/(2*eps3*k1*eps2*eps1) can be 0, then the equations would hold for all finite A, in which case there would be a family of solutions
B = A*((eps1*k3+eps3*k1)*exp(4*a*k1)+eps3*k1-eps1*k3)*exp(-a*(2*k1-k2+k3))/(2*eps3*k1)
C = -A*(eps1*k3-eps3*k1)*exp(-a*(k1+k3))/(2*eps3*k1)
D = A*(eps1*k3+eps3*k1)*exp(a*(k1-k3))/(2*eps3*k1)
which are linear in A.
Skill93 on 4 Nov 2018
Thanks a lot. @ Walter Roberson. thnks
Bruno Luong on 4 Nov 2018
Actually solving linear system is not what Skill interested, what he is interested is the the condition under which the 4 linear equation is dependent thus solvable.
This boils down to single equation of determinant. I shows here the solution he gives makes DET(M) = 0.
% Fake k, epsilon 1,2,3
k = rand(1,3);
eps = rand(1,3);
p = k./eps;
% compute solution a
r = ((p(1)+p(2))*(p(1)+p(3)))/((p(1)-p(2))*(p(1)-p(3)));
a = log(r)/(-4*k(1))
% Forming linear matrix
ep = exp(k*a);
em = exp(-k*a);
M = [em(3) 0 -ep(1) -em(1);
p(3)*em(3) 0 p(1)*ep(1) -p(1)*em(1);
0 em(2) -em(1) -ep(1);
0 -p(2)*em(2) p(1)*em(1) -p(1)*ep(1)];
% verifies the 4 x 4 system is rank 3
rank(M)
det(M)
Now if Walter who has access to Symb Tbx can show the opposite, started from
det(M) = 0
shows the solution of it is
r = ((p(1)+p(2))*(p(1)+p(3)))/((p(1)-p(2))*(p(1)-p(3)));
a = log(r)/(-4*k(1))
Then the problem is completely solved.

Florian Augustin on 2 Nov 2018
Hi,
I think you are using a modern syntax to call 'solve' that was not supported in R2010b. The equivalent call in R2010b would be
syms a A B C D eps1 eps2 eps3 k1 k2 k3;
eqn1 = (C*exp(k1*a))+(D*exp(-k1*a))-(A*exp(-k3*a));
eqn2 = ((-(C*k1)/eps1)*exp(k1*a))+(((D*k1)/eps1)*exp(-k1*a))-(((A*k3)/eps3)*exp(-k3*a));
eqn3 = (C*exp(-k1*a))+(D*exp(k1*a))-(B*exp(-k2*a));
eqn4 = ((-(C*k1)/eps1)*exp(-k1*a))+(((D*k1)/eps1)*exp(k1*a))+(((B*k2)/eps2)*exp(-k2*a));
sol = solve(eqn1, eqn2, eqn3, eqn4, A, B, C, D);
ASol = sol.A
BSol = sol.B
CSol = sol.C
DSol = sol.D
You can access the documentation for your release of MATLAB by typing 'doc solve' in the MATLAB interface.
Hope this helps,
-Florian

Stephan on 2 Nov 2018
Executing your code in 2018b gives the same result. So you need a better approach.
Walter Roberson on 2 Nov 2018
MATLAB gives all 0.
If you work through the equations one by one doing stepwise elimination, then all 0 is the only solution.
Skill93 on 3 Nov 2018
Thanks all...

R2010b

### Community Treasure Hunt

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

Start Hunting!