Joe Riel

9530 Reputation

23 Badges

20 years, 24 days

MaplePrimes Activity


These are answers submitted by Joe Riel

The following code compares three ways to do this

A := Matrix(100):

isRowZero1 := proc(A,i)
    andmap(Testzero, A[i,..]);
end proc:

isRowZero2 := proc(A,i)
local j;
    for j to upperbound(A,2) do
        if A[i,j] <> 0 then
            return false;
        end if;
    end do;
    return true;
end proc:

isRowZero3 := proc(A,i)
    not rtable_scanblock(A,[i, 1..upperbound(A,2)],'HasNonZero');
end proc:


CodeTools:-Usage(isRowZero1(A,1),'iterations'=10\000);
memory used=10.45KiB, alloc change=32.00MiB, cpu time=88.00us, real time=88.00us, gc time=3.20us

CodeTools:-Usage(isRowZero2(A,1),'iterations'=10\000);
memory used=2.47KiB, alloc change=0 bytes, cpu time=36.00us, real time=35.80us, gc time=0ns

CodeTools:-Usage(isRowZero3(A,1),'iterations'=10\000);
memory used=200 bytes, alloc change=0 bytes, cpu time=2.80us, real time=3.00us, gc time=0ns

Using rtable_scanblock appears to be the way to go. Note that method 2 is more efficient than method 1 because it doesn't allocate memory to extract the row. That's why, in a different thread, I wished Maple had an andseq builtin. Method 3 is essentially method 2, but using rtable_scanblock with its builtin procedure HasNonZero to get some speed. When dealing with rtables (Arrays, Matrices, Vectors) rtable_scanblock works but given its more complicated interface is not something I immediately try. 

applyop(`^`,1,A,2);

This is a rather low level approach and works for the simple case when when A is number with a unit. It won't work for the more general case of an algebraic expression with a unit. If you have to deal with such expressions you would be better off writing a small procedure that operates on the non-Unit part of the expression. Let me know if you need help doing that.

Set Digits := 10 before calling Histogram.

A simple method is

subs(beta-1 = 1, e44_6);

You can then multiply by the factor if desired.

Similarly

map(`/`, e44_6, beta-1)

If R is a list, then you could do 

if member(R[i], R[1..i-1]) then
It would be nice if Maple provided an orseq builtin, then one could do
if orseq(R[i]=R[k], k=1..i-1) then

The small advantage of that hypothetical solution is that it wouldn't allocate extra memory for a sublist that is not otherwise required.

Write directly to the file.  Something like (I haven't tested this, so assume it has bugs):

for i to 5000 do
   file := sprintf("SIM_%d.mpl", i);
   fprintf(file, "Threads:-Map(SIM, 5000, %d);\n", i);
   fclose(file);
end do:

Try

Arg := z -> Pi+argument(-z);
y := sqrt(x^2+1);
applyop(sort,1,y,order=plex(x),ascending);
Actually, you don't need the applyop, sort seems to work here without it
sort(y, order=plex(x), ascending);
sort(y, order=plex(x), descending);

Type diff then press escape, which pops up an appropriate dialog.

I suspect that you'll find that the solution is not unique unless another initial condition is specified. Here's one way to handle that

sys := {Q(0) = 0, Q(t) = (1.375*4190)*(80-T__1(t)), Q(t) = (1.375*4190)*(T__2(t)-38.2), diff(Q(t), t) = (0.1375e-1*(T__1(t)-T__1s(t)))*((T__1(t)+T__1s(t))*(1/2)), diff(Q(t), t) = (0.1375e-1*(T__2s(t)-T__2(t)))*((T__2s(t)+T__2(t))*(1/2)), diff(Q(t), t) = (240*0.1375e-1)*(T__1s(t)-T__2s(t))/(0.1e-2)}:
inieqs := subs(t=0,convert(sys,D)):
inisol := frontend(fsolve, [inieqs,{Q,T__1,T__2,D(Q),T__1s,T__2s}(0)], [{`+`,`*`,`=`,set},{}]):
ini := select(has,inisol, T__1s);
f := dsolve(sys union ini, numeric):
f(1);
  [t = 1., Q(t) = 16.9804473424030, T__1(t) = 79.9970526452866, T__1s(t) = 62.6882711631579, T__2(t) = 38.2029473547134, T__2s(t) = 62.6831259358860]
 
radnormal(sqrt(3579757));
               151*157^(1/2)

As Acer suggests, the first thing to do is to make the single-threaded approach as efficient as you can.  One improvement, probably minor here, is to avoid  building a list an element at a time. 

with(Threads);
with(plots);

HeatP := proc (f, g, n, lambda, X, N, M, T)
global x;
local i,k,t,val;
    val := add((int(sin(k*lambda*x)*g, x = 0 .. 1))*exp(-k*lambda*t)*sin(k*lambda*x), k = 1 .. n);
    [seq(plot(eval(val,t=(i*T-T)/M), x = 0 .. 1), i=X..N)];
end proc;

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

plts := HeatP(0, g, 5, Pi, 1, 3, 8, 2);

display(plts);

Note that the f parameter is never used.

I suspect that a proof is not what you are looking for in that the statement is practically a definition of Pi.

With that in mind, see the first example in the help page for VectorCalculus,ArcLength.

Was Maple's current directory the same as the directory in which the file was located? The current directory is displayed in the bar at the bottom of the GUI.  Click on it to change the directory.

verify is the wrong procedure to use here, it is for doing type-based verifications. Use is

is(2*q/(q^4+q^2+1)-1/((q-1)^2*(q+1)) >= 0) assuming q>7;
                       true
First 20 21 22 23 24 25 26 Last Page 22 of 114