Error trying to solve an equation

4 ビュー (過去 30 日間)
Ben
Ben 2015 年 3 月 24 日
コメント済み: Ben 2015 年 3 月 24 日
I'm trying to write a script to find a decision boundary between two classes which are distributed as 2-dimensional normal distributions. Here is my script (the estimated mean and covariance matrices are calculated previous to this running):
e = exp(1);
syms x;
sig1_det = det(sigma1_est);
sig2_det = det(sigma2_est);
zero = solve(1/(sig1_det^(1/2))*exp(-1/2*(x-mu1_est)\sigma1_est...
*(x-mu1_est)') == 1/(sig2_det^(1/2))*exp(-1/2*(x-mu2_est)\...
sigma2_est*(x-mu2_est)'), x);
However, when I run this, I get an error on the line with the "solve" call. Here's the error(s):
Error using mupadmex Error in MuPAD command: Operands are invalid. [linalg::matlinsolve]
Error in sym/privBinaryOp (line 835) Csym = mupadmex(op,args{1}.s, args{2}.s, varargin{:});
Error in \ (line 284) X = privBinaryOp(A, B, 'symobj::mldivide');
Error in script (line 6) zero = solve(1/(sig1_det^(1/2))*exp(-1/2*(x-mu1_est)\sigma1_est...
What'd I do wrong?

回答 (1 件)

Roger Stafford
Roger Stafford 2015 年 3 月 24 日
編集済み: Roger Stafford 2015 年 3 月 24 日
I see a couple of dubious entities in your expression to be solved. First, you have used the backslash symbol, '\', which doesn't seem to belong there, and second, you have used a quote sign: (x-mu1_est)') in two places, and that is inappropriate, too.
  1 件のコメント
Ben
Ben 2015 年 3 月 24 日
I had used the inv function, but Matlab suggested I do A\B rather than A*inv(B), so I changed that. The apostrophes are there because the mu variables are 1x2 vectors, so they need to be transposed on the right side of the covariance matrix, which is 2x2. However, I did try changing those things and got a different set of errors:
Error using mupadmex Error in MuPAD command: The dimensions do not match. [(Dom::Matrix(Dom::ExpressionField()))::_mult2]
Error in sym/privBinaryOp (line 835) Csym = mupadmex(op,args{1}.s, args{2}.s, varargin{:});
Error in * (line 219) X = privBinaryOp(A, B, 'symobj::mtimes');
Error in Question5b (line 6) zero = solve(1/(sig1_det^(1/2))*exp(-1/2*(x-mu1_est)*inv(sigma1_est)...

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by