how insert values of constants after using "solve" command

hello lets say i have this code :
syms x y c
X=[x ;y]
A=[3 -9; c 4]
B=[-42 ;2 ]
eqn=B==A*X
S=solve(eqn, x,y)
x=S.x
y=S.y
and I get answer of x and y , then lets say that I want C=3 and insert it to to x and get numerical answer , how do I make it happen ?

 採用された回答

Birdman
Birdman 2017 年 10 月 31 日

0 投票

x=subs(x,3)

4 件のコメント

tomer polsky
tomer polsky 2017 年 10 月 31 日
ok first of all thank your for your fast answer I really appriciat it ,second if i have more the one constant how can I know what concstat to switch ?
Birdman
Birdman 2017 年 10 月 31 日
For instance , think about 5 variable:
eq=subs(eq,{a,b,c,d,e},{1,2,3,4,5});
You first write the equation name in which you are going to do some modifications. Then second argument will be the symbolic variables which are going to be substituted, you should write them as I did. Third argument contains the numerical values of those symbolic variables.
Note that I wrote them respectively. For instance a will be replaced by 1, b by 2 and so on.
Walter Roberson
Walter Roberson 2017 年 10 月 31 日
Using the cell arrays as cvklpstunc shows is the more robust way, needed when vectors or arrays are being substituted for variables. But in the case of scalars, you can also use, for example,
eq = subs(eq, [a, b, c, d, e], [1, 2, 3, 4, 5])
with [] instead of {}. There are times when this is easier to use
tomer polsky
tomer polsky 2017 年 10 月 31 日
ok thank you for your help

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

その他の回答 (0 件)

質問済み:

2017 年 10 月 31 日

コメント済み:

2017 年 10 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by