2
$\begingroup$

I'm defining what's called a fractional integral in Mathematica, which acts on a list of functions that depend on $x$:

integral[α_, g_[x_][[i_]], x_] := Integrate[(x-t)^(α-1) g[t][[i]], {t, 0, x}]

with some assumptions that say the $x$ in the bounds is nonzero.

What it does is it takes a function $f(x)$, kept in a list, changes the variable to $t$, and integrates it along with a power law, evaluating the bounds at $0$ and $x$. The problem is that sometimes I have to input a different form of a function, for example,

integral[α, (g[x][[i]])^3, x].

Mathematica doesn't recognize it as a viable function and just returns it back without doing anything.

I need to find a robust pattern that would take any function of $x$ and change it to a function of $t$ inside the integral. Changing, in the definition,

g_[x_][[i_]] -> g_[x_]

doesn't help.

I appreciate any help!

$\endgroup$
1
  • 1
    $\begingroup$ When you say the functions are kept in a list, what do you mean exactly? Can you provide an example list (suitably short and simple) that shows what form the functions are in? Depending on the answer to this question, I would suggest something much simpler than specifying a pattern for the function. In addition, why put the Part specification in the Pattern when you can just Map integral over the list of functions? $\endgroup$
    – march
    Commented Aug 8, 2016 at 22:38

1 Answer 1

2
$\begingroup$

Here's one possibility that does away with having to do any complicated pattern-matching. Suppose you have a list of expressions to be integrated, given by

lst = {x^2, (x + 1)^2, x};

Define a function

Clear@integral
integral[a_, func_, var_] := Integrate[(var - t)^(a - 1) Evaluate[func /. var -> t], {t, 0, var}]

In this case, the symbol that goes into var must match the independent variable in your list of expressions. Then, if you want to integrate the functions in lst, just Map integral over the list:

integral[2, #, x] & /@ lst
(* {x^4/12, x^2/2 + x^3/3 + x^4/12, x^3/6} *)

The key is to use the replacement in

Evaluate[func /. var -> t]

to change variables inside the Integrate call.


Alternatively, if you need to specify different variables, then we can define an alternative version:

Clear@integral
integral[a_, func_, inVar_, x_] := Integrate[(x - t)^(a - 1) Evaluate[func /. inVar -> t], {t, 0, x}]
integral[a_, func_, var_] := integral[a, func, var, var]

Now suppose the list was

lst = {x^2, (y + 1)^2, z};

Then, we can do either

MapThread[integral[2, #1, #2] &, {lst, {x, y, z}}]
(* {x^4/12, y^2/2 + y^3/3 + y^4/12, z^3/6} *)

or, if you want the outputs to have all the same output variable,

MapThread[integral[2, #1, #2, x] &, {lst, {x, y, z}}]
(* {x^4/12, x^2/2 + x^3/3 + x^4/12, x^3/6} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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