solve 4 equations with some unknowns parameters.

I'm attempting to solve this problem which is attached. But I faced ERROR. Any suggestions?

12 件のコメント

Matt J
Matt J 2018 年 11 月 2 日
編集済み: Matt J 2018 年 11 月 2 日
We can't make suggestions until you tell us what the error is.
Skill_s
Skill_s 2018 年 11 月 2 日
編集済み: Matt J 2018 年 11 月 2 日
I have attached the .m file, however the error is below:
Error in ==> equation_2_8 at 13
sol = solve([eqn1, eqn2, eqn3, eqn4], [A, B, C, D]);
>> I do not know the exact meaning of error
Matt J
Matt J 2018 年 11 月 2 日
This looks like only part of the message. The full error message should give a reason, as well as the error location.
madhan ravi
madhan ravi 2018 年 11 月 2 日
編集済み: madhan ravi 2018 年 11 月 2 日
when I ran your code it didn't have any errors instead it returned all zeros
Stephan
Stephan 2018 年 11 月 2 日
編集済み: Stephan 2018 年 11 月 2 日
Which Matlab Release do you use? with R2018b i got the same result as Madhan.
Skill_s
Skill_s 2018 年 11 月 2 日
I use R2010b
Skill_s
Skill_s 2018 年 11 月 2 日
the messages of error is: ??? Error using ==> char Conversion to char from logical is not possible.
Error in ==> solve>getEqns at 169 vc = char(v);
Error in ==> solve at 67 [eqns,vars] = getEqns(varargin{:});
Error in ==> equation_2_8 at 13 sol = solve([eqn1, eqn2, eqn3, eqn4], [A, B, C, D]);
madhan ravi
madhan ravi 2018 年 11 月 2 日
do you have symbolic toolbox? type ver in command window to check whether you have that toolbox
Skill_s
Skill_s 2018 年 11 月 2 日
編集済み: Matt J 2018 年 11 月 2 日
I wrote "ver" in command window, the message is:
>> ver
-------------------------------------------------------------------------------------
MATLAB Version 7.11.0.584 (R2010b)
MATLAB License Number:
Operating System: Microsoft Windows 7 Version 6.2 (Build 9200)
Java VM Version: Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode
-------------------------------------------------------------------------------------
MATLAB Version 7.11 (R2010b)
Simulink Version 7.6 (R2010b)
Aerospace Blockset Version 3.6 (R2010b)
Aerospace Toolbox Version 2.6 (R2010b)
Bioinformatics Toolbox Version 3.6 (R2010b)
Communications Blockset Version 5.0 (R2010b)
Communications Toolbox Version 4.6 (R2010b)
Control System Toolbox Version 9.0 (R2010b)
Curve Fitting Toolbox Version 3.0 (R2010b)
DO Qualification Kit Version 1.3 (R2010b)
Database Toolbox Version 3.8 (R2010b)
Datafeed Toolbox Version 4.0 (R2010b)
EDA Simulator Link Version 3.2 (R2010b)
Econometrics Toolbox Version 1.4 (R2010b)
Filter Design HDL Coder Version 2.7 (R2010b)
Filter Design Toolbox Version 4.7.1 (R2010b)
Financial Derivatives Toolbox Version 5.6 (R2010b)
Financial Toolbox Version 3.8 (R2010b)
Fixed-Income Toolbox Version 2.0 (R2010b)
Fixed-Point Toolbox Version 3.2 (R2010b)
Fuzzy Logic Toolbox Version 2.2.12 (R2010b)
Global Optimization Toolbox Version 3.1 (R2010b)
IEC Certification Kit Version 1.3 (R2010b)
Image Acquisition Toolbox Version 4.0 (R2010b)
Image Processing Toolbox Version 7.1 (R2010b)
Instrument Control Toolbox Version 2.11 (R2010b)
MATLAB Builder EX Version 1.3 (R2010b)
MATLAB Builder JA Version 2.2 (R2010b)
MATLAB Builder NE Version 3.2 (R2010b)
MATLAB Compiler Version 4.14 (R2010b)
MATLAB Distributed Computing Server Version 5.0 (R2010b)
MATLAB Report Generator Version 3.9 (R2010b)
Mapping Toolbox Version 3.2 (R2010b)
Model Predictive Control Toolbox Version 3.2.1 (R2010b)
Neural Network Toolbox Version 7.0 (R2010b)
Optimization Toolbox Version 5.1 (R2010b)
Parallel Computing Toolbox Version 5.0 (R2010b)
Parallel Computing Toolbox Version 5.0 (R2010b)
Partial Differential Equation Toolbox Version 1.0.17 (R2010b)
RF Toolbox Version 2.8 (R2010b)
Real-Time Workshop Version 7.6 (R2010b)
Real-Time Workshop Embedded Coder Version 5.6 (R2010b)
Robust Control Toolbox Version 3.5 (R2010b)
Signal Processing Blockset Version 7.1 (R2010b)
Signal Processing Toolbox Version 6.14 (R2010b)
SimBiology Version 3.3 (R2010b)
SimDriveline Version 1.5.5 (R2010b)
SimElectronics Version 1.5 (R2010b)
SimEvents Version 3.1.1 (R2010b)
SimHydraulics Version 1.8 (R2010b)
SimMechanics Version 3.2.1 (R2010b)
SimPowerSystems Version 5.3 (R2010b)
SimRF Version 3.0 (R2010b)
Simscape Version 3.4 (R2010b)
Simulink 3D Animation Version 5.2 (R2010b)
Simulink Control Design Version 3.2 (R2010b)
Simulink Design Optimization Version 1.2 (R2010b)
Simulink Design Verifier Version 1.7 (R2010b)
Simulink Fixed Point Version 6.4 (R2010b)
Simulink Report Generator Version 3.9 (R2010b)
Simulink Verification and Validation Version 3.0 (R2010b)
Spreadsheet Link EX Version 3.1.2 (R2010b)
Stateflow Version 7.6 (R2010b)
Stateflow Coder Version 7.6 (R2010b)
Statistics Toolbox Version 7.4 (R2010b)
Symbolic Math Toolbox Version 5.5 (R2010b)
System Identification Toolbox Version 7.4.1 (R2010b)
SystemTest Version 2.6 (R2010b)
Video and Image Processing Blockset Version 3.1 (R2010b)
Wavelet Toolbox Version 4.6 (R2010b)
>>
Skill_s
Skill_s 2018 年 11 月 2 日
Thnks all the version of my windows is 10. Is it related to the version of windows?
Star Strider
Star Strider 2018 年 11 月 2 日
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)
...
Skill_s
Skill_s 2018 年 11 月 2 日
Thanks a lot. So, what should I do? Should I run another version of MATLAB?

サインインしてコメントする。

 採用された回答

Bruno Luong
Bruno Luong 2018 年 11 月 3 日
編集済み: Bruno Luong 2018 年 11 月 3 日

0 投票

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.

4 件のコメント

Skill_s
Skill_s 2018 年 11 月 3 日
Yes @ Bruno Luong . Thanks. The EM field with 3 layers. yeah you are right.
Walter Roberson
Walter Roberson 2018 年 11 月 3 日
編集済み: Walter Roberson 2018 年 11 月 4 日
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.
Skill_s
Skill_s 2018 年 11 月 4 日
Thanks a lot. @ Walter Roberson. thnks
Bruno Luong
Bruno Luong 2018 年 11 月 4 日
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.

サインインしてコメントする。

その他の回答 (1 件)

Florian Augustin
Florian Augustin 2018 年 11 月 2 日

1 投票

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

7 件のコメント

Skill_s
Skill_s 2018 年 11 月 2 日
Thanks a lot for your guidance.
Matt J
Matt J 2018 年 11 月 2 日
@Skill93,
If Florian's answer was what you were looking for, then you should Accept-click it.
Walter Roberson
Walter Roberson 2018 年 11 月 2 日
If I recall correctly, in R2010b, the syntax used for solve() was available but not clearly documented.
The problem was elsewhere: before R2011b, using relational expressions with symbolic expressions caused the expressions to be evaluated as a logical immediately. So the line
eqn1 = (C*exp(k1*a))+(D*exp(-k1*a))-(A*exp(-k3*a))==0;
built the expression on the left side, and immediately compared it to 0, found it was not identical, and immediately returned false into eqn1.
The workaround in those days was to not do the ==0 part on the equations: convert
eqn = A == B
to
eqn = (A) - (B)
And in those days, if you had an inequality such as
eqn1 = (C*exp(k1*a))+(D*exp(-k1*a))-(A*exp(-k3*a)) > 3
then you would have to build it using character vectors,
eqn1 = '(C*exp(k1*a))+(D*exp(-k1*a))-(A*exp(-k3*a)) > 3'
This would pretty much force you to use separate entries in the solve() command, like the
sol = solve(eqn1, eqn2, eqn3, eqn4, A, B, C, D);
that Florian shows, since [eqn1, eqn2, eqn3, eqn4] with character vectors would result in a single long character vector instead of multiple equations.
So, Florian's suggested code should work for the purpose, just not for exactly the reason that Florian indicated.
Skill_s
Skill_s 2018 年 11 月 2 日
Yes @Walter Roberson said correctly. and the guidance of @ Florian Augustin , gives zero output. the purpose is to solve parametric solutions not numerically. May be I should change to higher version of MATLAB
Stephan
Stephan 2018 年 11 月 2 日
Executing your code in 2018b gives the same result. So you need a better approach.
Walter Roberson
Walter Roberson 2018 年 11 月 2 日
MATLAB gives all 0.
If you work through the equations one by one doing stepwise elimination, then all 0 is the only solution.
Skill_s
Skill_s 2018 年 11 月 3 日
Thanks all...

サインインしてコメントする。

カテゴリ

製品

リリース

R2010b

質問済み:

2018 年 11 月 2 日

コメント済み:

2018 年 11 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by