KCPower

20 Reputation

3 Badges

8 years, 261 days

MaplePrimes Activity


These are questions asked by KCPower

I'm trying to use the Grid package to speed up my computations somewhat, however Grid[Map] does not seem to play well with add.

Erroran := proc (e, g, f, T)
 local k, errorterm, terms, n, ma, i;

 ma := proc (n) options operator, arrow; evalf(T*(1/2)*maximize(int(f*f, x = 0 .. 1)-add(int(f*sqrt(2)*sin(k*Pi*x), x = 0 .. 1), k = 0 .. n), s = 0 .. T)/(Pi*Pi)) end proc;

 errorterm := proc (n) options operator, arrow; int(g*g, x = 0 .. 1, numeric)-add(int(g*sqrt(2)*sin(k*Pi*x), x = 0 .. 1, numeric), k = 1 .. n)+ma(n) end proc;

 i := 1;

 while e < Grid[Map](errorterm, i) do i := i+1 
end do;
 return i
 end proc

h := piecewise(x <= 0, 0, 0 < x and x < 1, 3, x >= 1, 0)

Erroran(0.1e-3, h, 1, 1)

 

When I run the above code I get the error "Error, (in Grid:-Map) unable to execute add." Does anyone know of a workaround to this? Or another way to speed up my code? If so it would be much appreciated. 

The code works perfectly well if I don't use Grid and just use "errorterm(i)" in my while loop instead.

with(plots):
with(Grid):

HeatPC := proc (f, g, n, lambda, N, T)
 local k, u, i, L,fcoef;
 fcoef := proc (y) options operator, arrow; sqrt(2)*sin(lambda*y) end proc;
 u := proc (y, t) options operator, arrow; sum((int(fcoef(x)*g, x = 0 .. 1, numeric))*exp(-k*lambda*t)+exp(-k*lambda*t)*(int(exp(k*lambda*s)*(int(f, x = 0 .. 1, numeric)), s = 0 .. t, numeric)), k = 1 .. n) end proc;
 L := [Grid[Seq](plot(u(x, (i*T-T)/N), x = 0 .. 1, color = COLOR(HUE, i/N), legend = typeset((i*T-T)/N, "s")), i = 1 .. N)]; 
return u(1, 1), display(L, legendstyle = [location = right])
 end proc;

h := piecewise(x <= 0, 0, 0 < x and x < 1, 3, x >= 1, 0)

HeatPC(1, h, 100, Pi, 10, 1.5)

I'm trying to use the above procedure to plot graphs for different inputs. To make the code easier on the eye I want to split my main function u into several smaller functions. To that end I added the function fcoef. Now when I try to run the procedure for simple input values I get the error "Warning, expecting only range variable x in expression 100.*int(fcoef(x)*piecewise(x <= 0.,0.,0. < x and x < 1.,1.,1. <= x,0.),x = 0. .. 1.) to be plotted but found name fcoef". However u still evaluates nicely at (1,1) so obviously my function fcoef is well defined. How do I go about getting plot to recognize this?

 

 

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.

Page 1 of 1