I presume that you wish to calculate TdeltaA
for all of the values of PavP
at whatever the other constants are set to. If so, then there is a lot here that is incorrect. First of all, statements of the form
f[x_] := x^2
define a function, or more correctly a transformation rule. The left-hand side is a pattern that the execution engine matches. For example, from above, f[2]
would return 4
, f[a]
would return a^2
, but f[3, 4]
would return f[3,4]
because no rule has been set up for a two argument form of f
.
Second, as pointed out in the comments, there is a difference between :=
(SetDelayed
) and =
(Set
). Set
will evaluate the right-hand side before registering the pattern, while SetDelayed
does so after the pattern is matched. For example,
a = 5;
g[x_] = x^2 - a^2;
h[x_] := x^2 - a^2;
h[5] == g[5]
(* True *)
But, h
is susceptible to changes in a
:
a = 6;
h[5]
(* -11 *)
while g
is not
g[5]
(* 0 *)
For a more complete explanation, you should look up DownValues
and OwnValues
, and how they relate to each other.
Thirdly, the patterns on the left-hand side set up local variables on the right hand side in the function definition. If Set
is used (not that I recommend it here), then right hand side is evaluated before the variables become localized. (They are localized on the left-hand side, though.) This means any global values would be used, if they existed. For example,
x = 5;
q[x_] = x^2 - a^2
(* - 11 *)
q[28]
(* -11 *)
the value of q
is fixed. But, with SetDelayed
, the named patterns (x
in f
, g
, h
, and q
) become localized, and do not take on global values. For example, this
r[x_] := x^2 - a^2
acts identically to h
, above, despite x
having a global value.
To wrap up, what you are doing is creating a function, not a list of values, which is what I suspect you want. The For
loop, in fact, is just overwriting the definition a bunch of times, and not generating anything useful. To generate your list, I would do the following:
DeltaA1 = AbsorbanceA1[0,t1,Jp,A0,tau1,tau2] -
AbsorbanceA1[#,t1,Jp,A0,tau1,tau2]& /@ PavP
which evaluates (see Map
)
AbsorbanceA1[0,t1,Jp,A0,tau1,tau2] - AbsorbanceA1[#,t1,Jp,A0,tau1,tau2]
for each value in PavP
by replacing #
with that value. This results in a List
which is accessed by DeltaA1
.
Map
andTable
instead :) $\endgroup$ – Öskå Dec 8 '14 at 12:20Set
(=
) andSetDelayed
(:=
) $\endgroup$ – MikeLimaOscar Dec 8 '14 at 12:24Map
with an overload likeDelta[Pav_?ListQ,...]:=Delta[#,...]&\@Pav
andDelta[Pav_?NumberQ,...]:=Absorbance[...]
$\endgroup$ – mikuszefski Dec 8 '14 at 13:30