Message Boards Message Boards

0
|
2916 Views
|
3 Replies
|
3 Total Likes
View groups...
Share
Share this post:

[?] Get a clean matrix using this code?

Posted 6 years ago

i got a question about wolfram mathematica i want to make this 22 equations given to me and transform them into a 22x22 matrix.

this is my code.

equation1 = -318.1 x1 - 309.9 x2 + 993.1 x3 + 395.3 x4 - 599.2 x5 -
419.4 x6 + 676. x7 + 650.9 x8 + 512.9 x9 + 114.3 x10 - 491.7 x11 -
402.1 x12 + 111.4 x13 + 182.4 x14 - 593.9 x15 - 814.3 x16 +
91.7 x17 + 248.3 x18 - 421.3 x19 + 199.1 x20 - 711.4 x21 -
752.7 x22 == 249.7

equation2 = -281.9 x1 - 568.7 x2 + 206.9 x3 - 303.1 x4 + 674.3 x5 -
226.5 x6 + 507.4 x7 + 196.9 x8 + 764.6 x9 - 214.5 x10 -
587.5 x11 - 105.8 x12 - 869.8 x13 - 110.2 x14 + 431.9 x15 -
299.8 x16 + 979.4 x17 - 881.1 x18 - 16.6 x19 - 221.8 x20 -
33.5 x21 + 134.7 x22 == 637.8

equation3 = -577. x1 - 268.5 x2 - 692.2 x3 + 462.6 x4 + 81.4 x5 -
303.1 x6 + 736.6 x7 + 780.9 x8 + 560.8 x9 + 627.6 x10 +
698.8 x11 - 81.6 x12 + 436.9 x13 + 591.3 x14 + 651.7 x15 -
203.9 x16 + 449.1 x17 - 13.5 x18 + 964.6 x19 - 134.3 x20 +
692.6 x21 + 751.5 x22 == -462.

equation4 = -633.2 x1 - 500.6 x2 - 890.7 x3 + 10.4 x4 - 588. x5 +
144.1 x6 - 664.9 x7 + 777.8 x8 + 372. x9 + 684.1 x10 + 804.9 x11 -
215. x12 + 333.5 x13 - 860.5 x14 - 45.2 x15 - 10.3 x16 -
794.8 x17 + 992.3 x18 - 67.2 x19 - 200.6 x20 + 169.7 x21 +
70.6 x22 == 136.8

equation5 = -495.8 x1 + 823.8 x2 + 118.7 x3 - 219. x4 - 764. x5 +
785.8 x6 - 708.5 x7 + 224.4 x8 + 380.5 x9 - 517.9 x10 -
590.5 x11 - 967.3 x12 - 759. x13 - 981.3 x14 - 185.6 x15 -
703. x16 + 462.2 x17 + 793.8 x18 + 501.2 x19 + 11.8 x20 +
218.1 x21 - 727.9 x22 == -598.3

equation6 =
952.6 x1 - 555.6 x2 + 78.9 x3 + 601.1 x4 + 215.8 x5 - 255.1 x6 -
648.4 x7 + 576.4 x8 - 374.7 x9 - 253.8 x10 - 964.9 x11 +
576.1 x12 - 175.2 x13 - 71.6 x14 + 792. x15 + 118.1 x16 +
680.2 x17 - 632.4 x18 + 520.4 x19 - 789.7 x20 + 461.7 x21 -
141.9 x22 == 3.2

equation7 =
-717.9 x1 - 333.2 x2 - 977.4 x3 - 270.4 x4 + 610.1 x5 - 736.9 x6 -
5.5 x7 + 955.7 x8 - 530.1 x9 + 416.5 x10 - 427.6 x11 - 424.8 x12 -
423.5 x13 - 670.7 x14 - 364.6 x15 - 422.1 x16 + 277.3 x17 +
118.1 x18 - 203.6 x19 - 793.4 x20 - 520.7 x21 + 828. x22 == 229.4

equation8 = -570.9 x1 - 209.9 x2 + 946.4 x3 + 906.4 x4 - 927.9 x5 +
779.3 x6 + 105.1 x7 + 438.7 x8 - 512. x9 - 788.2 x10 - 820.1 x11 -
951.3 x12 - 144.4 x13 - 219.8 x14 - 976. x15 + 955.4 x16 +
808.8 x17 + 375.8 x18 - 94.8 x19 + 111.2 x20 + 447.2 x21 -
102.6 x22 == 184.7

equation9 =765.3 x1 - 780.6 x2 - 695.2 x3 - 656.6 x4 + 35.1 x5 - 853.9 x6 +
62.6 x7 - 194.2 x8 - 928.4 x9 - 939.1 x10 + 963.2 x11 -
460.8 x12 - 185.4 x13 + 223.1 x14 - 310.2 x15 - 61.4 x16 -
150.7 x17 - 232. x18 - 4.3 x19 + 497.3 x20 - 60.7 x21 + 684.8 x22 ==
404.2

equation10 = -613.9 x1 + 606.2 x2 - 633.5 x3 + 578.5 x4 + 155.8 x5 +
397.8 x6 + 95.6 x7 - 327.6 x8 + 783.9 x9 - 677.1 x10 - 866.4 x11 +
839.8 x12 - 276.5 x13 + 457.1 x14 - 12.6 x15 + 765. x16 +
402.2 x17 - 539.8 x18 - 951.4 x19 + 741. x20 + 10.1 x21 -
21.3 x22 == 677.

equation11 = -974.4 x1 - 666.2 x2 + 706.6 x3 + 354.7 x4 - 416.6 x5 -
636.4 x6 - 443.9 x7 + 694.5 x8 + 450.9 x9 - 819.8 x10 -
891.7 x11 - 362.5 x12 + 874.9 x13 + 730.4 x14 + 516.2 x15 -
50.5 x16 + 559.3 x17 + 627.8 x18 + 8.9 x19 + 315.5 x20 +
70.5 x21 - 912.4 x22 == 617.1

equation12 = -908.1 x1 - 672. x2 + 731.1 x3 - 909.8 x4 - 413.6 x5 +
222.3 x6 + 272.4 x7 + 84.3 x8 + 137. x9 + 402.2 x10 + 812.6 x11 +
760.3 x12 + 785.5 x13 + 988.2 x14 + 31.1 x15 + 999. x16 -
544.8 x17 + 554.8 x18 + 647.5 x19 + 101.1 x20 - 969.4 x21 -
472.2 x22 == -106.5

equation13 =
395.5 x1 - 419.4 x2 - 278.8 x3 - 535.4 x4 + 211.9 x5 + 456.2 x6 -
637.8 x7 + 36.3 x8 - 542.7 x9 - 348.8 x10 + 113.8 x11 +
510.4 x12 - 701.2 x13 - 739.3 x14 + 192.8 x15 - 159.8 x16 +
452.8 x17 - 251.6 x18 + 945.3 x19 - 50.3 x20 + 339.5 x21 -
954.5 x22 == -459.5

equation14 = -233.4 x1 - 274.4 x2 + 784.3 x3 - 426.9 x4 + 441.4 x5 -
27. x6 - 552.6 x7 + 699.7 x8 + 869.7 x9 + 331.2 x10 - 646.9 x11 +
670.4 x12 + 993.3 x13 - 378.1 x14 - 648.3 x15 + 76. x16 -
364.8 x17 + 235.1 x18 - 337.3 x19 - 245.9 x20 - 21.4 x21 -
224.2 x22 == -448.5

equation15 =
608.8 x1 + 810.4 x2 + 943.2 x3 + 70.3 x4 + 113. x5 - 599. x6 -
726.2 x7 + 163.7 x8 - 303.6 x9 - 614.9 x10 + 459.5 x11 - 7.1 x12 +
131.3 x13 + 820.5 x14 + 556.5 x15 - 115.2 x16 - 404.8 x17 +
437.2 x18 - 34.1 x19 - 715.4 x20 - 187. x21 - 172. x22 == -222.6

equation16 =
601. x1 + 411.7 x2 - 606.8 x3 + 253.2 x4 - 463.5 x5 + 91.8 x6 +
294.6 x7 + 543.1 x8 - 466.2 x9 + 479.1 x10 + 428.4 x11 +
597.6 x12 - 631.5 x13 + 321.7 x14 - 868.7 x15 + 35.4 x16 +
727.9 x17 + 757.9 x18 + 300.3 x19 - 699.7 x20 + 381.2 x21 +
815.3 x22 == 38.4

equation17 =
463.2 x1 + 294. x2 - 28.1 x3 - 725.8 x4 - 735.1 x5 + 715.3 x6 -
80.1 x7 + 996.4 x8 - 814.8 x9 + 918.2 x10 + 703.6 x11 -
594.5 x12 - 892. x13 + 878.3 x14 + 373.9 x15 - 164.3 x16 -
598. x17 - 200.9 x18 - 527.9 x19 - 991.7 x20 + 762. x21 -
615.8 x22 == 986.9

equation18 =
753.2 x1 - 415.7 x2 - 327.8 x3 - 781.3 x4 - 391.6 x5 - 734.7 x6 +
473.1 x7 - 450.2 x8 + 343.4 x9 + 974.6 x10 + 92. x11 - 143.3 x12 +
272.2 x13 - 389.4 x14 + 189.6 x15 - 979.1 x16 + 196.3 x17 -
153.8 x18 + 913.7 x19 + 571.7 x20 - 420.1 x21 + 941.9 x22 == 189.5

equation19 =
84. x1 + 998.8 x2 + 96.7 x3 + 468.2 x4 - 711. x5 + 357.3 x6 -
501.4 x7 - 110.4 x8 - 478. x9 + 114.4 x10 + 69.3 x11 + 356.3 x12 +
9.5 x13 + 970.2 x14 + 425.5 x15 - 544.5 x16 - 844.8 x17 +
874.2 x18 - 102.2 x19 + 183.1 x20 + 588. x21 - 25.6 x22 == 936.1

equation20 = -675.2 x1 - 269.7 x2 - 829.9 x3 + 107.8 x4 - 908.1 x5 -
810.8 x6 - 664. x7 + 721.2 x8 - 173.7 x9 + 434.3 x10 + 518.8 x11 +
322.5 x12 + 719.3 x13 - 701.7 x14 + 29. x15 + 90.8 x16 -
47.7 x17 - 534.2 x18 + 419.6 x19 - 416.8 x20 + 303.3 x21 -
389.9 x22 == 378.8

equation21 = -351.7 x1 + 817.8 x2 - 373.1 x3 + 100.8 x4 - 605. x5 -
725.4 x6 - 162.2 x7 - 174.9 x8 - 191.2 x9 - 16. x10 - 796.3 x11 +
264.6 x12 + 839. x13 - 327.9 x14 + 130. x15 + 429.6 x16 +
108.2 x17 - 344.2 x18 + 374.3 x19 + 408.3 x20 - 268. x21 +
900.4 x22 == -444.8

equation22 =
345. x1 + 521.9 x2 + 746.8 x3 + 176.4 x4 + 960.2 x5 - 919.6 x6 -
311.7 x7 + 409.5 x8 - 809.9 x9 + 719.8 x10 - 55. x11 + 237.8 x12 -
168.2 x13 - 442.7 x14 - 677.7 x15 - 227.3 x16 - 296.4 x17 +
672.9 x18 + 574.1 x19 - 370.5 x20 + 413.9 x21 + 799. x22 == 352.

system = {equation1, equation2, equation3, equation4, equation5,
equation6, equation7, equation8, equation9, equation10, equation11,
equation11, equation12, equation13, equation14, equation15,
equation16, equation17, equation18, equation19, equation20,
equation21, equation22}
MatrixForm[system]

when i run the program i dont get a clean matrix format i dont know why, please can somebody help my with this.

POSTED BY: jose caballero
3 Replies

I guess I didn't notice system at the end of the original post. (Note equation11 is repeated in it. You can use Length@system as a check.) This is shorter:

CoefficientArrays[system, Variables[system /. Equal -> Subtract]]

It automatically figures out the variables, which okay if all the coefficients are numeric. However, the ordering might not be what you expect:

Variables[system /. Equal -> Subtract]
(*
     {x1, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x2, x20, x21, 
      x22, x3, x4, x5, x6, x7, x8, x9}
*)

So it might be worth constructing the variable list yourself.

POSTED BY: Michael Rogers

Try this:

CoefficientArrays[
 ToExpression@Table["equation" <> ToString@i, {i, 22}], 
 ToExpression@Table["x" <> ToString@i, {i, 22}]]
POSTED BY: Michael Rogers
Anonymous User
Anonymous User
Posted 6 years ago

Its worked!

POSTED BY: Anonymous User
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract