Solving 7x7 Matrix Returns Very Long Fractions

5 visualizzazioni (ultimi 30 giorni)
Hello, I'm solving a 7x7 matrix. After inputting the A matrix and B vector and solving, the returned solutions for X are very, very long fractions. How can I specify that I would like these returned in rounded numbers (in scientific notation, for example), not in fractions? Code is below, and thank you.
Cx = 6 + 0.0806;
Cy = 6.8359;
syms w1 w2 w3 w4 w5 w6 w7;
eqn1 = + ((Cx)*w1) - (4*w2) + (1*w3) + (0*w4) + (0*w5) + (0*w6) - (4*w7) == (Cy)*(2*.125);
eqn2 = - (4*w1) + ((Cx)*w2) - (4*w3) + (1*w4) + (0*w5) + (0*w6) + (0*w7) == (Cy)*sin(2*pi*.250);
eqn3 = + (1*w1) - (4*w2) + ((Cx)*w3) - (4*w4) + (1*w5) + (0*w6) + (0*w7) == (Cy)*sin(2*pi*.375);
eqn4 = + (0*w1) + (1*w2) - (4*w3) + ((Cx)*w4) - (4*w5) + (1*w6) + (0*w7) == (Cy)*sin(2*pi*.500);
eqn5 = + (0*w1) + (0*w2) + (1*w3) - (4*w4) + ((Cx)*w5) - (4*w6) + (1*w7) == (Cy)*sin(2*pi*.625);
eqn6 = + (0*w1) + (0*w2) + (0*w3) + (1*w4) - (4*w5) + ((Cx)*w6) - (4*w7) == (Cy)*sin(2*pi*.750);
eqn7 = - (4*w1) + (0*w2) + (0*w3) + (0*w4) + (1*w5) - (4*w6) + ((Cx)*w7) == (Cy)*sin(2*pi*.875);
[A,B] = equationsToMatrix([eqn1, eqn2, eqn3, eqn4, eqn5, eqn6, eqn7], [w1, w2, w3, w4, w5, w6, w7]);
X = linsolve(A,B)
This returns the following (only w1 solution showing due to length):
X = 2182838934989084222859735148265186349320750668882016039009/735711874176482141060943596914818753670316261979795226624

Risposta accettata

Walter Roberson
Walter Roberson il 12 Ott 2016
Use vpa() or double() on the answer
  4 Commenti
balsip
balsip il 13 Ott 2016
Modificato: balsip il 13 Ott 2016
That was entirely unintended. It seems like the symbolic variables are the default output of the linsolve() function.
Steven Lord
Steven Lord il 13 Ott 2016
Only when you pass symbolic variables into linsolve.
A = gallery('minij', 7);
b = sum(A, 2);
xd = linsolve(A, b); % double
xs = linsolve(sym(A), b); % sym
whos xd xs

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by