Joe Riel

9660 Reputation

23 Badges

20 years, 9 days

MaplePrimes Activity


These are replies submitted by Joe Riel

@Christopher2222 My mistake.  I misread the description and thought you were applying the cooling air to just one end. However, the boundary condition you have at x=2 doesn't make sense, the units are wrong. If you are holding it at constant temperature, then drop the derivative. If it is something else, you need to adjust the value to get the units correct (Maple doesn't care, but your results will suffer).

@Christopher2222 My mistake.  I misread the description and thought you were applying the cooling air to just one end. However, the boundary condition you have at x=2 doesn't make sense, the units are wrong. If you are holding it at constant temperature, then drop the derivative. If it is something else, you need to adjust the value to get the units correct (Maple doesn't care, but your results will suffer).

Use seq with the = to save a few:  Wait(seq(Create(p(i)),i=L)).

Also, you can remove the assignment to p and just pass the procedure in.  That gets it down to 83 characters:

M:=():use Threads in Wait(seq(Create(proc(n):-M:=Sleep(n),M,n end(i)),i=L))end:[M];

Final edit (then back to work)

You can eliminate two more characters by sorting a sequence instead of a list:

L := 3,2,1:
M:=():use Threads in Wait(seq(Create(proc(n):-M:=Sleep(n),M,n end(i)),i=L))end:M;

@Alec Mihailovs I was thinking of extending it to handle fractions,but then wondered about the proper way to express them.  An easy solution is to just print numerator over denominator, however, that isn't what is typically used, at least not for small fractions.  For example, it should print, one half, one third, ..., twenty three and five sixteenths. That will take a bit more work.

Here it is.  I changed the case (Numbers -> Number).

NumberToWords.mpl

Interesting use, Alec.

@Christopher2222 I couldn't find the source on a backup (of my home computer). Possibly it could be retrieved from MaplePrimes archive.

@haka_nz Yes, but without knowing what the globals are assigned, it isn't easy to to reproduce the bug.

@haka_nz Yes, but without knowing what the globals are assigned, it isn't easy to to reproduce the bug.

Use ?plots[display] to combine separate plot structures into one plot. For example,

plt1 := plot(sin(x), x=0..Pi, color=blue):
plt2 := plot(cos(x), x=0..Pi,color=red):
plots[display](plt1,plt2);

Actually, you can drag one plot into another. Just click on the curve. It should then be highlighted, which is indicated by being surrounded by a blue lines. Then drag the curve to the other plot. Hold down the control key to copy and drag.

Use ?plots[display] to combine separate plot structures into one plot. For example,

plt1 := plot(sin(x), x=0..Pi, color=blue):
plt2 := plot(cos(x), x=0..Pi,color=red):
plots[display](plt1,plt2);

Actually, you can drag one plot into another. Just click on the curve. It should then be highlighted, which is indicated by being surrounded by a blue lines. Then drag the curve to the other plot. Hold down the control key to copy and drag.

What help page are you referring to?

Neat.  The action isn't particularly smooth.  Using a Matrix input to ?PolarPlot, and ?evalhf to recompute it, seems to help a bit. The number of columns in the Matrix needs to be greater than 50; plot just uses that as a minimum, I believe.  Here are my hacks to the code block:

npts := 300:                
M := Matrix(npts,2);#datatype=float[8]):

UpdateM := proc(M,a,b,n)
local i,theta;
   for i to n do
      theta := b - Pi + 2*Pi*i/n;
      M[i,1] := cos(theta)/a;
      M[i,2] := sin(theta)/b;
   end do;
 end proc:

plotter_action := proc()
   local A,B;
  
   A := DocumentTools:-GetProperty('Plot1','endx');
   B := DocumentTools:-GetProperty('Plot1','endy');
  
   DocumentTools:-SetProperty('Label0','caption',
                              sprintf("%a",
                                      evalf[3](A)),
                              'refresh'=true);

   DocumentTools:-SetProperty('Label1','caption',
                              sprintf("%a",
                                      evalf[3](B)),
                              'refresh'=true);
   evalhf(UpdateM(var(M),A,B,npts));

   DocumentTools:-SetProperty('Plot0', 'value',
                              plots:-polarplot(M,
                                    #eval([cos(b+t)/a, sin(a+t)/b, t=-Pi..Pi],
                                    #     [a=A, b=B]),
                                    'coordinateview'=[0..1,-2*Pi..2*Pi],
                                    'color'='RGB'(A/8+abs(B/4),abs(B/2-A/8),2/3-abs(A/8-B/2)),
                                    'thickness'=2),
                              'refresh'=true);
end proc:

A faster approach is to create the empty plot structure, then compute the coordinates and substitute them into the CURVES structure.  That avoids calling the plot routine, which isn't optimized for rapid redrawing.  The following appliable module, which replaces all the code in the Code Region, implements that.  It is noticeably smoother in redrawing but doesn't change color. That, however, is easily implemented.

plotter_action := module()
export ModuleApply;
local A,B, npts, M, Plt, UpdateM;

    DocumentTools:-SetProperty('Plot1', 'value'
                               ,  plot(()->NULL, 1 .. 4, -1 .. 1
                                       , 'view' = [1..4, -1..1]
                                       , 'labels=[a,b]', 'gridlines'=true)
                              );

    npts := 300:
    M := Matrix(npts,2);

    UpdateM := proc(M,a,b,n)
    local i,phi,r,theta;
        for i to n do
            phi := b - Pi + 2*Pi*i/n;
            r := cos(phi)/a;
            theta := sin(phi)/b;
            M[i,1] := r*cos(theta);
            M[i,2] := r*sin(theta);
        end do;
        0;
    end proc:

    Plt := plots:-polarplot(M,
                            'coordinateview'=[0..1,-2*Pi..2*Pi],
                            'color'='RGB'(A/8+abs(B/4),abs(B/2-A/8),2/3-abs(A/8-B/2)),
                            'thickness'=2);


    ModuleApply := proc()
    local A,B,plt;

        A := DocumentTools:-GetProperty('Plot1','endx');
        B := DocumentTools:-GetProperty('Plot1','endy');

        DocumentTools:-SetProperty('Label0','caption',
                                   sprintf("%a",
                                           evalf[3](A)),
                                   'refresh'=true);

        DocumentTools:-SetProperty('Label1','caption',
                                   sprintf("%a",
                                           evalf[3](B)),
                                   'refresh'=true);
        evalhf(UpdateM(var(M),A,B,npts));
        plt := subsop([1,1]=convert(M,listlist), Plt);
        DocumentTools:-SetProperty('Plot0', 'value',plt, 'refresh'=true);
    end proc:

end module:

@Alejandro Jakubi 

The actual notation used where I first saw this, ("Concrete Mathematics", by Knuth, Pasternak, ...) is that

[ boolean expression] = 1 if boolean is true, else 0. 

It is handy when manually simplifying sums. Iverson, if I recall correctly, is the inverter of APL, which brought a lot of interesting notation.

@Alejandro Jakubi 

The actual notation used where I first saw this, ("Concrete Mathematics", by Knuth, Pasternak, ...) is that

[ boolean expression] = 1 if boolean is true, else 0. 

It is handy when manually simplifying sums. Iverson, if I recall correctly, is the inverter of APL, which brought a lot of interesting notation.

@hirnyk 

A nicer way (equivalent, just less typing) to input your solution with diffs is

vars := indets(T,name):
eqs := map2(diff,T,vars):
fsolve(eqs);
First 77 78 79 80 81 82 83 Last Page 79 of 195