1

In a system of simultaneous equations, Matlab [version R2016a] finds a solution – but fails to find this (still valid) solution when I add an additional (and for the solution irrelevant) equation to the system.

This is (a simpler version of) my code:

syms g p l h1 h2 h3

% set assumptions
g=0;
assume(0<p<1);
assume(0<l<1);
assume(0<h1<1);
assume(0<h2<1);
assume(0<h3<1);
assumeAlso(h2<h1); 
assumeAlso(h3<h2);

% equations
H1 = g^2+2*g*p*l*p/(1-g*l)+p^2*l^2;
H2 = g^2*(H1)+2*g*p^2*l^3 + 2*g^2*p^2*l^2/(1-g*l) + p^2*l^4;
H3 = g^2*(H2)+2*g*p^2*l^5 + 2*g^2*p^2*l^4 + 2*g^3*p^2*l^3/(1 - g*l) + p^2*l^6;

Now, using only the first two equations yields a solution for both parameters

solve([H1-h1,H2-h2],[l,p])

solution = 

    l: [1x1 sym]
    p: [1x1 sym]

ans = h2^(1/2)/h1^(1/2)   ans = h1/h2^(1/2)

But "offering" all three equations to Matlab, I do not find a solution. Anyone an idea why this might be? I am not very experienced with Matlab, so I might miss something fundamental here.

solution=solve([H1-h1,H2-h2,H3-h3],[l,p])  

solution = 

    l: [0x1 sym]
    p: [0x1 sym]
Jan Madrid
  • 11
  • 1
  • 1
    Perhaps there is no solution? Not all equations can be solved, especially with all that assumptions – Ander Biguri Feb 12 '18 at 10:08
  • Thanks Anders. I guess something like this must be going on – Matlab may not show the solution to the first two equations because it might not be sure if the solution is compatible with the third equation. But it fails to find a solution even if I make no assumptions on the variable h3 – in which case the third equation can always be satisfied. – Jan Madrid Feb 12 '18 at 10:21
  • Note that MATLAB is smart. It is not that "it might not be sure", its that it is 100% sure that its not compatible. Even if you remove the conditions, MATLAB does not find a solution, meaning those equations are not compatible, there is no solution that matches all 3 equations – Ander Biguri Feb 12 '18 at 10:23
  • Anders, l=h2^(1/2)/h1^(1/2) and p=h1/h2^(1/2) solves the first two equations, and setting h3=H3 solves the third equation. So the system has a solution – as Matlab figures out when offered only the first two equations. – Jan Madrid Feb 12 '18 at 10:38
  • After trying a little more, Matlab does find the solution if I ask Matlab to explicitly solve also for h3, i.e. if I change the last line to solution=solve([H1-h1,H2-h2,H3-h3],[l,p,h3]). That does not really answer my question though – why does Matlab not find the solution when asked to solve only for p and l? – Jan Madrid Feb 12 '18 at 10:42
  • You can too do `subs(H3,[l,p],solution.l,solution.p)` after solving the first 2 equation and you get `h2^2/h1=h3`. But perhaps this solution is not possible with your constrains. Also, `H3=h3` is not the solution.... Is the equation defined by you. While I can not figure it out, my best guess is that `h2^2/h1=h3` is not possible with the conditions you have (note the solution for `solve([H1-h1,H2-h2],[l,p])` is only valid for `h1^2 < h2`). – Ander Biguri Feb 12 '18 at 11:16
  • No, you are right. `[h1,h2]=[0.9,0.82]` gives valid solutions for all conditions – Ander Biguri Feb 12 '18 at 11:28
  • Thanks Ander, your comments were very useful. I realize that the problem relates to a confusion what the endogenous and exogenous variables of the system are. Essentially, I want to solve the system for the exogenous variables, which makes it a little more tricky on how to input the system into Matlab. Clearly, the h2^2/h1=h3 relation you mentioned is the missing piece in the example above, but I am still struggling to extend this insight into more general models. – Jan Madrid Feb 12 '18 at 21:24

0 Answers0