1
$\begingroup$

I have a short package like this:

BeginPackage["FunctionAnalysis`",{"Global`"}];
MonoIntervals::usage="returns monotonic intervals of given function";
Begin["`Private`"];
FunctionAnalysis`Private`MonoIntervals[func_[arg_],var_]:={Reduce[D[func[arg],var]>0,var]}
End[];
EndPackage[];

I include it, and when I call, for example:

MonoIntervals[Sin[x],x]

it executes MonoIntervals. The problems occurs when I try to call MonoIntervals with functions like:

f[x_]:=x^2+2*x-10
MonoIntervals[f[x],x]

this results in

Out[25]=MonoIntervals[-10 + 2 x + x^2, x]

Why doesn't the function execute?

$\endgroup$
1
$\begingroup$

Because MonoIntervals[f[x],x] will evaluate like this:

  1. MonoIntervals[f[x], x]
  2. MonoIntervals[x^2+2*x-10, x]

And it stops there because x^2+2*x-10 doesn't match the pattern func_[arg_]. What precisely are you trying to achieve by using this pattern?

$\endgroup$
  • $\begingroup$ I am trying to get intervals where given function is positive. What pattern would suit for my case? I thought I have to use func_[arg_], if I replace it with MonoIntervals[func_,arg_] and use later in Reduce[D[func,arg]>0,arg] it still doesn't evaluate. $\endgroup$ – Kristians Kuhta Dec 19 '14 at 16:47
  • $\begingroup$ @KristiansKuhta Have you seen the tutorial on patterns? If you are still unsure about why your function behaves the way it does, it's a good idea to stop for a moment and read through it. $\endgroup$ – Szabolcs Dec 19 '14 at 17:01

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.