Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to NSolve equation which involves NIntegrate?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg120085] Re: How to NSolve equation which involves NIntegrate?
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Fri, 8 Jul 2011 04:51:01 -0400 (EDT)
  • References: <201106250929.FAA20235@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

There are two solutions, by the way:

Clear[f, g, a]
f[a_] = Integrate[Sin[a x], {x, 0, 1}];
g[a_] = a*a;
Plot[{a^2, f[a]}, {a, -.1, .6}]

or

Clear[f, g]
f[a_?NumericQ] := NIntegrate[Sin[a x], {x, 0, 1}]
g[a_] := a*a
FindRoot[f[a] - g[a], {a, -.1}]
FindRoot[f[a] - g[a], {a, 1}]

{a -> 4.73799*10^-21}

{a -> 0.490073}

Bobby

On Thu, 07 Jul 2011 10:40:10 -0500, DrMajorBob <btreat1 at austin.rr.com>  
wrote:

> Clear[f, g]
> f[a_?NumericQ] := NIntegrate[Sin[a x], {x, 0, 1}]
> g[a_] := a*a
> FindRoot[f[a] - g[a], {a, 1}]
>
> {a -> 0.490073}
>
> a) NumericQ eliminates the error you mentioned,
>
> b) NSolve is limited to algebraic problems, and
>
> c) I had to come up with a starting point for the search.
>
> (a) and (b) are related, in that NSolve wanted to keep a symbolic in  
> solving the problem, but f[a] is undefined, when a is symbolic.
>
> Bobby
>
> On Thu, 07 Jul 2011 09:58:23 -0500, Ted Sariyski  
> <tsariysk at craft-tech.com> wrote:
>
>> I am sorry, I should made up an example. Here it is:
>>
>> f[a_] := NIntegrate[Sin[a x], {x, 0, 1}]
>> g[a_] := a*a
>> NSolve[f[a] == g[a], a]
>>
>> Out[]: NIntegrate::inumr: "The integrand Sin[a x] has evaluated to  
>> non-numerical values for all sampling points in the region with  
>> boundaries {{0,1}}."
>>
>> Thanks,
>> --Ted
>>
>> On 7/7/2011 10:26 AM, DrMajorBob wrote:
>>> You left out the definition of h, so how can we possibly tell you why  
>>> it evaluates to non-numerical values?
>>>
>>> Bobby
>>>
>>> On Thu, 07 Jul 2011 06:31:38 -0500, Ted Sariyski  
>>> <tsariysk at craft-tech.com> wrote:
>>>
>>>> Hi,
>>>> I need  a numerical solution for a system of equations which involve
>>>> numerical integrals. For one parameter the equation would be:
>>>>
>>>> f[a]==g[a]
>>>>      where
>>>> f[a_]:=NIntegrate[h[x, a] , {x, x1, x2}]
>>>>
>>>> NSolve returns: "The integrand  has evaluated to non-numerical  
>>>> values".
>>>>
>>>> Is there a built-in procedures for this type of problems or I need to
>>>> make explicit iterations?
>>>>
>>>> Thanks in advance,
>>>> --Ted
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: Unwanted Recursion
  • Next by Date: Re: Interaction of Remove and Global variables in a Module
  • Previous by thread: Re: How to NSolve equation which involves NIntegrate?
  • Next by thread: Contour ColorFunction in a ParametricPlot