Consider the following simple example:
tlist1[a_: "a"] = Switch[a, "a", {1, 2, 3}, "b", {4, 5, 6}];
tfct1[a_: "a", x_] := #[[1]] + #[[2]]*x^#[[3]] &[tlist1[a]];
tfct2[a_: "a", x_] = D[tfct1[a, x], x];
What I want to do is to save a set of parameters as a list (tlist1) in order to generate multiple functions from the same pattern (in real, this will be Sellmeier coefficients for the Sellmeier formula). So tfct1 should give me the desired function when I specify a
. E.g. tfct1["a",x]=1+2*x^3
or tfct1["b",x]=4+5*x^6
.
Now, tfct2 uses derivatives (and second-order derivatives, but I skipped that for simplification), and I would like a result like tfct2["a",x]=6*x^2
and tfct2["b",x]=30*x^5
. But it should be usable as tfct2["a",2]=24
or tfct2["b",2]=960
.
Because of the Switch statement I was using delayed evaluation :=
in the definition of tfct1
but this somehow screws up the derivation process.
So, how do I use Switch right like in this example when I would like to use derivatives? Or is there a better way to deal with such things? (still, I would like to use symbols like "a", "b", "c" for my coefficient sets)