Carl Love

Carl Love

28070 Reputation

25 Badges

13 years, 31 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

Here's my improved version of Kitonum's ContoursWithLabels. Now there's no specific variable name dependence, and I've added separate keyword options to control each plot.

restart:

ContoursWithLabels:= proc(
     Expr::algebraic,
     Range1::(name= range(realcons)), Range2::(name= range(realcons)),
     {contours::{posint, {set,list}(realcons)}:= 8},
     {ImplicitplotOptions::{list,set}({name, name= anything}):= NULL},
     {GraphicOptions::{list,set}({name, name= anything}):= NULL},
     {TextOptions::{list,set}({name, name= anything}):= NULL},
     {Coloring::{list,set}({name, name= anything}):= NULL}
)
local r1, r2, f, L1, h, S1, P, r, M, C, T, p, p1, m, n, i;
     f:= unapply(Expr, lhs~([Range1,Range2]));
     if contours::posint then
          r1:= rand(convert(rhs(Range1), float));
          r2:= rand(convert(rhs(Range2), float));
          L1:= select(type, (f@op)~({seq([r1,r2](), i= 1..205)}), realcons);
          h:= (L1[-6]-L1[1])/contours;
          S1:= [seq(L1[1]+h/2+h*(n-1), n= 1..contours)]
     else #contours::{set,list}(realcons)
          S1:= [contours[]]
     end if;
     userinfo(1, ContoursWithLabels, print('Contours' = evalf[2](S1)), `\n`);
     r:= k-> rand(20..k-20);
     for C in S1 do
          P:= plots:-implicitplot(
               Expr = C, Range1, Range2,
               gridrefine= 3, ImplicitplotOptions[]
          );
          for p in [plottools:-getdata(P)] do
               p1:= convert(p[3], listlist);
               n:= nops(p1);
               if n < 500 then
                    m:= `if`(40 < n, r(n)(), round(n/2));
                    M[`if`(40 < n, [p1[1..m-11], p1[m+11..n]], [p1])[]]:= NULL;
                    T[[p1[m][], evalf[2](C)]]:= NULL
               else
                    h:= trunc(n/2);
                    m:= r(h)();
                    M[p1[1..m-11], p1[m+11..m+h-11], p1[m+h+11..n]]:= NULL;
                    T[[p1[m][], evalf[2](C)], [p1[m+h][], evalf[2](C)]]:= NULL
               end if
          end do
     end do;
     plots:-display(
          [`if`(
               Coloring = NULL,
               NULL,
               plots:-densityplot(Expr, Range1, Range2, Coloring[])
          ),
          plot([indices(M, 'nolist')], color= black, GraphicOptions[]),
          plots:-textplot([indices(T, 'nolist')], TextOptions[])
         ], 'axes'= 'box', 'gridlines'= false, _rest
     )
end proc:

 

Example:

PP:=0.3800179925e-3*exp(-0.6065722618e-3*(x-29.51704536)^2+(0.6650093594e-3*(x-29.51704536))*(a-12.94061928)-0.1106850312e-2*(a-12.94061928)^2);

0.3800179925e-3*exp(-0.6065722618e-3*(x-29.51704536)^2+0.6650093594e-3*(x-29.51704536)*(a-12.94061928)-0.1106850312e-2*(a-12.94061928)^2)

infolevel[ContoursWithLabels]:= 1:

ContoursWithLabels(
     PP, x= -20..20, a= -20..20, contours= {seq(1e-4..4e-4, 5e-5)},
     Coloring= [colorstyle= HUE, colorscheme= ["Cyan", "Red"], style= surface],
     TextOptions= [font= [HELVETICA,BOLD,7], color= blue],
     ImplicitplotOptions= [gridrefine= 4],
     GraphicOptions= [thickness= 0],
     title= "         My contour plot\n",
     labelfont= [TIMES,BOLDITALIC,16], axesfont= [HELVETICA,8],
     size= [600,600]
);

ContoursWithLabels:

Contours = [0.1e-3, 0.15e-3, 0.20e-3, 0.25e-3, 0.30e-3, 0.35e-3, 0.40e-3]


 


Download ContoursWithLabels.mw

plots:-polygonplot3d([A1, A2, A3]);

Here's an easier way for your whole code:

block:= ListTools:-Reverse~(Bits:-Split~(convert(message, bytes), bits= 8)):
Block:= Matrix(block):
Block[..,3..7]:= 1 -~ Block[..,3..7]:
cblock:= convert(Block, listlist);

Depending on what your next operation is, it may be better to skip the last command and just keep it in Matrix form.

 

Here's a variant that uses the special ways that Matrices can be indexed:

SelectRealRows:= (M::Matrix)-> M[remove(i-> has(M[i,..], I), [$1..op([1,1],M)]), ..];

The reason is that filled is an option to the plot command, not an option to the PLOT data structure. In other words, plot does some computation to construct the polygon to fill; it's not the plot renderer that does it.

Here's a workaround. This should work for any 2D plot with a single curve. (But, mind you, this is quick-and-dirty; I only tested it on DensityPlots.)

FillPlot:= proc(P::specfunc(PLOT))
local
     C:= indets(P, specfunc(CURVES))[1],
     A:= convert(op(1,C), listlist)
;
     PLOT(
          POLYGONS(
               [[A[1][1],0], A[], [A[-1][1],0], [A[1,1],0]],
               LEGEND("__never_display_this_legend_entry"),
               STYLE(PATCHNOGRID),
               TRANSPARENCY(0.4),
               indets(C, specfunc(COLOUR))[]
          ),
          op(P)
     )
end proc:    

FillPlot(DensityPlot(X));       


 

To retain the symbolic constants, use solve instead of fsolve.

There is a way to create true symbolic constants, but you can't get fsolve to express solutions in terms of them; fsolve is strictly numeric.

Two ways. In the first, change g to

g:= proc(t)
local j;
     if not t::numeric then return 'procname'(t) end if;

    ... the rest of g ...

And change the plot command to

plot([g(t)[1], g(t)[2], t= 0..1]);

The second way is to simplify everything:

f0:= t-> (t, 3.9*t*(1-t)):
IFS:= (i,x,y)-> piecewise(i=0, [y,x], i=1, [x,y+1], i=2, [x,y]+~1, i=3, [2-y,1-x])[]/2:
g:= t-> IFS(trunc(4*t), f0(frac(4*t))):
plot([g(t)[1], g(t)[2], t= 0..1]);

Why have you put m3 in square brackets? That's the problem.

Also with*matrix and with*linearalgebra don't mean anything. Get rid of those.

Try changing Do(HD= HuffmanCoding(HT)) to
Do(HD= [HuffmanCoding(HT)]).

The reason is that I doubt that Do can handle the assignment of an expression sequence with more than one term, which is what the output of HuffmanCoding will be.

Here's an example:

restart:

 

First I'll choose some random words as our example strings.

L||(1..3):= 'combinat:-randcomb(EssayTools:-GetWordList(), 10)' $ 3:

 

Construct the DataFrame.

ds:= DataFrame(<<L2> | <L3>>, rows= L1, columns= [$1..2]);

ds := Matrix(10, 3, {(1, 1) = ``, (1, 2) = 1, (1, 3) = 2, (2, 1) = "alphard's", (2, 2) = "gathering's", (2, 3) = "understatement's", (3, 1) = "fronde", (3, 2) = "recharges", (3, 3) = "pterodactyl's", (4, 1) = "estimations", (4, 2) = "headlock", (4, 3) = "axial", (5, 1) = "cannoned", (5, 2) = "balded", (5, 3) = "pickaxed", (6, 1) = "num5", (6, 2) = "underlay", (6, 3) = "stewing", (7, 1) = "pagination's", (7, 2) = "quizzed", (7, 3) = "curmudgeon", (8, 1) = "elma's", (8, 2) = "periwinkle", (8, 3) = "outerwear's", (9, 1) = "keller", (9, 2) = "changchun", (9, 3) = "orion's", (10, 1) = `...`, (10, 2) = `...`, (10, 3) = `...`})

Select all rows with a column 1 entry greater than "n":

ds[ds[..,1] >~ "n"];

Matrix([[``, 1, 2], ["fronde", "recharges", "pterodactyl's"], ["num5", "underlay", "stewing"], ["pagination's", "quizzed", "curmudgeon"], ["elma's", "periwinkle", "outerwear's"], ["overeats", "wahhabi", "coaxial"], ["shopping's", "sideswipes", "reformation's"]])

Select all rows whose column 2 entry ends with "'s"

ds[(w-> evalb(w[-2..-1]="'s"))~(ds[..,2])];

Matrix([[``, 1, 2], ["alphard's", "gathering's", "understatement's"], ["fronde", "recharges", "pterodactyl's"], ["elma's", "periwinkle", "outerwear's"], ["keller", "changchun", "orion's"], ["shopping's", "sideswipes", "reformation's"]])

 

 

Download DataFrame_string_filter.mw

However, it's a disappointment that the commands select, remove, and selectremove haven't been overloaded to work with DataSeries and DataFrames.

Here's an easy example that you should be able to execute on your own computer.

restart:

filename:= FileTools:-JoinPath(["example/address.json"], base= datadir);

"C:\Program Files\Maple 2016\data\example/address.json"

T:= JSON:-ParseFile(filename, output= table);

table( [( "phoneNumbers" ) = [table( [( "type" ) = "local", ( "number" ) = "+1 (519) 747-2373" ] ), table( [( "type" ) = "tollfree", ( "number" ) = "+1 (800) 267-6583" ] ), table( [( "type" ) = "fax", ( "number" ) = "+1 (519) 747-5284" ] )], ( "companyName" ) = "Maplesoft", ( "address" ) = table( [( "city" ) = "Waterloo", ( "country" ) = "Canada", ( "streetAddress" ) = "615 Kumpf Drive", ( "province" ) = "ON", ( "postalCode" ) = "N2V 1K8" ] ), ( "founded" ) = 1988 ] )

 

The following transformation makes the table easier to visualize. (This command is very advanced, and I don't expect you to understand it.)

(T-> subsindets(subsindets(`<,>`(op(T)), table, thisproc), list, `<,>`))(T);

Vector(1, {(1) = Vector(4, {(1) = "phoneNumbers" = (Vector(3, {(1) = Vector(2, {(1) = "type" = "local", (2) = "number" = "+1 (519) 747-2373"}), (2) = Vector(2, {(1) = "type" = "tollfree", (2) = "number" = "+1 (800) 267-6583"}), (3) = Vector(2, {(1) = "type" = "fax", (2) = "number" = "+1 (519) 747-5284"})})), (2) = "companyName" = "Maplesoft", (3) = "address" = (Vector(5, {(1) = "city" = "Waterloo", (2) = "country" = "Canada", (3) = "streetAddress" = "615 Kumpf Drive", (4) = "province" = "ON", (5) = "postalCode" = "N2V 1K8"})), (4) = "founded" = 1988})})

To extract a particular datum:

T["phoneNumbers"][1]["number"];

"+1 (519) 747-2373"

T["address"]["city"];

"Waterloo"

T["founded"];

1988

 

Download JSON.mw

If you want further explanation of any of the syntax (except the part that I said was advanced), let me know.

I'm nearly certain at this point, so I'll make this an Answer:

I think that the last statement of OrderB is of the form print(x). You need to change that to either return(x), return x, or simply x. It doesn't matter which one. A procedure should never use print to return its final value. The purpose of print is to display supplementary information on the screen.

The differential equations and the initial conditions need to be in a single set. So, you need to

dsolve(IVP union ICs, numeric);

Delta:= D[2,1,1] + D[2,1] + D[2,3,3] + D[1,1] + D[3,1,1]:

To use it:

Delta(f)(x,y,z);

Here's a workaround.


restart:

assume(k::positive);

I1:= int(exp(-I*k*x)/cosh(x), x= -infinity..infinity):

I2:= evalc(I1);

int(cos(k*x)/cosh(x), x = -infinity .. infinity)

The integrand is obviously even, so...

I3:= 2*eval(I2, -infinity= 0);

Pi/cosh((1/2)*Pi*k)


Download cosh_integral.mw

Obviously the result is true for negative k also.

First 226 227 228 229 230 231 232 Last Page 228 of 395