フィルターのクリア

error using sym/subs with logical operation

1 回表示 (過去 30 日間)
alice W
alice W 2019 年 7 月 4 日
コメント済み: Stephen23 2019 年 7 月 4 日
Hello,
here is my code
syms x1 x2
aa=x1 == 0 & x2 == 0
subs(aa, [0.5 0.5])
the result is
ans =
[ 1/2 == 0 & x2 == 0, 1/2 == 0 & x2 == 0]
I wanna get result like this
1/2==0 & 1/2==0
What's the problem?
Thanks.

採用された回答

Stephan
Stephan 2019 年 7 月 4 日
編集済み: Stephan 2019 年 7 月 4 日
1
You only substitute x1 - you have to substitute them both. Try:
syms x1 x2
aa= x1 == 0 & x2 == 0
aa = subs(aa,[x1 x2], [0.5 0.5])
which results in:
aa =
1/2 == 0
2
Or use vectors, which doesnt work together with "&":
syms x1 x2
aa=[x1 == 0, x2 == 0]
aa = subs(aa,[x1 x2], [0.5 0.5])
result is:
aa =
[ 1/2 == 0, 1/2 == 0]
3
If you use 2 different numbers:
syms x1 x2
aa= x1 == 0 & x2 == 0
aa = subs(aa,[x1 x2], [0.5 0.6])
you get:
aa =
1/2 == 0 & 3/5 == 0
because Matlab can not simplify this, like it did in the first example.
  3 件のコメント
Stephan
Stephan 2019 年 7 月 4 日
my pleasure - please accept useful answers
Stephen23
Stephen23 2019 年 7 月 4 日
+1 clear and useful answer

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by