# Defining functions that depend upon other functions which depend upon other functions and so on

The problem is that I have to evaluate functions, that take output from previous functions, and combine them to form new functions, and do some operations and evaluate the value at new function.

But, Here is a simple example to demonstrate my problem:

g[x_] := 3 x^2 + 2 x

f[x_] := 20 x + Integrate[g[x], x]

f[2]


During evaluation of In[146]:= Integrate::ilim: Invalid integration variable or limit(s) in 2. >>

So, as you can see, you get the error, because it tries to evaluate integral with respect to 2 instead of with respect to x.

That means we need to force Integrate function to evaluate w.r.t x, then, it can substitute x = 2. But, how is that possible here?

• define f as f[x_] := 20 x + Integrate[g[y], y] /. y -> x?
– kglr
Mar 19, 2015 at 0:03
• I like f[x_] := 20 x + Integrate[g[y],{y,0,x}] better, as strictly speaking, an indefinite integral isn't really a number or even a function. Mar 19, 2015 at 0:10

we need to force Integrate function to evaluate w.r.t x
ClearAll[f, g, x]