Re: Re: Re: Condition/constraint problem
- To: mathgroup at smc.vnet.net
- Subject: [mg40996] Re: [mg40976] Re: [mg40938] Re: Condition/constraint problem
- From: David Withoff <withoff at wolfram.com>
- Date: Sun, 27 Apr 2003 03:21:18 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
> 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 You can improve this result by using the ND function to compute the derivative, and most importantly, using the Scale option of ND to tell the computer about the scale of variation of the function. For example: In[]:= << "NumericalMath`NLimit`" In[]:= altfin1[t0_?NumberQ] := ND[vx1[t], t, t0, Scale -> 0.01] In[]:= Plot[altfin1[t], {t, 0, 1/4}] can be expected to give a result with relatively little numerical error. The reported behavior is discussed in http://support.wolfram.com/mathematica/kernel/Symbols/System/Derivative.html and shows what happens when numerical differentiation is used without knowing the scale of variation of the function. The result is "correct to within numerical error", but that numerical error is very large. The definition of vx1[t] is meaningful only when t is a number, so the derivative of vx1[t] can only be computed numerically. The Derivative function does this automatically, but without knowing the scale of variation of the function it cannot give reliable results for rapidly varying functions. It has been suggested that the frequency of difficulty with automatic numerical differentiation is sufficiently high that this feature should simply be removed (which is really the only reasonable alternative), in which case the example above would generate an error message and abandon the calculation, and users would be obligated to use ND (or equivalent) to do this calculation. Although automatic use of numerical algorithms is employed quite successfully elsewhere in Mathematica, it may be that automatic differentiation is an exception. I do not know the answer to that question, but I would agree that this suggestion merits continued consideration. Dave Withoff Wolfram Research