Matlab Outputting answers as fractions

조회 수: 193 (최근 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 CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by