Matlab Outputting answers as fractions

195 ビュー (過去 30 日間)
Michael Finch
Michael Finch 2019 年 12 月 10 日
コメント済み: Star Strider 2019 年 12 月 12 日
Hi so i'm trying to find 4 variables from 4 linear equations which it does however the answers output are all huge fractions for some reason anyone know how to change this? Code attached for context.
clear; clc;
format shortG
syms C1 C2 C3 C4
eqn1= 0.3598*C1 - 0.6445*C2 - 0.6388*C3 + 0.2170*C4 == 0;
eqn2= -0.6155*C1 + 0.3427*C2 - 0.5333*C3 + 0.4683*C4 == 40;
eqn3= 0.5942*C1 + 0.3962*C2 + 0.1659*C3 + 0.6800*C4 == 0;
eqn4= -0.3724*C1 - 0.5570*C2 + 0.5291*C3 +0.5208*C4 == 0;
[A,B] = equationsToMatrix([eqn1, eqn2, eqn3, eqn4], [C1, C2, C3, C4]);
X=linsolve(A,B)
X =
-123100469289600000/5000172844664399
68542380776800000/5000172844664399
-106674157217600000/5000172844664399
93657426868400000/5000172844664399

採用された回答

Star Strider
Star Strider 2019 年 12 月 10 日
You are still in the Symbolic Math Toolbox environment.
Try one of these (depending on the rresult you want):
X = vpa(linsolve(A,B))
X = double(linsolve(A,B))
The vpa call keeps the results symbolic, the double call makes the results numeric.
  2 件のコメント
Michael Finch
Michael Finch 2019 年 12 月 12 日
Thank you this worked perfectly :)
Star Strider
Star Strider 2019 年 12 月 12 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by