Solving 7x7 Matrix Returns Very Long Fractions

8 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2016-10-12
Use vpa() or double() on the answer
  4 个评论
balsip
balsip 2016-10-13
编辑:balsip 2016-10-13
That was entirely unintended. It seems like the symbolic variables are the default output of the linsolve() function.
Steven Lord
Steven Lord 2016-10-13
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

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by