Hi everyone. This doubt of mine does seem stupid, but I can't seem to figure it out.
I'm 100% sure that I've wrote this simple (working) code for the usage of Simpson's rule before, on a Numerical Analysis project, like the following
simpson[f_, nos_] :=
Block[{h = nos[[2]] - nos[[1]],
n = Length[nos]}, (h/3) (f[nos[[1]]] + f[nos[[n]]] +
4 Sum[f[nos[[2 k]]], {k, (n - 1)/2}] +
2 Sum[f[nós[[2 k + 1]]], {k, (n - 3)/2}])]
Bare in mind that "nos" is the vector with nodal values for x, i.e. the x_i's. However, I've started using Mathematica again for another course, and this code right now isn't working as before (I thinkkkk).
I thought of doing something like
function[ff_,a_]:=Block[{f},
f[x_]:=ff;
f[a]]
which also used to work for me before, but running " function[x,3] " also yields "x". Can anyone help me with this? There must be something stupid I'm doing. I'll add that, interestingly enough, using f for integration does work on these kinds of functions; the problem seems to happen only when I need to evaluate the argument on a given point ( i.e. obtain f[x] ).
Finally, what would be your preferred ways of handling functions with other functions as arguments?
Thank you all. :)
EDIT:
An even simpler example, running this code
function[f_]:=f[3]
function[x]
yields the result "x[3]", however, my goal is to be able to obtain "3" with it. How could I do it?