Solution for variables in an overridden system

I am trying to write a Matlab program that accepts variables for a system from a user, but there are more variables than system parameters. In particular, six variables in three equations:

w - d - M = 0
l - d - T = 0
N - T + M = 0

It can be represented in matrix form as A*x=0, where

A = [1  0  0 -1  0 -1;
     0  1  0 -1 -1  0;
     0  0  1  0 -1  1];

x = [w  l  N  d  T  M]';

I would like to be able to solve this system, given the well-known subset of variables. For example, if the user gives d, T, M, then the system is trivially solved for the other three variables. If the user supplies w, N, Mthen it becomes soluble 3-DOF-system. Etc. (If the user overrides or undetermines the system, then, of course, an error may occur.)

() . , , ( ).

, , , ; - ?

+3
3

-, x - NaN . ISNAN, . A*x , b. , A*x = -b.

A = [1  0  0 -1  0 -1;
     0  1  0 -1 -1  0;
     0  0  1  0 -1  1];

idx = ~isnan(x); 
b = A(:,idx)*x(idx); % user provided constants
z = A(:,~idx)\(-b); % solution of Ax = -b
x(~idx) = z;

x = [NaN NaN NaN 1 1 1]', , [2 2 0 1 1 1]'. MLDIVIDE, , , PINV - .

+4

A = [1  0  0 -1  0 -1;
     0  1  0 -1 -1  0;
     0  0  1  0 -1  1];

A*x = 0

x :

x = [w  l  N  d  T  M]';

, {d, T, M} . x. 4-, 5- 6- , .

known_idx = [4 5 6];
unknown_idx = setdiff(1:6,known_idx);

.

xknown = [1; -3; 7.5];

, .

Aknown = A(:,known_idx);
Aunknown = A(:,unknown_idx);

. , Aknown 3x3, () .

xunknown = Aunknown\(-Aknown*xknown)
xunknown =
         -8.5
            2
         10.5

.

x = zeros(6,1);
x(known_idx) = xknown;
x(unknown_idx) = xunknown;
x =
         -8.5
            2
         10.5
            1
           -3
          7.5

, , , . , .

, , , , {l, d, T}, . . Aunknown . pinv .

+3

? , , , :

(w, d, M)
(l, d, T)
(N, T, M)

, , :

User input: w, N, M
Given variables:
(w, d, M) -> 2
(l, d, T) -> 0
(N, T, M) -> 1 

d . , , , .

.

0

Source: https://habr.com/ru/post/1723846/


All Articles