acer

32328 Reputation

29 Badges

19 years, 317 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@wswain You have misunderstood my subsindets calls, I'm afraid.

Let's look at this call:

   subsindets(convert(Array3[1, 2..], list), string, u -> u[5..])

The first argument is convert(Array3[1, 2 .. ()], list) , which produces a list.

The second argument, string, is not a transformer. It is a type, that subsindets uses to distinguish which subexpressions to transform.

The third argument, u -> u[5..] is the transformer.

There is no fourth argument there, ie. none like rest in the Calling Sequences on the subsindets Help page.

I could see that the only strings in the first row were the ones with the substring prefix "RPM " which I wanted to remove. I could also have used StringTools:-Drop, or a few other StringTools commands. It seemed to me that indexing was simpler. Eg,

ee := "RPM 101 - 200":
ee[5..];

             "101 - 200"

StringTools:-Drop(ee, 4);

             "101 - 200"

Contrary to your followup query's claim, I did not convert the entries of Array3[1, 2..] to strings. They already were strings.

I could also have used map directly on the entries of that particular sub-Array, instead of having subsindets target its subexpressions of type string (which happened to be all that sub-Array's entries, anyway). Eg, using that Array3, these last three lines accomplish the same thing.

L := convert(Array3[1,2..],list):
subsindets(L, string, u->u[5..]);
map(u->u[5..], L);
map(`?[]`, L, [5..]);

There are often several ways to accomplish manipulations. I didn't think much about which might be best here -- whatever "best" means.

Your example is small, and you might not need the code to scale up. At some point you may choose to balance between legibility, flexibility, and efficiency.

[edit] I am not a big fan of arcane and slick functional programming if the efficiency needs don't demand it. I don't think that it's highly legible for newcomers to Maple, and it can be difficult for them to debug.

@ceight1 Here is one way, which you adjust to other examples.

The embedded Table looks better in the actual Maple GUI than it does inlined in this forum.

Slope Fields

 

restart

interface(rtablesize = 50)

ode := diff(y(x), x) = -2*x*y(x)+1

diff(y(x), x) = -2*x*y(x)+1

ic := y(0) = 1

y(0) = 1

exactsol := dsolve({ic, ode})

y(x) = ((1/2)*Pi^(1/2)*erfi(x)+1)*exp(-x^2)

exactsolfunc := unapply(rhs(exactsol), x)

proc (x) options operator, arrow; ((1/2)*Pi^(1/2)*erfi(x)+1)*exp(-x^2) end proc

NULL 

f := proc (x, y) options operator, arrow; -2*x*y+1 end proc

proc (x, y) options operator, arrow; -2*y*x+1 end proc

x, y := 'x', 'y'; x[0] := 0; y[0] := 1; h := 0.5e-1; x_end := .65; N := ceil((x_end-x[0])/h)

13

for n to N do x[n] := n*h; y[n] := y[n-1]+h*f(x[n-1], y[n-1]) end do

UseHardwareFloats := false; xdat := `<,>`(convert(x, list)); ydat := `<,>`(convert(y, list)); exactdat := map(exactsolfunc, xdat); abserr := map(abs, exactdat-ydat); alldat := `<,>`(`<|>`(x__n, y__n, "Actual Value", "Absolute Error"), `<|>`(xdat, ydat, exactdat, abserr))

Matrix(%id = 18446884663419907238)

 

DocumentTools:-Tabulate(alldat, width = 500, widthmode = pixels, fillcolor = proc (M, i, j) `if`(i = 1, "LightGray", "White") end proc)
``

 

`#msub(mi("x"),mi("n"))`

`#msub(mi("y"),mi("n"))`

Actual Value

Absolute Error

0

1

1

0.

0.5e-1

1.05

1.047419872

0.2580128e-2

.10

1.094750

1.089385826

0.5364174e-2

.15

1.133802500

1.125521358

0.8281142e-2

.20

1.166795462

1.155540473

0.11254989e-1

.25

1.193459553

1.179252227

0.14207326e-1

.30

1.213623064

1.196562851

0.17060213e-1

.35

1.227214372

1.207475440

0.19738932e-1

.40

1.234261869

1.212087271

0.22174598e-1

.45

1.234891394

1.210584886

0.24306508e-1

.50

1.229321281

1.203237166

0.26084115e-1

.55

1.217855217

1.190386665

0.27468552e-1

.60

1.200873180

1.172439530

0.28433650e-1

.65

1.178820789

1.149854370

0.28966419e-1

 

HELP_CODE_ac_tab.mw

@wswain At the very least you should explain what you mean by,

     ...RPM range text =  "0-100, 101-200, 201-300", etc.  for each
     bin and rotated vertical to fit.

Keep in mind that you haven't even explained what the two axes of your plot are supposed to represent, if the above quote truly relates to axis labeling. If it instead relates to some kind of colorbar legend for the ranges of values of the data then please indicate as much.

Providing code that reproduces the output or plots in your Question is usually helpful, often useful to those answering, and polite.

Upload and attach a worksheet that contains code to reproduce.

Why the need to use typeset? Does it not render similarly without that?

@Carl Love When the OP started with his queries [1, 2], there was no mention of LaTeX in the Question bodies. And so my previous responses [1, 2] were only about printing in the Maple GUI, and not about LaTeX export.

I have previously had some small success in using an XML add-on package in LaTeX, to cope with some marked up "TypeMK" Maple names. But some entities were a pain. I don't think that I'd go there to make it easier.

@BrettKnoss The second example doesn't need the DataFrame, I just threw it in at the end. It only needs M, a Matrix which stores the data.

The Matrix M gets extended at each iteration by use of the round-bracket "programmer's indexing". The seems simpler than Append on a DataFrame.

@Carl Love From the OP's edited description it reads as if the bug was in his own code, which had a mismatched type declaration on the local variable to which the FetchAll result were assigned.

@DJJerome1976 It's always better to explain what you're really after up front.

restart;

temp := "This is the %s object with a certain property.":

sprintf(temp, convert(46,ordinal));

"This is the 46th object with a certain property."

nprintf(temp, convert(46,ordinal));

`This is the 46th object with a certain property.`

nprintf(`#mn(%a);`,sprintf(temp, convert(46,ordinal)));

`#mn("This is the 46th object with a certain property.");`

Download printf_s.mw

@matviiv10 Please don't post followup queries about this code in a separate Question.

@tomleslie This inlines here, for me.

It might be due to supplying the size option. (I usually/always use that, for arrays of plots, and inlining those here usually/always works for me.)

restart;
N:=15:
# f:=(x,y) -> (Re,Im)(sin(x+I*y):
f:=(x,y) -> (Re,Im)(ln(1+I*(1+x+I*y)^2/9)):
P:=plot([seq([x,y,x=0..1],y=0..1,1/N), seq([x,y,y=0..1],x=0..1,1/N)]):
plot([seq([f(x,y),x=0..1],y=0..1,1/N), seq([f(x,y),y=0..1],x=0..1,1/N)],scaling=constrained):

# Using plottools:-transform
with(plottools):with(plots):
F := transform((x, y) -> [f(x,y)]):

plots:-display(<P|F(P)>, scaling=constrained, size=[400,400]);

 

 

 

 

 

 

Download Vector_of_plots_size.mw

I wish that they'd fix the backend to utilize PNG instead of JPG/other for the exported plot images, and also to not render gridlines when the plot structure doesn't contain it.)

@Carl Love I don't disagree with you.

I was wondering why Tom removed the units from the integration range, while not otherwise adjusting for that dimension.

I figured I might possibly have misinterpreted the goal, which was not stated in words -- only because I didn't really understand the OP's first attempt. However the OP's two attempts did both have units on the integration range, so originally I figured that the intention was something in units A^2*s.

What do you want to happen if the parameter `a` value is changed, between computing the various xphi values and any subsequent call to `k`?

Do you want the calls to `k` to get the prior values for xphi, or to recompute using the later parameter setting?

@tomleslie It wasn't clear (to me, at least) whether the answer is supposed to be in terms of units A^2 or A^2*s. Perhaps the target answer was supposed to be obvious?!

@mmcdara The padding value is in pixels, afaik. (Well, pixels in the usual sense, ie. at 100% zoom. Let's not get into dot-pitch.)

The example mostly works for me in my Maple 2020 GUI. Some things work imperfectly when rendered by this site's considerably older backend engine.

First 145 146 147 148 149 150 151 Last Page 147 of 591