フィルターのクリア

Substituting a value to a syms function in a matrix?

3 ビュー (過去 30 日間)
S Priya
S Priya 2022 年 2 月 20 日
回答済み: Walter Roberson 2022 年 2 月 20 日
I have a 4x4 matrix
A=
[E11e, 0, 0, 0]
[ 0, E11e, 0, 0]
[ 0, 0, E11e, 0]
[ 0, 0, 0, 0.5*E11e]
where Elle is a symbolic function....(syms E11e)
And I need to substitute the value of Elle as 4.3287e+08.
How should I do it?

採用された回答

VBBV
VBBV 2022 年 2 月 20 日
編集済み: VBBV 2022 年 2 月 20 日
A = subs(A,E11e,4.3287e+08)

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 2 月 20 日
compare:
syms E11e(t)
A1 = [
E11e, 0, 0, 0
0, E11e, 0, 0
0, 0, E11e, 0
0, 0, 0, str2sym('0.5')*E11e ]
A1(t) = 
syms E11e
A2 = [
E11e, 0, 0, 0
0, E11e, 0, 0
0, 0, E11e, 0
0, 0, 0, str2sym('0.5')*E11e ]
A2 = 
Notice that the output for the symbolic function case always includes the names of the symbolic function parameters. As you do not show that in your symbol is a symbolic variable rather than a symbolic function.
The replacement method is the same either way:
B1 = subs(A1, E11e, str2sym('4.3287e+08'))
B1(t) = 
B2 = subs(A2, E11e, str2sym('4.3287e+08'))
B2 = 
It would be more common to,
subs(A2, E11e, 4.3287e+08)
ans = 
This has a slightly different meaning than using str2sym() would have: when you use the numeric constant then by default the constant is converted to a rational value (or rational combined with a square root or π); when you use str2sym() like I used there, then a software floating-point number is used.

カテゴリ

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