フィルターのクリア

Starting with all symbols, ending with mixed symbols and number?

1 回表示 (過去 30 日間)
Craig
Craig 2023 年 12 月 11 日
編集済み: Dyuman Joshi 2023 年 12 月 11 日
I'm performing some symbolic manipulations that result in
(a/b)*x
I'd like to keep 'x' a symbol and substitute numbers for a and b. Unfortunately, the numbers are treated symbolically and a/b doesn't simplify
double((a/b)*x ) doesn't work because x is still a symbol. I'm sure there's a trivial solution that I haven't found.
thanks in advance

採用された回答

Walter Roberson
Walter Roberson 2023 年 12 月 11 日
syms a b x
%Expression
y = (a/b)*x;
newy0 = subs(y, [a b], [2 3])
newy0 = 
newy1 = subs(y, [a b], sym([2 3], 'd'))
newy1 = 
newy2 = vpa(subs(y, [a b], [2 3]))
newy2 = 
sympref('FloatingPointOutput', true)
ans = logical
0
newy4 = subs(y, [a b], [2 3])
newy4 = 

その他の回答 (2 件)

Dyuman Joshi
Dyuman Joshi 2023 年 12 月 11 日
編集済み: Dyuman Joshi 2023 年 12 月 11 日
Use subs -
syms a b x
%Expression
y = (a/b)*x;
y = subs(y, [a b], [2 3])
y = 
If you want the expression in decimal representation, you could use vpa -
%Decimal representation with atleast 10 significant digits
y = vpa(y, 10)
y = 

Torsten
Torsten 2023 年 12 月 11 日
移動済み: Torsten 2023 年 12 月 11 日
Unfortunately, the numbers are treated symbolically and a/b doesn't simplify
The numbers are not treated symbolically, but as long as x is symbolic, the complete expression is symbolic.
"double" can only be applied to expressions in which all symbolic variables have been substituted by numerical values.

カテゴリ

Help Center および File ExchangeNumbers and Precision についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by