連立方程式の解につい​て、変数文字の係数を​分数でなく小数で表示​したい

17 views (last 30 days)
Daisuke
Daisuke on 6 Sep 2019
Commented: Daisuke on 9 Sep 2019
連立方程式を解く際に、解に含まれる文字の係数を実数で表示するようにしたいです。
以下は例です。
format compact
syms x1 y1 z1 z2
eqn1 = 1/10*x1+10/90*y1+z1 == 10
eqn2 = (2*x1+y1-4/9)/(20+5/2*z1) == -1
eqn3 = (2*x1+y1-5/6*z2)/20-(z1+x1*2) == 9.6
sol = solve([eqn1, eqn2,eqn3], [x1,y1,z1]);
x1Sol = sol.x1
y1Sol = sol.y1
z1Sol = sol.z1
計算結果は以下のようコマンドウィンドウに表示されます。
x1Sol =
- (65*z2)/3417 - 8132/603
y1Sol =
(105*z2)/2278 - 1944/67
z1Sol =
43936/3015 - (11*z2)/3417
この結果を以下のように表示する方法はありますか?
x1Sol =
- 0.0190*z2 - 13.4859
y1Sol =
0.0461*z2 - 29.0149
z1Sol =
14.5725 - 0.0032*z2

Accepted Answer

Yoshio
Yoshio on 7 Sep 2019
Edited: Yoshio on 7 Sep 2019
とりあえず
x1Soln = vpa(sol.x1,6)
y1Soln = vpa(sol.y1,6)
z1Soln = vpa(sol.z1,6)
とすると
x1Soln =
- 0.0190225*z2 - 13.4859
y1Soln =
0.0460931*z2 - 29.0149
z1Soln =
14.5725 - 0.0032192*z2
となります。ご希望の表示と少し異なりますが。
  1 Comment
Daisuke
Daisuke on 9 Sep 2019
vpa関数で解決しました。
回答ありがとうございました!

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!