numeric::linsolve

Solve a system of linear equations

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

numeric::linsolve(eqs, <vars>, options)

Description

numeric::linsolve(eqs, vars) solves a system of linear equations eqs for the unknowns vars.

numeric::linsolve is a fast numerical linear solver. It is also a recommended solver for linear systems with exact or symbolic coefficients (using Symbolic).

Expressions are interpreted as homogeneous equations. E.g., the input [x = y - 1, x - y] is interpreted as the system of equations [x = y - 1, x - y = 0].

    Note:   Without the option Symbolic, the input data are converted to floating-point numbers. The coefficient matrix A of the system Ax = b represented by eqs must not contain non-convertible parameters, unless the option Symbolic is used! If such objects are found, then numeric::linsolve automatically switches to its symbolic mode, issuing a warning. This warning may be suppressed via NoWarning. Symbolic parameters in the "right hand side" b are accepted without warning.

The numerical working precision is set by the environment variable DIGITS.

The solutions are returned as a list of solved equations of the form

,

where x1, x2, … are the unknowns. These simplified equations should be regarded as constraints on the unknowns. E.g., if an unknown x1, say, does not turn up in the form [x1 = …, …] in the solution, then there is no constraint on this unknown; it is an arbitrary parameter. Generally, all unknowns that do not turn up on the left hand side of the solved equations are arbitrary parameters spanning the solution space. Cf. Example 9.

In particular, if the empty list is returned as the solution, there are no constraints whatsoever on the unknowns, i.e., the system is trivial.

The ordering of the solved equations corresponds to the ordering of the unknowns vars. It is recommended that the user specifies vars by a a list of unknowns. This guarantees that the solved equations are returned in the expected order. If vars are specified by a set, or if no vars are specified at all, then an internal ordering is used.

If no unknowns are specified by vars, numeric::linsolve solves for all symbolic objects in eqs. The unknowns are determined internally by indets(eqs, PolyExpr).

numeric::linsolve returns the general solution of the system eqs. It is valid for arbitrary complex values of the symbolic parameters which may be present in eqs. If no such solution exists, FAIL is returned. Solutions that are valid only for special values of the symbolic parameters may be obtained with the option ShowAssumptions. See Example 2, Example 3, Example 4, and Example 11.

The solved equations representing the solution are suitable as input for assign and subs. See Example 8.

numeric::linsolve is suitable for solving large sparse systems. See Example 6.

If eqs represents a system with a banded coefficient matrix, then this is detected and used by numeric::linsolve. Note that in this case, it is important to specify both the equations as well as the unknowns by lists to guarantee the desired form of the coefficient matrix. When using sets, the data may be reordered internally leading to a loss of band structure and, consequently, of efficiency. See Example 6.

    Note:   numeric::linsolve is tuned for speed. For this reason, it does not check systematically that the equations eqs are indeed linear in the unknowns! For non-linear equations, strange things may happen; numeric::linsolve might even return wrong results! See Example 5.

    Note:   numeric::linsolve does not react to any properties of the unknowns or of symbolic parameters that are set via assume.

    Note:   Gaussian elimination with partial pivoting is used. Without the option Symbolic, floating-point arithmetic is used and the pivoting strategy takes care of numerical stabilization. With Symbolic, exact data are assumed and the pivoting strategy tries do maximize speed, not taking care of numerical stabilization! See Example 7.

Environment Interactions

Without the option Symbolic, the function is sensitive to the environment variable DIGITS, which determines the numerical working precision.

Examples

Example 1

Equations and variables may be entered as sets or lists:

numeric::linsolve({x = y - 1, x + y = z}, {x, y});
numeric::linsolve([x = y - 1, x + y = z], {x, y});
numeric::linsolve({x = y - 1, x + y = z}, [x, y]);
numeric::linsolve([x = y - 1, x + y = z], [x, y])

With the option Symbolic, exact arithmetic is used. The following system has a 1-parameter set of solution; the unknown x3 is arbitrary:

numeric::linsolve([x[1] + x[2] = 2, x[1] - x[2] = 2*x[3]],
                  [x[1], x[2], x[3]], Symbolic)

The unknowns may be expressions:

numeric::linsolve([f(0) - sin(x + 1) = 2, f(0) = 1 - sin(x + 1)],
                  [f(0), sin(x + 1)])

The following system does not have a solution:

numeric::linsolve([x + y = 1, x + y = 2], [x, y])

Example 2

We demonstrate some examples with symbolic coefficients. Note that the option Symbolic has to be used:

eqs := [x + a*y = b, x + A*y = b]:
numeric::linsolve(eqs, [x, y], Symbolic)

Note that for a = A, this is not the general solution. Using the option ShowAssumptions, it turns out that the above result is the general solution subject to the assumption aA:

numeric::linsolve(eqs, [x, y], Symbolic, ShowAssumptions)

delete eqs:

Example 3

We give a further demonstration of the option ShowAssumptions. The following system does not have a solution for all values of the parameter a:

numeric::linsolve([x + y = 1, x + y = a], [x, y], Symbolic)

With ShowAssumptions, numeric::linsolve investigates under which conditions (on the parameter a) there is a solution:

numeric::linsolve([x + y = 1, x + y = a], [x, y], Symbolic,
                  ShowAssumptions)

We conclude that there is a 1-parameter set of solutions for a = 1. The constraint in a is a linear equation, since the parameter a enters the equations linearly. If a is regarded as an unknown rather than as a parameter, the constraint becomes part of the solution:

numeric::linsolve([x + y = 1, x + y = a], [x, y, a], Symbolic,
                  ShowAssumptions)

Example 4

With exact arithmetic, PI is regarded as a symbolic parameter. The following system has a solution subject to the constraint PI = 1:

numeric::linsolve([x = x - y + 1, y = PI], [x, y],
                  Symbolic, ShowAssumptions)

With floating-point arithmetic, PI is converted to 3.1415.... The system has no solution:

numeric::linsolve([x = x - y + 1, y = PI], [x, y], 
                  ShowAssumptions)

Example 5

Since numeric::linsolve does not do a systematic internal check for non-linearities, the user should make sure that the equations to be solved are indeed linear in the unknowns. Otherwise, strange things may happen. Garbage is produced for the following non-linear systems:

a := sin(x):
numeric::linsolve([y = 1 - a, x = y], [x, y], Symbolic)

numeric::linsolve([a*x + y = 1, x = y], [x, y], Symbolic)

Polynomial non-linearities are usually detected. Regarding x, y, c as unknowns, the following quadratic system yields an error:

numeric::linsolve([x*c + y = 1, x = y], Symbolic)
Error: This system does not seem to be linear. [numeric::linsolve]
 Error:
This system does not seem to be linear. [numeric::linsolve] 

This system is linear in x, y if c is regarded as a parameter:

numeric::linsolve([x*c + y = 1, x = y], [x, y], Symbolic)

delete a:

Example 6

We solve a large sparse system. The coefficient matrix has only 3 diagonal bands. Note that both the equations as well as the variables are passed as lists. This guarantees that the band structure is not lost internally:

n := 500: x[0] := 0: x[n + 1] := 0:
eqs := [x[i-1] - 2*x[i] + x[i+1] = 1 $ i = 1..n]:
vars := [x[i] $ i = 1..n]:
numeric::linsolve(eqs, vars)

[x[1] = -250.0, x[2] = -499.0, x[3] = -747.0, x[4] = -994.0, x[5] = -1240.0, x[6] = -1485.0, x[7] = -1729.0, x[8] = -1972.0, x[9] = -2214.0, x[10] = -2455.0, x[11] = -2695.0, x[12] = -2934.0, x[13] = -3172.0, x[14] = -3409.0, x[15] = -3645.0, x[16] = -3880.0, x[17] = -4114.0, x[18] = -4347.0, x[19] = -4579.0, x[20] = -4810.0, x[21] = -5040.0, x[22] = -5269.0, x[23] = -5497.0, x[24] = -5724.0, x[25] = -5950.0, x[26] = -6175.0, x[27] = -6399.0, x[28] = -6622.0, x[29] = -6844.0, x[30] = -7065.0, x[31] = -7285.0, x[32] = -7504.0, x[33] = -7722.0, x[34] = -7939.0, x[35] = -8155.0, x[36] = -8370.0, x[37] = -8584.0, x[38] = -8797.0, x[39] = -9009.0, x[40] = -9220.0, x[41] = -9430.0, x[42] = -9639.0, x[43] = -9847.0, x[44] = -10054.0, x[45] = -10260.0, x[46] = -10465.0, x[47] = -10669.0, x[48] = -10872.0, x[49] = -11074.0, x[50] = -11275.0, x[51] = -11475.0, x[52] = -11674.0, x[53] = -11872.0, x[54] = -12069.0, x[55] = -12265.0, x[56] = -12460.0, x[57] = -12654.0, x[58] = -12847.0, x[59] = -13039.0, x[60] = -13230.0, x[61] = -13420.0, x[62] = -13609.0, x[63] = -13797.0, x[64] = -13984.0, x[65] = -14170.0, x[66] = -14355.0, x[67] = -14539.0, x[68] = -14722.0, x[69] = -14904.0, x[70] = -15085.0, x[71] = -15265.0, x[72] = -15444.0, x[73] = -15622.0, x[74] = -15799.0, x[75] = -15975.0, x[76] = -16150.0, x[77] = -16324.0, x[78] = -16497.0, x[79] = -16669.0, x[80] = -16840.0, x[81] = -17010.0, x[82] = -17179.0, x[83] = -17347.0, x[84] = -17514.0, x[85] = -17680.0, x[86] = -17845.0, x[87] = -18009.0, x[88] = -18172.0, x[89] = -18334.0, x[90] = -18495.0, x[91] = -18655.0, x[92] = -18814.0, x[93] = -18972.0, x[94] = -19129.0, x[95] = -19285.0, x[96] = -19440.0, x[97] = -19594.0, x[98] = -19747.0, x[99] = -19899.0, x[100] = -20050.0, x[101] = -20200.0, x[102] = -20349.0, x[103] = -20497.0, x[104] = -20644.0, x[105] = -20790.0, x[106] = -20935.0, x[107] = -21079.0, x[108] = -21222.0, x[109] = -21364.0, x[110] = -21505.0, x[111] = -21645.0, x[112] = -21784.0, x[113] = -21922.0, x[114] = -22059.0, x[115] = -22195.0, x[116] = -22330.0, x[117] = -22464.0, x[118] = -22597.0, x[119] = -22729.0, x[120] = -22860.0, x[121] = -22990.0, x[122] = -23119.0, x[123] = -23247.0, x[124] = -23374.0, x[125] = -23500.0, x[126] = -23625.0, x[127] = -23749.0, x[128] = -23872.0, x[129] = -23994.0, x[130] = -24115.0, x[131] = -24235.0, x[132] = -24354.0, x[133] = -24472.0, x[134] = -24589.0, x[135] = -24705.0, x[136] = -24820.0, x[137] = -24934.0, x[138] = -25047.0, x[139] = -25159.0, x[140] = -25270.0, x[141] = -25380.0, x[142] = -25489.0, x[143] = -25597.0, x[144] = -25704.0, x[145] = -25810.0, x[146] = -25915.0, x[147] = -26019.0, x[148] = -26122.0, x[149] = -26224.0, x[150] = -26325.0, x[151] = -26425.0, x[152] = -26524.0, x[153] = -26622.0, x[154] = -26719.0, x[155] = -26815.0, x[156] = -26910.0, x[157] = -27004.0, x[158] = -27097.0, x[159] = -27189.0, x[160] = -27280.0, x[161] = -27370.0, x[162] = -27459.0, x[163] = -27547.0, x[164] = -27634.0, x[165] = -27720.0, x[166] = -27805.0, x[167] = -27889.0, x[168] = -27972.0, x[169] = -28054.0, x[170] = -28135.0, x[171] = -28215.0, x[172] = -28294.0, x[173] = -28372.0, x[174] = -28449.0, x[175] = -28525.0, x[176] = -28600.0, x[177] = -28674.0, x[178] = -28747.0, x[179] = -28819.0, x[180] = -28890.0, x[181] = -28960.0, x[182] = -29029.0, x[183] = -29097.0, x[184] = -29164.0, x[185] = -29230.0, x[186] = -29295.0, x[187] = -29359.0, x[188] = -29422.0, x[189] = -29484.0, x[190] = -29545.0, x[191] = -29605.0, x[192] = -29664.0, x[193] = -29722.0, x[194] = -29779.0, x[195] = -29835.0, x[196] = -29890.0, x[197] = -29944.0, x[198] = -29997.0, x[199] = -30049.0, x[200] = -30100.0, x[201] = -30150.0, x[202] = -30199.0, x[203] = -30247.0, x[204] = -30294.0, x[205] = -30340.0, x[206] = -30385.0, x[207] = -30429.0, x[208] = -30472.0, x[209] = -30514.0, x[210] = -30555.0, x[211] = -30595.0, x[212] = -30634.0, x[213] = -30672.0, x[214] = -30709.0, x[215] = -30745.0, x[216] = -30780.0, x[217] = -30814.0, x[218] = -30847.0, x[219] = -30879.0, x[220] = -30910.0, x[221] = -30940.0, x[222] = -30969.0, x[223] = -30997.0, x[224] = -31024.0, x[225] = -31050.0, x[226] = -31075.0, x[227] = -31099.0, x[228] = -31122.0, x[229] = -31144.0, x[230] = -31165.0, x[231] = -31185.0, x[232] = -31204.0, x[233] = -31222.0, x[234] = -31239.0, x[235] = -31255.0, x[236] = -31270.0, x[237] = -31284.0, x[238] = -31297.0, x[239] = -31309.0, x[240] = -31320.0, x[241] = -31330.0, x[242] = -31339.0, x[243] = -31347.0, x[244] = -31354.0, x[245] = -31360.0, x[246] = -31365.0, x[247] = -31369.0, x[248] = -31372.0, x[249] = -31374.0, x[250] = -31375.0, x[251] = -31375.0, x[252] = -31374.0, x[253] = -31372.0, x[254] = -31369.0, x[255] = -31365.0, x[256] = -31360.0, x[257] = -31354.0, x[258] = -31347.0, x[259] = -31339.0, x[260] = -31330.0, x[261] = -31320.0, x[262] = -31309.0, x[263] = -31297.0, x[264] = -31284.0, x[265] = -31270.0, x[266] = -31255.0, x[267] = -31239.0, x[268] = -31222.0, x[269] = -31204.0, x[270] = -31185.0, x[271] = -31165.0, x[272] = -31144.0, x[273] = -31122.0, x[274] = -31099.0, x[275] = -31075.0, x[276] = -31050.0, x[277] = -31024.0, x[278] = -30997.0, x[279] = -30969.0, x[280] = -30940.0, x[281] = -30910.0, x[282] = -30879.0, x[283] = -30847.0, x[284] = -30814.0, x[285] = -30780.0, x[286] = -30745.0, x[287] = -30709.0, x[288] = -30672.0, x[289] = -30634.0, x[290] = -30595.0, x[291] = -30555.0, x[292] = -30514.0, x[293] = -30472.0, x[294] = -30429.0, x[295] = -30385.0, x[296] = -30340.0, x[297] = -30294.0, x[298] = -30247.0, x[299] = -30199.0, x[300] = -30150.0, x[301] = -30100.0, x[302] = -30049.0, x[303] = -29997.0, x[304] = -29944.0, x[305] = -29890.0, x[306] = -29835.0, x[307] = -29779.0, x[308] = -29722.0, x[309] = -29664.0, x[310] = -29605.0, x[311] = -29545.0, x[312] = -29484.0, x[313] = -29422.0, x[314] = -29359.0, x[315] = -29295.0, x[316] = -29230.0, x[317] = -29164.0, x[318] = -29097.0, x[319] = -29029.0, x[320] = -28960.0, x[321] = -28890.0, x[322] = -28819.0, x[323] = -28747.0, x[324] = -28674.0, x[325] = -28600.0, x[326] = -28525.0, x[327] = -28449.0, x[328] = -28372.0, x[329] = -28294.0, x[330] = -28215.0, x[331] = -28135.0, x[332] = -28054.0, x[333] = -27972.0, x[334] = -27889.0, x[335] = -27805.0, x[336] = -27720.0, x[337] = -27634.0, x[338] = -27547.0, x[339] = -27459.0, x[340] = -27370.0, x[341] = -27280.0, x[342] = -27189.0, x[343] = -27097.0, x[344] = -27004.0, x[345] = -26910.0, x[346] = -26815.0, x[347] = -26719.0, x[348] = -26622.0, x[349] = -26524.0, x[350] = -26425.0, x[351] = -26325.0, x[352] = -26224.0, x[353] = -26122.0, x[354] = -26019.0, x[355] = -25915.0, x[356] = -25810.0, x[357] = -25704.0, x[358] = -25597.0, x[359] = -25489.0, x[360] = -25380.0, x[361] = -25270.0, x[362] = -25159.0, x[363] = -25047.0, x[364] = -24934.0, x[365] = -24820.0, x[366] = -24705.0, x[367] = -24589.0, x[368] = -24472.0, x[369] = -24354.0, x[370] = -24235.0, x[371] = -24115.0, x[372] = -23994.0, x[373] = -23872.0, x[374] = -23749.0, x[375] = -23625.0, x[376] = -23500.0, x[377] = -23374.0, x[378] = -23247.0, x[379] = -23119.0, x[380] = -22990.0, x[381] = -22860.0, x[382] = -22729.0, x[383] = -22597.0, x[384] = -22464.0, x[385] = -22330.0, x[386] = -22195.0, x[387] = -22059.0, x[388] = -21922.0, x[389] = -21784.0, x[390] = -21645.0, x[391] = -21505.0, x[392] = -21364.0, x[393] = -21222.0, x[394] = -21079.0, x[395] = -20935.0, x[396] = -20790.0, x[397] = -20644.0, x[398] = -20497.0, x[399] = -20349.0, x[400] = -20200.0, x[401] = -20050.0, x[402] = -19899.0, x[403] = -19747.0, x[404] = -19594.0, x[405] = -19440.0, x[406] = -19285.0, x[407] = -19129.0, x[408] = -18972.0, x[409] = -18814.0, x[410] = -18655.0, x[411] = -18495.0, x[412] = -18334.0, x[413] = -18172.0, x[414] = -18009.0, x[415] = -17845.0, x[416] = -17680.0, x[417] = -17514.0, x[418] = -17347.0, x[419] = -17179.0, x[420] = -17010.0, x[421] = -16840.0, x[422] = -16669.0, x[423] = -16497.0, x[424] = -16324.0, x[425] = -16150.0, x[426] = -15975.0, x[427] = -15799.0, x[428] = -15622.0, x[429] = -15444.0, x[430] = -15265.0, x[431] = -15085.0, x[432] = -14904.0, x[433] = -14722.0, x[434] = -14539.0, x[435] = -14355.0, x[436] = -14170.0, x[437] = -13984.0, x[438] = -13797.0, x[439] = -13609.0, x[440] = -13420.0, x[441] = -13230.0, x[442] = -13039.0, x[443] = -12847.0, x[444] = -12654.0, x[445] = -12460.0, x[446] = -12265.0, x[447] = -12069.0, x[448] = -11872.0, x[449] = -11674.0, x[450] = -11475.0, x[451] = -11275.0, x[452] = -11074.0, x[453] = -10872.0, x[454] = -10669.0, x[455] = -10465.0, x[456] = -10260.0, x[457] = -10054.0, x[458] = -9847.0, x[459] = -9639.0, x[460] = -9430.0, x[461] = -9220.0, x[462] = -9009.0, x[463] = -8797.0, x[464] = -8584.0, x[465] = -8370.0, x[466] = -8155.0, x[467] = -7939.0, x[468] = -7722.0, x[469] = -7504.0, x[470] = -7285.0, x[471] = -7065.0, x[472] = -6844.0, x[473] = -6622.0, x[474] = -6399.0, x[475] = -6175.0, x[476] = -5950.0, x[477] = -5724.0, x[478] = -5497.0, x[479] = -5269.0, x[480] = -5040.0, x[481] = -4810.0, x[482] = -4579.0, x[483] = -4347.0, x[484] = -4114.0, x[485] = -3880.0, x[486] = -3645.0, x[487] = -3409.0, x[488] = -3172.0, x[489] = -2934.0, x[490] = -2695.0, x[491] = -2455.0, x[492] = -2214.0, x[493] = -1972.0, x[494] = -1729.0, x[495] = -1485.0, x[496] = -1240.0, x[497] = -994.0, x[498] = -747.0, x[499] = -499.0, x[500] = -250.0]

The band structure is lost if the equations or the unknowns are specified by sets. The following call takes more time than the previous call:

numeric::linsolve({op(eqs)}, {x[i] $ i = 1..n})

delete n, x, eqs, vars:

Example 7

The option Symbolic should not be used for equations with floating-point coefficients, because the symbolic pivoting strategy favors efficiency instead of numerical stability.

eqs := [x + 10^20*y = 10^20, x + y = 0]:

The float approximation of the exact solution is:

map(numeric::linsolve(eqs, [x, y], Symbolic), map, float)

We now convert the exact coefficients to floating-point numbers:

feqs := map(eqs, map, float)

The default pivoting strategy stabilizes floating-point operations. Consequently, one gets a correct result:

numeric::linsolve(feqs, [x, y])

With Symbolic, the pivoting strategy optimizes speed, assuming exact arithmetic. Numerical instabilities may occur if floating-point coefficients are involved. The following incorrect result is caused by internal round-off effects ("cancellation"):

numeric::linsolve(feqs, [x, y], Symbolic)

delete eqs, feqs:

Example 8

We demonstrate that the simplified equations representing the solution can be used for further processing with subs:

eqs := [x + y = 1, x + y = a]:
[Solution, Constraints, Pivots] := 
  numeric::linsolve(eqs, [x, y], ShowAssumptions)

subs(eqs, Solution)

The solution can be assigned to the unknowns via assign:

assign(Solution):
x, y, eqs

delete eqs, Solution, Constraints, Pivots, x:

Example 9

If the solution of the linear system is not unique, then some of the unknowns are used as "free parameters" spanning the solution space. In the following example, the unknowns z, w are such parameters. They do not turn up on the left hand side of the solved equations:

eqs := [x + y = z, x + 2*y = 0, 2*x - z = -3*y, y + z = 0]:
vars := [x, y, z, w]:
Solution := numeric::linsolve(eqs, vars, Symbolic)

You may define a function such as the following NewSolutionList to rename your free parameters to "myName1", "myName2" etc. and fill up your list of solved equations accordingly:

NewSolutionList := 
proc(Solution : DOM_LIST, vars : DOM_LIST, myName : DOM_STRING)
local i, solvedVars, newEquation;
begin
  solvedVars := map(Solution, op, 1);
  for i from 1 to nops(vars) do
     if not has(solvedVars, vars[i]) then
        newEquation := vars[i] = genident(myName);
        Solution := listlib::insertAt(
            subs(Solution, newEquation), newEquation, i) 
     end_if 
  end_for:
  Solution
end_proc:
NewSolutionList(Solution, vars, "FreeParameter")

delete eqs, vars, Solution, NewSolutionList:

Example 10

We demonstrate the difference between hardware and software arithmetic. The following problem is very ill-conditioned. The results, both with HardwareFloats as well as with SoftwareFloats, are marred by numerical round-off:

n:= 10:
eqs:= [(_plus(x[j]/(i + j -1) $ j = 1..n) = 1) $ i = 1..n]:
vars:= [x[i] $ i = 1..n]:
numeric::linsolve(eqs, vars, SoftwareFloats);
numeric::linsolve(eqs, vars, HardwareFloats)

This is the exact solution:

numeric::linsolve(eqs, vars, Symbolic);

delete eqs, vars:

Example 11

We demonstrate how a complete solution of the following linear system in x, y with symbolic parameters a, b, c, d may be found:

eqs := [x + y = d, a*x + b*y = 1, x + c*y = 1]:
numeric::linsolve(eqs, [x, y], Symbolic, ShowAssumptions)

This is the general solution, assuming ab. We now set b = a to investigate further solution branches:

eqs := subs(eqs, b = a):
numeric::linsolve(eqs, [x, y], Symbolic, ShowAssumptions)

This is the general solution for a = b, assuming c ≠ 1. We finally set c = 1 to obtain the last solution branch:

eqs := subs(eqs, c = 1):
numeric::linsolve(eqs, [x, y], Symbolic, ShowAssumptions)

From the constraints on the symbolic parameters a and d, we conclude that there is a special 1-parameter solution x = 1 - y for a = b = c = d = 1.

delete eqs:

Parameters

eqs

A list, set, array, or matrix (Cat::Matrix) of linear equations or arithmetical expressions

vars

A list or set of unknowns to solve for. Unknowns may be identifiers or indexed identifiers or arithmetical expressions.

Options

Hard, HardwareFloats, Soft, SoftwareFloats

With Hard (or HardwareFloats), computations are done using fast hardware float arithmetic from within a MuPAD® session. Hard and HardwareFloats are equivalent. With this option, the input data are converted to hardware floats and processed by compiled C code. The result is reconverted to MuPAD floats and returned to the MuPAD session.

With Soft (or SoftwareFloats) computations are dome using software float arithmetic provided by the MuPAD kernel. Soft and SoftwareFloats are equivalent. SoftwareFloats is used by default if the current value of DIGITS is larger than 15 and the input matrix A is not of domain type DOM_HFARRAY.

Compared to the SoftwareFloats used by the MuPAD kernel, the computation with HardwareFloats may be many times faster. Note, however, that the precision of hardware arithmetic is limited to about 15 digits. Further, the size of floating-point numbers may not be larger than approximately 10308 and not smaller than approximately 10- 308.

If no HardwareFloats or SoftwareFloats are requested explicitly, the following strategy is used: If the current value of DIGITS is smaller than 16 or if the matrix A is a hardware float array of domain type DOM_HFARRAY, then hardware arithmetic is tried. If this is successful, the result is returned.

If the result cannot be computed with hardware floats, software arithmetic by the MuPAD kernel is tried.

If the current value of DIGITS is larger than 15 and the input matrix A is not of domain type DOM_HFARRAY, or if one of the options Soft, SoftwareFloats or Symbolic is specified, MuPAD computes the result with its software arithmetic without trying to use hardware floats first.

There may be several reasons for hardware arithmetic to fail:

  • The current value of DIGITS is larger than 15.

  • The data contains symbolic objects.

  • The data contains numbers larger than 10308 or smaller than 10- 308 that cannot be represented by hardware floats.

If neither HardwareFloats nor SoftwareFloats is specified, the user is not informed whether hardware floats or software floats are used.

If HardwareFloats are specified but fail due to one of the reasons above, a warning is issued that the (much slower) software floating-point arithmetic of the MuPAD kernel is used.

Note that HardwareFloats can only be used if all input data can be converted to floating-point numbers.

The trailing digits in floating-point results computed with HardwareFloats and SoftwareFloats may differ.

    Note:   For ill-conditioned systems, the result is subject to round-off errors. The results returned with HardwareFloats and SoftwareFloats may differ significantly! SeeExample 10.

Symbolic

Prevents conversion of input data to floating-point numbers. This option overrides HardwareFloats and SoftwareFloats.

This option must be used if the coefficients of the equations contain symbolic parameters that cannot be converted to floating-point numbers.

    Note:   This option should not be used for equations with floating-point coefficients! Numerical instabilities may occur in floating-point operations. See Example 7.

ShowAssumptions

Returns information on internal assumptions on symbolic parameters in eqs.

This option is only useful if the equations contain symbolic parameters. Consequently, it should only be used in conjunction with the option Symbolic.

    Note:   The format of the return value is changed to [Solution, Constraints, Pivots].

Solution is a set of simplified equations representing the general solution subject to Constraints and Pivots.

Constraints is a list of equations for symbolic parameters in eqs, which are necessary and sufficient to make the system solvable.

Such constraints arise if Gaussian elimination of the original equations leads to equations of the form 0 = c, where c is some expression involving symbolic parameters in the "right hand side" of the system. All such equations are collected in Constraints. numeric::linsolve assumes that these equations are satisfied and returns a solution.

If no such constraints arise, the return value of Constraints is the empty list.

Pivots is a list of inequalities involving symbolic parameters in the coefficient matrix A of the linear system Ax = b represented by eqs. Internally, division by pivot elements occurs in the Gaussian elimination. The expressions collected in Pivots are the numerators of the pivot elements that contain symbolic parameters. If only numerical pivot elements were used, the return value of Pivots is the empty list.

    Note:   The option ShowAssumptions changes the return strategy for "unsolvable" systems. Without the option Symbolic, FAIL is returned whenever Gaussian elimination produces an equation 0 = c with non-zero c. With ShowAssumptions, such equations are returned via Constraints, provided c involves symbolic parameters.

    If c is a purely numerical value, then [FAIL, [], []] is returned.

See  Example 2, Example 3, Example 4, and Example 11.

NoWarning

Suppresses warnings

If symbolic coefficients are found, numeric::linsolve automatically switches to the Symbolic mode with a warning. With this option, this warning is suppressed; numeric::linsolve still uses the symbolic mode for symbolic coefficients, i.e., exact arithmetic without floating-point conversions is used.

Return Values

Without the option ShowAssumptions, a list of simplified equations is returned. It represents the general solution of the system eqs. FAIL is returned if the system is not solvable.

With ShowAssumptions, a list [Solution, Constraints, Pivots] is returned. Solution is a list of simplified equations representing the general solution of eqs. The lists Constraints and Pivots contain equations and inequalities involving symbolic parameters in eqs. Internally, these were assumed to hold true when solving the system.

[FAIL, [], []] is returned if the system is not solvable.

Was this topic helpful?