Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am solving a recursive expression with ParallelTable. Here is a MWE showing how I do it, and how I set the initial condition:

SetSharedVariable[vals]
t[n_] := t[n - 1]*i*NIntegrate[Exp[-i*x^2], {x, -Infinity, Infinity}];

t[0] = 1;

vals = ParallelTable[{i, t[3]}, {i, 1, 500}];

The expression t depends on i implicitly. Now I want to make this dependency explicit, as shown here (note, it is not a functioning example!):

SetSharedVariable[vals]
t[d_, n_] := 
  t[n - 1]*d*NIntegrate[Exp[-d*x^2], {x, -Infinity, Infinity}];

(* WHAT TO DO WITH THIS, THE INITIAL CONDITION? *)
t[i, 0] = 1;

vals = ParallelTable[{i, t[i, 3]}, {i, 1, 500}];

My concern is regarding the initial condition. When I am dealing with tables, is there an easy way to implement initial conditions, or do I have to use a For-loop for that (where i is the variable)?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Is this what you're looking for?

Clear[t]
SetSharedVariable[vals]
t[d_, n_] := 
   t[d, n - 1]*d*NIntegrate[Exp[-d*x^2], {x, -Infinity, Infinity}]; (*missing d*)

t[_, 0] := 1;


vals = ParallelTable[{i, t[i, 3]}, {i, 1, 500}]

To check:

Table[t[i, 0], {i, 10}]
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.