Given matrix $K_{n \times n}, H_{n \times n},M_{n \times n}$, I want to solve for $B_{n \times n} $ and $V_{n \times 1}$ from the nonlinear system of equations: \begin{aligned} &H_{i j}=\frac{B_{i j} \frac{K_{i j}}{V_{i}}}{\sum_{i ^{\prime} =1}^{n} \sum_{j ^{\prime} =1}^{n} B_{i^{\prime} j^{\prime}} \frac{K_{i^{\prime} j^{\prime}}}{V_{i^{\prime}}}}\\ &M_{i j}=\frac{B_{i j} K_{i j}}{\sum_{j^{\prime}=1}^{n} B_{i j^{\prime}} K_{i j^{\prime}}} \end{aligned}

I am trying the following code, but it fails.

n = 200;
H = magic(n);
M = magic(n);
K = magic(n);

opts = optimoptions(@fsolve,'Algorithm', 'levenberg-marquardt');

fun = @(X)system_fun(X,H,M,K,n);
X0 = ([ones(n,n),ones(n,1)]);


function F=system_fun(X,H,M,K) 

B =X(:,1:N); 

V = X(:,N+1); 

Aux1 = B.*K./V;

Aux2 = sum(sum(Aux1,2));

Aux3 = Aux1./Aux2;

Aux11 = B.*K;

Aux22 = sum(sum(Aux1,2));

Aux33 = Aux11./Aux22;

     H- Aux3;
     M - Aux33;

  • 2
    $\begingroup$ I don't see any question or system of equations in your post. $\endgroup$
    – nicoguaro
    Jan 3 '20 at 1:32
  • 1
    $\begingroup$ @nicoguaro It's a nonlinear system of equations where all the $B_{ij}$ and $V_{i}$ are unknowns but $K_{ij}$, $H_{ij}$, and $M_{ij}$ are known here. $\endgroup$ Jan 3 '20 at 16:21
  • 1
    $\begingroup$ Perhaps you could provide the output from running fsolve. Exactly what manner of failure occurred? Leaving aside whether you may have an implementation error and the adequacy of your starting point, X0, do you realize that fsolve attempts to find a solution to the system of equations, and will report success only if it does so within prescribed tolerance? Are you sure your system actually has a solution? If you "solve" by nonlinear least squares, that will handle cases in which "exact" solution exists, as well as those where it doesn't (but gets as close as it can in least squares sense). $\endgroup$ Jan 3 '20 at 16:37
  • 2
    $\begingroup$ @MarkL.Stone My guess is that it doesn't have a solution at least in its current form, cause based on OP's description, there are $n^{2}+n$ unknowns ($n^{2}$ $B_{ij}$ + $n$ $V_{i}$) but OP provided $n^{2} + n^{2}$ equations, which there are $n^{2} - n$ more equations than what is actually needed here. $\endgroup$ Jan 3 '20 at 17:54

As mentioned in a comment by @AloneProgrammer, it's unlikely that your system has a solution. But to make any kind of progress, it's also useful to rewrite the system in a way that makes its structure simpler. To this end, notice that in the first equation, you always have terms of the form $A_{ij}=B_{ij}/V_i$. So the first of the two equations might be easier to understand if you wrote it in the form $$ A_{ij} = \frac{H_{ij}}{K_{ij}} K:A, $$ which makes it clear that the equation really is linear in $A$. Similarly, the second equation is of the form $$ B_{ij} = \frac{M_{ij}}{K_{ij}} \sum_{j'} K_{ij'}B_{ij'}. $$

For matrix $B$, consider them as vector of vertical vectors defined as: $B = [b_{0}, b_{1},...,b_{n}]$, where $b_{i}$ is a vertical vector defined as: $b_{i} = [B_{i0},B_{i1},...,B_{in}]^{T}$, where $B_{ij}$ are scalars. Similarly for matrices $K$, $M$, $A$, and $H$ consider them in a similar fashion as vector of vertical vectors defined as: $K = [k_{0},k_{1},...,k_{n}]$, $M = [m_{0},m_{1},...,m_{n}]$, $A = [a_{0},a_{1},...,a_{n}]$, and $H = [h_{0},h_{1},...,h_{n}]$. So the above equation could be rewritten as:

$$B_{ij} = \frac{M_{ij}}{K_{ij}} k_{i} \cdot b_{i}$$

or by using Hadamard division:

$$b_{i} = (m_{i} \oslash k_{i}) k_{i} \cdot b_{i}$$

Also first equation could be rewritten as:

$$a_{i} = (h_{i} \oslash k_{i}) \sum_{\alpha} k_{\alpha} \cdot a_{\alpha}$$

Both of these equations are of the form "linear operator applied to A" equals "1 times A" (and similarly for B), and so what you have is in reality an eigenvalue (or here, "eigenmatrix") problem.

So the solvability of your problem depends on the following conditions:

  • The operator on the right hand side of the first equation ($L_{1} = (h_{i} \oslash k_{i}) \sum_{\alpha} k_{\alpha} \cdot$) above has an eigenvalue equal to 1
  • The operator on the right hand side of the second equation ($L_{2} = (m_{i} \oslash k_{i}) k_{i} \cdot$) above has an eigenvalue equal to 1
  • Among the eigenvectors $A$ that correspond to the eigenvalue 1 and the eigenvectors $B$ that correspond to the eigenvalue 1, there are such vectors so that $V = b_{i} \oslash a_{i}$ or in another word all the members $a_{i}$ vectors should be non-zero.

Whether or not the problem has a solution therefore clearly depends on particular properties of the matrices $H,K,M$.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.