Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
fsolve using only integer values...

Subject: fsolve using only integer values...

From: Joakim Riml

Date: 17 Nov, 2008 14:46:41

Message: 1 of 5

Hi!

I have a problem regarding fsolve. I want to solve an equation system with two input parameters and I have used fsolve succesfully. Now i want to restrict one of the parameters to have integer values only. Is that possible??

Regards Joakim

Subject: fsolve using only integer values...

From: Walter Roberson

Date: 18 Nov, 2008 03:50:01

Message: 2 of 5

Joakim Riml wrote:
 
> I have a problem regarding fsolve. I want to solve an equation system with two input
> parameters and I have used fsolve succesfully. Now i want to restrict one of the
> parameters to have integer values only. Is that possible??

No. fsolve can only work with continuous functions. If you have a parameter
which is integer valued, the function cannot possibly be continuous in that
parameter (not unless the parameter is used trivially, such as multiplying it
by 0.)

--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: fsolve using only integer values...

From: Joakim Riml

Date: 18 Nov, 2008 07:50:22

Message: 3 of 5

Hi again!

Thank you for your answer, I get your point. Let me rephrase: Is there some method to optimize 2 equations with 2 unknown parameters and be able to restict the solution in a way that one of the parameters have to be an integer? The other can be a float number.

I'm constructing a compartment model, and the number of compartments (one of the unknown parameters) does need to be of integer since I want to use it in a loop afterwards.....

Thanks

Joakim

Walter Roberson <roberson@hushmail.com> wrote in message <sXqUk.8379$ev2.5411@newsfe12.iad>...
> Joakim Riml wrote:
>
> > I have a problem regarding fsolve. I want to solve an equation system with two input
> > parameters and I have used fsolve succesfully. Now i want to restrict one of the
> > parameters to have integer values only. Is that possible??
>
> No. fsolve can only work with continuous functions. If you have a parameter
> which is integer valued, the function cannot possibly be continuous in that
> parameter (not unless the parameter is used trivially, such as multiplying it
> by 0.)
>
> --
> .signature note: I am now avoiding replying to unclear or ambiguous postings.
> Please review questions before posting them. Be specific. Use examples of what you mean,
> of what you don't mean. Specify boundary conditions, and data classes and value
> relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: fsolve using only integer values...

From: Per Sundqvist

Date: 18 Nov, 2008 08:36:03

Message: 4 of 5

"Joakim Riml" <rimpa23@hotmail.com> wrote in message <gfts3u$b83$1@fred.mathworks.com>...
> Hi again!
>
> Thank you for your answer, I get your point. Let me rephrase: Is there some method to optimize 2 equations with 2 unknown parameters and be able to restict the solution in a way that one of the parameters have to be an integer? The other can be a float number.
>
> I'm constructing a compartment model, and the number of compartments (one of the unknown parameters) does need to be of integer since I want to use it in a loop afterwards.....
>
> Thanks
>
> Joakim
>
> Walter Roberson <roberson@hushmail.com> wrote in message <sXqUk.8379$ev2.5411@newsfe12.iad>...
> > Joakim Riml wrote:
> >
> > > I have a problem regarding fsolve. I want to solve an equation system with two input
> > > parameters and I have used fsolve succesfully. Now i want to restrict one of the
> > > parameters to have integer values only. Is that possible??
> >
> > No. fsolve can only work with continuous functions. If you have a parameter
> > which is integer valued, the function cannot possibly be continuous in that
> > parameter (not unless the parameter is used trivially, such as multiplying it
> > by 0.)
> >
> > --
> > .signature note: I am now avoiding replying to unclear or ambiguous postings.
> > Please review questions before posting them. Be specific. Use examples of what you mean,
> > of what you don't mean. Specify boundary conditions, and data classes and value
> > relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

First. Is it a minimization problem from the beginning? i.e., you take the derivative of that function w.r.t the two parameters=0. It is not good if one of them is an integer!

For minimization use: [c1,Fmin]=fminsearch(fun(c1,[c2]),...,[c2])
and repeat minimization w.r.t the continuous parameter, keeping the integer parameter c2 fixed (help fminsearch). Then compare different Fmin for different values of integer c2.

/Per

Subject: fsolve using only integer values...

From: Martin B?nner

Date: 18 Nov, 2008 10:02:02

Message: 5 of 5


Hello Joakim,

in general fsolve implements a solver algorithm for the class of continuous nonlinear optimization problems. That means all variables need to be real numbers in order to apply fsolve.

In your problem, one variable is an integer. That means your class of problem falls into the set of so-called "(non)-linear mixed-integer problems". These are 1.) in most cases much more difficult to solve. In other cases 2.), depending of the nature of the problem, it can be easy. Key is to distinguish between the two.

So, what can you do with your problem in practice?

Here, are my answers:
For 1. You could use a mixed-integer solver. To my knowledge, Matlab does not have one integrated. Therefore, you can study the literature around mixed-integer optimization, and implement one for yourself.
For 2. THIS IS MAYBE/HOPEFULLY THE EASY ROAD FOR YOU: There are several way to define "easy" subclasses inside the mixed-integer problem. Here is one for you, hope it helps:
In the case your integer variable is restricted to a "small" set of numbers by the nature of your problem, it will be easy. For instance, if your problem allows only fives values {-2, -1, 0, +1, +2}. Then, you transfer the single mixed-integer problem for N variables into five conventional problems with (N-1) variables by fixing the integer to the allowed values. You solve the 5 conventional problems with fsolve, which gives you 5 values, Then you make a simple search of the minimum of these values.
Obviously, this can be handled best by writing a short Matlab script. What "small" means depends on the size of your problem and your time and computing power. For small problems, it can be that it is feasible for even 100.000 possible integer values.

Hope that helps,
Best greetings from Munich, Germany.
Martin



"Joakim Riml" <rimpa23@hotmail.com> wrote in message <gfs04h$o0s$1@fred.mathworks.com>...
> Hi!
>
> I have a problem regarding fsolve. I want to solve an equation system with two input parameters and I have used fsolve succesfully. Now i want to restrict one of the parameters to have integer values only. Is that possible??
>
> Regards Joakim

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us