Matlab Outputting answers as fractions

66 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Star Strider
Star Strider il 10 Dic 2019
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 Commenti
Michael Finch
Michael Finch il 12 Dic 2019
Thank you this worked perfectly :)
Star Strider
Star Strider il 12 Dic 2019
As always, my pleasure!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by