2

我想在 matlab 中求解给定的方程以找到 beta 的值但得到错误。我在下面发布代码和错误。

提前致谢。

n1=1.77;
n2=1.45;
d=1e-6;
lambda = 1e-6;
ko = 2*pi/lambda;
A=(ko*n1)^2;
B=(ko*n2)^2;
syms beta;
s = 'sqrt(A-beta^2)*(d/2)*tan(sqrt(A-beta^2)*d/2)=sqrt(beta^2-B)*(d/2)';
solve (s);

错误:

Error using solve>processString (line 337)
' sqrt(A-beta^2)*(d/2)*tan(sqrt(A-beta^2)*d/2)=sqrt(beta^2-B)*(d/2) ' is not a valid expression or equation.

Error in solve>getEqns (line 267)
   eqns = processString(eqns, v, vc);

Error in solve (line 150)
   [eqns,vars,options] = getEqns(varargin{:});

Error in transcendetal (line 9)
   solve (s); 
4

1 回答 1

1

I confirm the following works on R2013a:

syms beta A B d

n1=1.77;
n2=1.45;
d=1e-6;
lambda = 1e-6;
ko = 2*pi/lambda;
A=(ko*n1)^2;
B=(ko*n2)^2;

solve ( sqrt(A-beta^2)*(d/2)*tan(sqrt(A-beta^2)*d/2)==sqrt(beta^2-B)*(d/2))

However,

Warning: Explicit solution could not be found.
> In solve at 179
ans =
[ empty sym ]

This is odd, because in R2010a with the 'old' syntax you give above, I get

ans =
                                                                                                   0
 -(log((A + B - 2*beta^2 + 2*(A - beta^2)^(1/2)*(beta^2 - B)^(1/2)*i)/(A - B))*i)/(A - beta^2)^(1/2)

Note that this last solution is complex-valued, which might be some option you have to enable in later versions...I don't know the symbolic math toolbox very well; I still prefer the whiteboard method :p

于 2013-11-04T14:58:27.983 回答