I'm trying to write a Mathematica function which takes an arbitrary expression as input. More concretely, I'm trying to write an integration function (utilizing the trapezoidal method), the input of which behaves like NIntegrate. For example:
fTest[x_, y_] := x + y;
fNew[y_] := NIntegrate[x^2*fTest[x, y], {x, 0, 10}];
Currently, I have something like:
NInt1D[f_] :=
Module[{Num, eps, sum, a, X},
Num = 10;
eps = 10/Num;
sum = 0;
For[a = -Num, a <= +Num, a++,
X = a*eps;
sum += f[X]*eps;];
Return[sum]];
Which is problematic for me, since the above NInt1d only takes functions as input, and not expressions, preventing me from defining my function in terms of the integral, as can be done with NIntegrate.
I hope this toy example makes clear my intentions. I found another post which ask this question in the context of creating a Plot function [1]. Unfortunately, the explanation was too specific, and I found it hard to understand -- I'm somewhat new to Mathematica.
Xfor example – Lukas Lang Dec 29 '18 at 23:42