MathGroup Archive 2003

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

Search the Archive

Re: Re: Re: Condition/constraint problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg41028] Re: [mg40976] Re: [mg40938] Re: Condition/constraint problem
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Tue, 29 Apr 2003 05:25:12 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

As a rule built-in functions do not rely on packages. As far as I know 
there is no exception to this. There is, I think, a good case for 
including more numerical math functions in the kernel, particularly 
that, judging by some comments I have heard, some of the numerical math 
packages (e.g. NLimit) are not considered very satisfactory by 
numerical math experts at WRI. But then that could be precisely the 
reason why this has not been done...

Andrzej Kozlowski
Yokohama, Japan
http://www.mimuw.edu.pl/~akoz/
http://platon.c.u-tokyo.ac.jp/andrzej/


On Tuesday, April 29, 2003, at 12:22  pm, Bobby Treat wrote:

> I don't understand why Derivative shouldn't call ND for functions like 
> this.  If the other method is more appropriate sometimes (but I can't 
> imagine when), an option could select which method is used.  It might 
> be inconvenient to explicitly put options on derivatives, but 
> SetOptions might be used. At minimum, the Scale option would be > needed.
>
> I suppose, though, the real take-away lesson is not to use Dt or 
> Derivative without sanity-checking the results.
>
> Bobby
>
> -----Original Message-----
> From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
To: mathgroup at smc.vnet.net
> To: Bobby Treat <drmajorbob+MathGroup3528 at mailblocks.com>
> Cc: mathgroup at smc.vnet.net
> Sent: Tue, 29 Apr 2003 11:25:04 +0900
> Subject: [mg41028] Re: [mg40976] Re: [mg40938] Re: Condition/constraint problem
>
> Of course, but that is not surprising since you are comparing 
> something that is a part of general functionality with something that 
> is specifically designed for the given purpose. As David Withoff 
> pointed out, it may be seen as an argument for removing this 
> particular feature from Mathematica altogether, although since it 
> works quite well in simple cases I personally think it should stay, 
> perhaps with some sort of "health warning" in the documentation.
>
>
> Andrzej Kozlowski
> Yokohama, Japan
> http://www.mimuw.edu.pl/~akoz/
> http://platon.c.u-tokyo.ac.jp/andrzej/
>
>
>
>
> On Tuesday, April 29, 2003, at 10:43 am, Bobby Treat wrote:
>
>
>> Compare ND with the simplistic method, for the same stepsize:
>>
>> << NumericalMath`NLimit`
>> f = 3/2000 + (3/2500)*Sin[70*#1] &;
>> vx1[t_] := 3/2000 + (3/2500)*Sin[70*t] /; t < 5
>> nd[t_] := ND[vx1[x], x, t, Scale -> 0.001]
>> myDv[step_] := (vx1[#1 + step] - vx1[#1 - step])/(2*step) &
>> plot = Plot[{ND[vx1[x], x,
>> t, Scale -> 0.001] - f'[t], myDv[
>> 0.001][t] - f'[t]}, {t, 0, 2}, ImageSize ->
>> 500, PlotRange -> All, DisplayFunction -> Identity];
>> Max /@ Abs@(Cases[plot, Line[a_] :> a, Infinity][[All, All, 2]])
>>
>> {7.651476674475077*^-12, 0.00006858319495960108}
>>
>> Dt and Derivative do well if given enough precision (and time), but
> so > does ND -- and much faster.
>>
>> Bobby
>>
>> -----Original Message-----
>> From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
To: mathgroup at smc.vnet.net
>> To: Bobby Treat <drmajorbob+MathGroup3528 at mailblocks.com>
>> Cc: mathgroup at smc.vnet.net; kuska at informatik.uni-leipzig.de; >
> u8514501 at cc.nctu.edu.tw
>> Sent: Tue, 29 Apr 2003 08:48:19 +0900
>> Subject: [mg41028] Re: [mg40976] Re: [mg40938] Re: Condition/constraint problem
>>
>> Well, if you are willing to wait a bit then to get pretty small error 
>> all you need to do is:
>>
>>
>> In[6]:=
>> $MinPrecision = $MaxPrecision = 50
>>
>>
>> Out[6]=
>> 50
>>
>>
>> In[7]:=
>> f = 3/2000 + (3/2500)*Sin[70*#1] & ;
>>
>>
>> In[8]:=
>> vx1[t_] := 3/2000 + (3/2500)*Sin[70*t] /; t < 5
>> fin1 = Dt[vx1[t], t];
>> plot = Plot[fin1 - Derivative[1][f][t], {t, 0, 2}, ImageSize -> 500,
>> PlotRange -> All];
>> Max[Abs[Cases[plot, Line[a_] :> a, Infinity][[1,All,2]]]]
>>
>>
>> (Graph omitted)
>>
>>
>> Out[11]=
>> 4.173050793809807*^-13
>>
>>
>> etc.
>>
>>
>>
>>
>>
>>
>> On Tuesday, April 29, 2003, at 03:44 am, Bobby Treat wrote:
>>
>>
>>> Trying to understand the issues better, I tried a simpleton
> numerical >> method:
>>>
>>> f = 0.0015 + 0.0012 Sin[70 #] &;
>>> myDv[step_] := If[#1 + step < 5, (
>>> f[#1 + step] - f[#1 - step])/(2*step), undefined] &
>>> maxError[delta_] := Block[{$DisplayFunction},
>>> plot = Plot[{f'[t] - myDv[delta][t]}, {t, 0, 2}, PlotPoints ->
>>> 100, ImageSize -> 500];
>>> Max@Abs@Cases[plot, Line[a_] :> a, Infinity][[1, All, 2]]
>>> ]
>>> ListPlot[Table[{delta,
>>> maxError[delta]}, {delta, .1, 1.1, .1}], AxesOrigin -> {0, >
>> Automatic}];
>>>
>>> Even with relatively huge step-sizes, this error is smaller than the 
>>> one Derivative is making:
>>>
>>> vx1[t_] := 0.0015 + 0.0012 Sin[70 t] /; t < 5
>>> fin1 = Dt[vx1[t], t];
>>> plot = Plot[fin1 - f'[t], {t, 0, 2}, PlotPoints -> 100, ImageSize ->
>>> 500, PlotRange -> All];
>>> Max@Abs@Cases[plot, Line[a_] :> a, Infinity][[1, All, 2]]
>>>
>>> 0.12411
>>>
>>> There's also this behavior, as Peltio already pointed out:
>>>
>>> Table[fin1, {t, 4.4, 5, 0.1}]
>>> Table[myDv[0.01][t], {t, 4.4, 5, 0.1}]
>>> Table[f'[t], {t, 4.4, 5, 0.1}]
>>>
>>> {-0.0398025806772852, -0.02675008852536776,
>>> Derivative[1][vx1][4.6000000000000005],
>>> Derivative[1][vx1][4.7], Derivative[1][vx1][
>>> 4.800000000000001], Derivative[1][vx1][
>>> 4.9], Derivative[1][vx1][5.]}
>>>
>>> {0.0767133, 0.0515567, 0.00102404, -0.0500126, -0.0764333,
>>> -0.0652338, undefined}
>>>
>>> {0.0833559, 0.0560209, 0.00111271, -0.0543432, -0.0830516,
>>> -0.0708824, -0.0238252}
>>>
>>> There may not be a bug, but it sure ain't impressive!
>>>
>>> Bobby
>>>
>>> -----Original Message-----
>>> From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
To: mathgroup at smc.vnet.net
>>> To: Bobby Treat <drmajorbob+MathGroup3528 at mailblocks.com>
>>> Cc: mathgroup at smc.vnet.net; Jens-Peer Kuska >
>> <kuska at informatik.uni-leipzig.de>; u8514501 at cc.nctu.edu.tw
>>> Sent: Sat, 26 Apr 2003 20:01:28 +0900
>>> Subject: [mg41028] Re: [mg40976] Re: [mg40938] Re: Condition/constraint
> problem
>>>
>>> I forgot to say one (rather obvious) thing so just for the sake of >
>> completeness: the reason for the difference is, of course, that the >
> > first derivative is computed numerically while the second 
> symbolically > > and the value specified for t is substituted into the 
> symbolic > > expression. As Jens correctly pointed out, Mathematica 
> can't compute > > the derivative of the first function symbolically 
> and won't return any > > value if specify an exact number (like 2) for 
> the value where the > you
>>> want the derivative to be computed.
>>>
>>>
>>> Anyway, my point was that there is no bug here.
>>>
>>>
>>> Andrzej Kozlowski
>>> Yokohama, Japan
>>> http://www.mimuw.edu.pl/~akoz/
>>> http://platon.c.u-tokyo.ac.jp/andrzej/
>>>
>>>
>>>
>>>
>>> On Saturday, April 26, 2003, at 07:47 pm, Andrzej Kozlowski wrote:
>>>
>>>
>>>> This seems to be just an accuracy problem due to the very rapidly >
>>> oscillating nature of the function. You need much more accurate
>> input,
>>>> and even then the answers won't be exactly the same:
>>>>
>>>> In[1]:=
>>>> vx1[t_] := 3/2000 + (3*Sin[70*t])/2500 /; t < 5
>>>>
>>>> In[2]:=
>>>> vx2[t_] := 3/2000 + (3*Sin[70*t])/2500
>>>>
>>>> In[3]:=
>>>> Derivative[1][vx1][2.`50]
>>>>
>>>> Out[3]=
>>>> -0.016616340216276107118073957504289560620917139256026603482\
>>>> 40545`46.5497
>>>>
>>>> In[4]:=
>>>> Derivative[1][vx2][2.`50]
>>>>
>>>> Out[4]=
>>>> -0.016616340216358530300150292495099072037728048646002646485\
>>>> 71143`47.1588
>>>>
>>>>
>>>> Andrzej Kozlowski
>>>> Yokohama, Japan
>>>> http://www.mimuw.edu.pl/~akoz/
>>>> http://platon.c.u-tokyo.ac.jp/andrzej/
>>>>
>>>>
>>>> On Saturday, April 26, 2003, at 04:26 pm, Bobby Treat wrote:
>>>>
>>>>> Your explanation implies there IS no value for vx1'[t], but >>
>>> Mathematica
>>>>> does compute one, when t is numeric. It's simply wrong.
>>>>>
>>>>> vx1[t_] := 0.0015 + 0.0012 Sin[70 t] /; t < 5
>>>>> vx2[t_] := 0.0015 + 0.0012 Sin[70 t]
>>>>> vx1'[2.]
>>>>> vx2'[2.]
>>>>>
>>>>> 0.00793433
>>>>> -0.0166163
>>>>>
>>>>> Bobby
>>>>>
>>>>> -----Original Message-----
>>>>> From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
To: mathgroup at smc.vnet.net
>>>>> To: mathgroup at smc.vnet.net
>>>>> Subject: [mg41028] [mg40976] [mg40938] Re: Condition/constraint problem
>>>>>
>>>>> Hi,
>>>>>
>>>>> der derivative is complete right, since
>>>>> Condition[] has no derivative
>>>>>
>>>>> Dt[vx1[t]] evaluates to vx1'[t]
>>>>>
>>>>> until you can tell Mathematica how to
>>>>> find out
>>>>> a) what the function value of vx1[t] for t>5 may be
>>>>> b) to compute the derivative for t==5
>>>>> c) determine when the symbol t in vx1[t] may be >5
>>>>>
>>>>>
>>>>> Regards
>>>>> Jens
>>>>> Bamboo wrote:
>>>>>>
>>>>>> Dear all,
>>>>>>
>>>>>> I find a problem and don't know why. The input is as following.
>>>>>> If a condiction(constraint) is set to the function, vx1[t],
>>>>>> the derivative of vx1[t] is worng (fin1 is not equal to fin2).
>>>>>> Any help welcome.
>>>>>>
>>>>>> vx1[t_] : = 0.0015 + 0.0012 Sin[70 t] /; t < 5
>>>>>> vx2[t_] : = 0.0015 + 0.0012 Sin[70 t]
>>>>>> fin1 = Dt[vx1[t], t]
>>>>>> fin2 = Dt[vx2[t], t]
>>>>>> Plot[fin1, {t, 0, 2}]
>>>>>> Plot[fin2, {t, 0, 2}]
>>>>>>
>>>>>> Thanks,
>>>>>> Bamboo
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>>
>> Andrzej Kozlowski
>> Yokohama, Japan
>> http://www.mimuw.edu.pl/~akoz/
>> http://platon.c.u-tokyo.ac.jp/andrzej/
>>
>>
>>
>>
>
>
>



  • Prev by Date: Re: Re: Re: Condition/constraint problem
  • Next by Date: Eliminating unknown functions from partial differential equations
  • Previous by thread: Re: Re: Re: Condition/constraint problem
  • Next by thread: Where have all the axes gone?