Question: How to multithread to aid with constructing a list.

I'm trying to write some simple code to help plot an approximation of a solution to the heat equation. On one set of axes I want to plot the temperature characteristic of a 1-D bar at different temperatures. I am able to do this easily enough, but the code uses a for loop and my core i7 is not being utilized properly. To rectify this I have tried to use threads, but after many hours of playing around I cannot get it to work fully. The first time I run my code I am faced with the error "Error, (in plot) cannot determine if this expression is true or false: not fHwLibraryInitialized".

Then after this I can run my code a few more times and it will produce a graph, but each time the graph will be different, meaning most of them are incorrect. After running my display command several times I am then faced with the error "kernel connection has been lost", and I need to restary. I have never played with threads before and have very little understanding of how it works.

with(Threads);
with(plots);

para := proc (A, B)
return [op(A), op(B)]; 
 end proc;

HeatP := proc (f, g, n, lambda, X, N, M, T)
 local k, u, i, L, a; 
u := proc (x, t) options operator, arrow; sum((int(sin(k*lambda*x)*g, x = 0 .. 1))*exp(-k*lambda*t)*sin(k*lambda*x), k = 1 .. n) end proc;
 L := [];
 if N-X < 3 then for i from X to N do
 L := [op(L), plot(u(x, (i*T-T)/M), x = 0 .. 1)] 
end do; 
return L;
else a := floor((1/2)*(N-X))+X; 
Threads:-Task:-Continue(para, Task = [HeatP, f, g, n, lambda, X, a, M, T], Task = [HeatP, f, g, n, lambda, a+1, N, M, T])
 end if
 end proc;

g := piecewise(x <= 0, 0, 0 < x and x < 1, exp(-2/(1-(x-1/2)^2)), x >= 0, 0);

display(Threads:-Task:-Start(HeatP, 0, g, 5, Pi, 1, 8, 8, 2));

I cannot see where the problem is, but there is obviously at least one. Any help would be appreciated.

Please Wait...