I'm having a problem concerning function addition. The following code shows an example that illustrates my problem. I had this list of functions that have the same variable. I had them by using the Total function and declared a function of that variable equal to the Total[list], like in this example:
f1[x_] := 2 x + 1;
f2[x_] := x;
f3[x_] = 4 x;
l1 = List[f1[x], f2[x], f3[x]];
o[x_] := Total[l1];
o[1]
The output of o[1]
was 1+7x
, instead of 8
, which is what I want. Any suggestion on how to approach this problem?
Thank you
f1[x_] := 2 x + 1; f2[x_] := x; f3[x_] = 4 x; l1[x_] := List[f1[x], f2[x], f3[x]]; o[x_] := Total[l1[x]]; o[1]
$\endgroup$x_
parameter is scoped differently from thex
symbol you provide inl1
. So you could also mostly keep your code but replaceo
with this:o[v_] := Total[l1] /. x -> v
$\endgroup$Evaluate
in definition ofo[x_]
, i.e.,o[x_] := Evaluate@Total[l1];
$\endgroup$SetDelayed
andEvaluate
! $\endgroup$