Solving 7x7 Matrix Returns Very Long Fractions
조회 수: 5 (최근 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
댓글 수: 0
채택된 답변
Walter Roberson
2016년 10월 12일
Use vpa() or double() on the answer
댓글 수: 4
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개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Special Values에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!