Xlambda
Well-known Member
- Joined
- Mar 8, 2021
- Messages
- 860
- Office Version
- 365
- Platform
- Windows
ALINEARSYS solves any system of linear equations. Thought to put some of text manipulation formulas to work for a higher purpose. ?
calls : AFLATTEN , ASPLIT , ATRIM , AREPLACE , AREMOVE , T_CHARS
calls : AFLATTEN , ASPLIT , ATRIM , AREPLACE , AREMOVE , T_CHARS
Excel Formula:
=LAMBDA(ec,
LET(d,"|",r,ROWS(ec),ae,SWITCH(LEFT(ec,1),"+","","-","","+")&ec,es,ASPLIT(ae,"="),e,INDEX(es,,1),n,INDEX(es,,2),ea,ASPLIT(ATRIM(AREPLACE(e,{"+";"-"},{"|+";"|-"}),d,),d),c,COLUMNS(ea),
f,AFLATTEN(ea),l,LEN(f),fr,AREMOVE(f,T_CHARS(,-1,),d),rf,SEARCH(d,fr),fs,IF(ISERR(rf),IF(l=0,fr,fr&d),fr),sf,SEARCH(d,fs),ce,MID(f,1,sf-1),
cf,IFERROR(--SWITCH(ce,"-",-1,"+",1,ce),0),v,IFERROR(MID(f,sf,l-sf+1),""),uv,SORT(UNIQUE(FILTER(v,v<>""))),tv,TRANSPOSE(uv),
q,QUOTIENT(SEQUENCE(r*c)-1,c)+1,x,XMATCH(v,tv),s,(q-1)*r+x,m,IFNA(XLOOKUP(SEQUENCE(r,r),s,cf),0),mi,MINVERSE(m),rs,MMULT(mi,n),
cx,OR(AREMOVE(LOWER(ec),T_CHARS(1,-1,"+-.="),"")<>""),ca,r<>ROWS(uv),cb,AND(ISNUMBER(n)),cc,AND(ISERR(mi)),
IFS(cx,"check syntax",ca,"check variables",NOT(cb),"only nrs after =",cc,"no solutions",TRUE,CHOOSE({1,2},uv&" =",rs))
)
)
LAMBDA 7.0.xlsx | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | |||
1 | sample | =ALINEARSYS(A2:A12) | =ALINEARSYS(H2:H5) | =ALINEARSYS(M2:M5) | |||||||||||||||||
2 | x1+x2+x3+x4+x5+x6+x7+x8+x9+x10+x11=100 | x1 = | 9.901271973 | -b-c+d=-4 | a = | 2.82352941 | x=2 | a = | -3 | ||||||||||||
3 | -2x3+4x6-2x11=12 | x10 = | 10.78741129 | b+c+a+d=10 | b = | 2.52941176 | -a=3 | b = | 1 | ||||||||||||
4 | 4x2-3x11+2x9-4x5=6 | x11 = | -34.00819959 | c-2d+2a-b=3 | c = | 3.05882353 | b=1 | c = | -4 | ||||||||||||
5 | -2x10+2x1+0.7x4+x8=12 | x2 = | -15.81144776 | -2c+2d+3a-b=3 | d = | 1.58823529 | -c=4 | x = | 2 | ||||||||||||
6 | x5-2x7+x2=9 | x3 = | -19.90090621 | sum check | 10 | ||||||||||||||||
7 | x5+2x3-x9+3x7-2x6=15 | x4 = | -20.11349492 | ||||||||||||||||||
8 | 2x8-x10-2x1+x4=5 | x5 = | 55.44094879 | =ALINEARSYS(H9:H12) | =ALINEARSYS(M9:M11) | ||||||||||||||||
9 | 1.5x7-2x2+3x4-1.2x6=23 | x6 = | -23.9545529 | 2ax3-2ax2+ax1=10 | ax1 = | 84.9473684 | 2x11-x22+2x33=-3 | x11 = | 2 | ||||||||||||
10 | x8-2x3+x10-x5=23 | x7 = | 15.31475052 | -ax4+.5ax2=-2 | ax2 = | -17.789474 | x11+x22-x33=6 | x22 = | 1 | ||||||||||||
11 | -x9+2x10+x1-2x11=5 | x8 = | 27.85172508 | .33ax3+.25ax1=3 | ax3 = | -55.263158 | x11+2x22-4x33=16 | x33 = | -3 | ||||||||||||
12 | x3-x4+x10=11 | x9 = | 94.49249372 | ax1+ax3+ax4+ax2=5 | ax4 = | -6.8947368 | |||||||||||||||
13 | sum check | 5 | |||||||||||||||||||
14 | =SUM(F2:F12) | ||||||||||||||||||||
15 | check | 100 | |||||||||||||||||||
16 | =ALINEARSYS(J17:J18) | =ALINEARSYS(O17:O18) | |||||||||||||||||||
17 | Syntax rules: | No variables after "=" sign | a-2*b=3 | check syntax | a-2b=3 | a = | 7 | ||||||||||||||
18 | If ecuation starts with + or - use " ' " as first char. '-2x+…. | a+b=9 | a+b=9 | b = | 2 | ||||||||||||||||
19 | 0.5 instead of 1/2 | (* char) | |||||||||||||||||||
20 | |||||||||||||||||||||
21 | =ALINEARSYS(B22:B24) | =ALINEARSYS(F22:F24) | =ALINEARSYS(J22:J23) | =ALINEARSYS(M22:M23) | |||||||||||||||||
22 | Error debug. | x+y-z=5 | no solutions | x+y-z=5 | no solutions | x+y=2x | only nrs after = | x+y+z=3 | check variables | ||||||||||||
23 | y-5z=8 | y-5z=8 | x-y=1 | x-y=1 | |||||||||||||||||
24 | y-5z=-1 | 2x+2y-2z=10 | (=2x) | (3 variables,only 2 ec) | |||||||||||||||||
25 | (2nd and 3rd ec inconsistent) | (1st and 3rd, same ecuation, infinite solutions) | |||||||||||||||||||
26 | |||||||||||||||||||||
ALINEARSYS post |
Cell Formulas | ||
---|---|---|
Range | Formula | |
E1,O21,G21,K21,C21,P16,K16,F14,O8,J8,O1,J1 | E1 | =FORMULATEXT(E2) |
E2:F12 | E2 | =ALINEARSYS(A2:A12) |
J2:K5,J9:K12,O2:P5 | J2 | =ALINEARSYS(H2:H5) |
K6,K13 | K6 | =SUM(K2:K5) |
O9:P11 | O9 | =ALINEARSYS(M9:M11) |
F15 | F15 | =SUM(F2:F12) |
K17,K22,P17:Q18 | K17 | =ALINEARSYS(J17:J18) |
C22,G22 | C22 | =ALINEARSYS(B22:B24) |
O22 | O22 | =ALINEARSYS(M22:M23) |
Dynamic array formulas. |
Upvote
0