3
$\begingroup$
f[x_] := 2x + 3;
ε = 0.1; δ = 1; a = 0; L = 3;

fL[x_] = Abs[f[x] - L];

For[i = 1, i < 100, i++, 
  max = Quiet[MaxValue[{fL[x], 0 < Abs[x - a] < δ}, {x}]];
  If[max < ε, Break[]];
  δ = δ/2];

Print["Hence, |f(x)-L|<ϵ whenever 0<|x-a|<", δ ]

Question

Let $f(x)$ be any function and $L$ be any number. For a given $a$ and $\varepsilon>0$, find a $\delta>0$ such that for all $x$ satisfying $0<|x-a|<\delta$, the inequality $|f(x)-L|<\varepsilon$ holds.

For $f(x)=2x+3, \varepsilon = 0.1, L = 3, a = 0$, I have written a program in Mathematica to find value of $\delta$.

My final output is;

Hence, |f(x)-L|<ε whenever 0<|x-a|<1/32

But when I calculate $\delta$ manually, I get $\delta=\varepsilon$.

I want same thing from Mathematica. My program is giving me a $\delta$ for which solution is OK, but I want a symbolic result.

$\endgroup$
  • $\begingroup$ "But when I calculate δ manually..." - have you tried to implement what you do manually? $\endgroup$ – J. M. will be back soon Aug 13 '17 at 6:18
5
$\begingroup$

Here's general way, limited by ability of Reduce to deal with the chosen function:

Block[{f, a, lim, eps, del, x},
 f[x_] := 2 x + 3;             (* set up problem *)
 lim = f[a];
 Reduce[del > 0 && eps > 0 &&  (* these will be carried through to the answer if needed *)
   ForAll[x, x ∈ Reals,        (* condition in the definition of limit *)
    0 < Abs[x - a] < del \[Implies] Abs[f[x] - lim] < eps],
  {del}, Reals]                (* "solve" for del *)
 ]

(*  eps > 0 && 0 < del <= eps/2  *)

This found all solutions del, but really we need only demonstrate one. One could throw in a Exists[del, del > 0,...], but you won't see a formula for del from which it can be deduced there is such a del. For a numeric example, such as the example in the OP, one can use FindInstance to prove the existence of a del:

Block[{f, a, lim, eps, del, x},
 f[x_] := 2 x + 3;         (* set up problem *)
 a = 0;
 lim = f[a];
 eps = 1/10;
 FindInstance[del > 0 &&
   ForAll[x, x ∈ Reals, 
    0 < Abs[x - a] < del \[Implies] Abs[f[x] - lim] < eps],
  {del}, Reals]
 ]

(*  {{del -> 27/2021}}  *)

Here's another general existence proof, assuming del has a certain form del == k * eps, for some positive constant k.

Block[{f, a, lim, eps, del, x},
 f[x_] := 2 x + 3;
 a = 0;
 lim = f[a];
 FindInstance[k > 0 &&
   ForAll[eps, eps > 0,
    Exists[del, del == k*eps,    (* assumed form of del in terms of parameter k and eps *)
     ForAll[x, x ∈ Reals, 
      0 < Abs[x - a] < del \[Implies] Abs[f[x] - lim] < eps]
     ]],
  {k}, Reals]
 ]

(*  {{k -> 27/203}}  *)

For other functions, the form for del varies. I'm not sure how best to guess the form. One might use Series and replace the condition eps > 0 by something like 1 > eps > 0. It can also help to replace k > 0 by 1 > k > 0. Sometimes using an upper bound smaller than 1 helps. Examples:

  • For x^2, use 1 > eps > 0; a = 0 ==> {{k -> 9/34}}, a = 1 ==> {{k -> 27/244}}.
  • For Surd[x, 3] and a = 0, use del == k*eps^3 ==> {{k -> 9/34}}.
  • For Surd[x, 3] and a = 1, no change is necessary ==> {{k -> 1/5}}.

[I seem to remember a similar Q&A but couldn't find it.]


General function

This is based on the FindInstance[] solution above, and uses Series to guess what power to put on eps in del == k * eps^pow.

exponents = Cases[#,  (* sometimes `Series` produces a `Piecewise` result *)
    Verbatim[SeriesData][x_, _, c_, min_, _, den_] /; FreeQ[c, x] :> min/den,
    {0, Infinity}] &;

ClearAll[findDelta];
findDelta[f_, l_: Automatic, x_ -> a_] :=
  Module[{lim, pow, k}, Block[{eps, del},
    lim = l /. Automatic -> (f /. x -> a);  (* use function value for Automatic *)
    pow = Replace[
      exponents@Series[f - lim, {x, a, 2}],
      {{} :> (Print["Oops, no idea for form of del[eps]."]; $Failed),
       n_ /; Min[n] <= 0 :> (Print["Oops, nonpositive power suggests DNE."]; $Failed),
       n_ :> 1/Min[n]   (* inverse function gives the power to use *)
       }
      ];

    Condition[
     del == k*eps^pow /. 
      First@FindInstance[1 > k > 0 &&
         ForAll[eps, 1 > eps > 0,
          Exists[del, del == k*eps^pow,
           ForAll[x, x ∈ Reals, 
            0 < Abs[x - a] < del \[Implies] Abs[f - lim] < eps]
           ]],
        {k}, Reals],
     FreeQ[pow, $Failed]
     ]
    ]];

Examples:

findDelta[2 x + 3, x -> 0]      (*  del == (27 eps)/203  *)
findDelta[2 x^3, x -> 0]        (*  del == (27 eps^(1/3))/128  *)
findDelta[2 x^3, x -> 1]        (*  del == (27 eps)/698  *)
findDelta[Surd[x, 3], x -> 0]   (*  del == (9 eps^3)/34  *)

(* failures/errors: *)
findDelta[1/Log[Abs@Sin[x]]], 0, x -> 0]
(* Print:  Oops, no idea for form of del[eps].       *)
(* Out[]=  findDelta[1/Log[Abs@Sin[x]]], 0, x -> 0]  *)

findDelta[Exp[1/x], 0, x -> 0]
(* Errors: 1/0, ComplexInfinity                      *)
(* Print:  Oops, nonpositive power suggests DNE.     *)
(* Out[]=  findDelta[E^(1/x), 0, x -> 0]             *)
$\endgroup$
1
$\begingroup$

The following is a function that will return δ given f, ε, a and L (which I'm going to call l because upper case variables aren't a good idea in Mathematica). This is the function:

delta[f_, l_, a_, ε_] := Quiet[Min[Abs[a - x /. Solve[Abs[f[x] - l] == ε, x]]]]

With your example (and I'm defining f as a pure function):

f = 2 # + 3 &;
ε = 0.1;
a = 0;
l = 3;
δ = delta[f, l, a, ε]

0.05

So with ε = 0.1 you need to set δ < 0.05 so that |f[x] - l| < ε. Now we can check our answer:

MaxValue[{Abs[f[x] - l], a - δ < x < a + δ}, x]

0.1

as required.

It can also handle symbolic arguments (but I don't guarantee that it won't break easily):

ClearAll[ε]
δ = delta[f, l, a, ε]

0.5 Abs[ε]

That is, given any ε > 0, choose δ < 0.5 ε. Then |f[x] - l| < ε.

This function can handle marginally more complicated functions, like this cubic:

f = -#^3 + 3 #^2 + 2 # + 3 &;
ε = 0.1;
a = 1;
δ = delta[f, f[a], a, ε]

0.0200016

And as before

MaxValue[{Abs[f[x] - f[a]], a - δ < x < a + δ}, x]

0.1

as required.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.