fsolve for system of equations with partially known solution

3 views (last 30 days)
I have the following system of equations:
F(1)=sign(x(1))*(sign(x(2))+sign(x(3)))-x(1);
F(2)=sign(x(2))*(sign(x(1))+sign(x(4)))-x(2);
F(3)=sign(x(3))*(sign(x(1))+sign(x(4)))-x(3);
F(4)=sign(x(4))*(sign(x(2))+sign(x(3)))-x(4);
I am using fsolve to find F(x)=0. This system has obviously a lot of possible solutions (e.g. x=[0 0 0 0] or x=[2 2 2 2] or x=[1 2 0 1].
Is there a way to add additional constraints with fsolve? For example, I only want solutions that satisfy x(1)=0, i.e. I already know parts of the solution. Another example would be: Give a possible solution that satisfies both, x(1)=0 and x(3)=0. As I want to solve the system for many different constraints, I do not want to have to change the initial system of equations. Is there a simple way to do that with fsolve?
Thank you!
------------------------------------------------------------
Thank you Matt for your very helpful answer and comment. I already successfully implemented an iterative solver for the stated problem. The issue is that the actual problem has up to 81 equations rather than 4. And as soon as the number of equations reaches ~30, the computation time is too high. That's why I am looking for a direct solution of the problem.
Considering the problem I posted with, e.g. x(1)=1 and x(3)=0 it is very easy to manually analytically find the solutions. The first equation for this case states that sign(x(2))=1, so x2>0. The 4th equation states that x(4)=sign(x(4)), so x(4) must be either 0, -1 or 1. Together one can easily find that 2 solultions exist for this case, namely: x=[1 1 0 0] and x=[1 2 0 1]. So if it is so easy to solve with a pen and paper I thought there must be a simple way to do this with MATLAB...
I already tried to solve this Problem with solve, vpasolve and fsolve, but nothing seems to work yet. As the equations are not differentiable at all fsolve gives wrong Solutions. Thank's for that, Matt.
Another thing: Solutions are only allowed to be positive integers.
  1 Comment
Matt J
Matt J on 7 Sep 2015
Edited: Matt J on 7 Sep 2015
This system has obviously a lot of possible solutions
There are fewer than 625 possible solutions. The number 625 is accounted for by rearranging your equations in the form
x(i) = sign(x(i))*(sign(x(j))+sign(x(k)))
The right hand side (and therefore also each x(i) ) can only take on one of 5 integer values ranging from -2 to 2.
For a problem this size, you could just loop overall 625 combinations and test which ones are admissible as solutions. No need for fsolve or any other iterative solver at all.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 7 Sep 2015
Edited: Matt J on 7 Sep 2015
Even without constraints, FSOLVE is not applicable to the the system of equations that you've shown. FSOLVE is designed for twice differentiable F(x), which your system is not.
As for constraining the equations, you can always do so by wrapping it in an anonymous function
function myfunc(z, indices,fixedvals)
%embed z in x
I=1:4;
x(indices)=fixedvals;
x(setdiff(I,indices))=z;
F(1)=...; %Expressions involving x
F(2)=...;
F(3)=...;
F(4)=...;
end
and now do things like
fixedIndices=[1,3];
fixedValues=[0,0]
fun=@(z) myfunc(z,fixedIndices,fixedValues); %constrain x1=x3=0
z=fsolve(fun,rand(2,1),...);
For larger problems, this kind of embedding has drawbacks, which are discussed in this recent similar thread,

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!