[Date Index]
[Thread Index]
[Author Index]
Re: FindFit with conditionals
*To*: mathgroup at smc.vnet.net
*Subject*: [mg57366] Re: [mg57307] FindFit with conditionals
*From*: Andrzej Kozlowski <andrzej at akikoz.net>
*Date*: Wed, 25 May 2005 06:03:19 -0400 (EDT)
*References*: <200505240912.FAA19168@smc.vnet.net> <B8AB71D2-44E9-434B-BB5D-BACFA4B5579C@akikoz.net> <20050524181807.GA23723@venus>
*Sender*: owner-wri-mathgroup at wolfram.com
On 25 May 2005, at 03:18, Edward Peschko wrote:
> On Tue, May 24, 2005 at 09:24:38PM +0900, Andrzej Kozlowski wrote:
>
>> First , FindInstance does not hold its arguments (look at Attributes
>> [FindInstance]) so of course it tries to evaluate NIntegrate[...] and
>> you get he message complaining that the integrand is not numerical.
>> Secondly, FindInstance uses similar methods to Reduce, which means it
>> is esentially an "algebraic" function which uses exact methods. You
>> can use it with non-exact inputs but I believe it will still use
>> exact methods to find the answer, and it will not, I think,
>> internaly perform any non-exact computations of the kind that you are
>> trying to use. (Of course it will evaluate "non-exact" functions
>> suplied as argumetns and it may use some "exact numerical methods"
>> but still the main point is, I think, valid, and that it that like
>> Reduce, it attempts to give exact answers and is not suitable for
>> solving numerical (approximate) questions.
>>
>
> Fair enough -
>
> but that still leaves me with the question - what's the best way to
> do this then?
>
> IMO there should be (IMO) an easy way to say:
>
>
> <built-in-function> [ f[x_,y_,z_], {x,y,z}, Integers ]
>
> where
> <built-in-function>
>
> is a mathematica function,
>
> f[x_,y_,z_...]
>
> is an expression or series of chained expressions, and
>
> {x,y,z}
>
> is a list of arguments to pass to function, and which vary from
> evaluation
> to evaluation via global optimization tools, and
>
> Integers
>
> which is the domain over which {x,y,z} can vary.
>
>
> I'm agnostic on the algorithm being deterministic, algebraic, or
> approximative,
> but IMO this would be a very expressive way of solving problems
> that otherwise
> would be very messy.
>
> Just my 2 cents.
>
Many functions that use exact methods, such as Integrate, Limit,
Reduce already accept Assumptions and/or domains, although you should
realize that there are rather few general algorithms for dealing
with problems over the integers.
For non-exact inputs, like your original problem, the thing to do is
to use NMinimize or NMaximize.
Let me quickly illustrate how to do this for a trivial problem; you
can try to adapt this method to your original one.
Suppose for example we need to find an integer a such that
NIntegrate[x^3, {x, -1, a}] == 3.75
(the answer is a==-2 or a ==2 ).
We have to formulate this as an optimization problem. For this
purpose we define a function
f[a_?NumericQ] := Abs[NIntegrate[x^3, {x, -1, a}] - 3.75]
Note the use of pattern a_?NumericQ in the definition of NIntegrate,
it is meant to prevent NIntegrate trying to evaluate before it
receives a numerical value for a form NMinimize, since NMinimize does
not hold its arguments. Now we try to solve an optimization problem:
In[20]:=
NMinimize[{f[a], a â?? Integers}, {a}]
Out[20]=
{4.440892098500626*^-16, {a -> -2}}
If we wan tot find the posiitve solution we can impose an additional
constraint:
NMinimize[{f[a], a â?? Integers && a > Plus[0]}, {a}]
{1.3322676295501878*^-15, {a -> 2}}
I think this is the best you can hope for for the kind of problems
you seem to have in mind.
Andrzej Kozlowski
Prev by Date:
**Re: Re: plot hyperbola (OT)**
Next by Date:
**Re: Re: Mapping Data**
Previous by thread:
**Re: FindFit with conditionals**
Next by thread:
** Re: manipulating powers**
| |