acer

32303 Reputation

29 Badges

19 years, 307 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

@nm My experiments indicate that it is not the fact that the nested procedure is anonymous that makes the difference to mint. But rather, it's the fact that the anonymous procedure is immediately, functionally applied that makes the difference to mint.

For example, I can apply an anonymous procedure using %, and mint reports as you'd expected. Or I can map an anonymous procedure across a list, say, and again mint reports as expected on the anonymous procedure. And those happen even if nested within another procedure. Eg,

foo := proc()
  local C1,y,x;
  map( proc()
         C1:= `tools/genglobal`(_C);
         sol:=y(x)=  C1;
       end proc, [ ]);
end proc:

For which my M2023.2 mint reports,

Nested Anonymous Procedure proc() on lines 3 to 6
  These global variables start with an _:  _C
  These local variables were assigned a value, but otherwise unused:  sol
  These local variables were not declared explicitly:  sol
Procedure foo() on lines 1 to 7
  These local variables were used but never assigned a value:  x, y

Apart from the aspects of whether the nested proc is assigned to some name (and what procname might produce, "unknown", etc...), I don't believe that its own behavior wrt locals, etc, differs according to whether it's anonymous or anonymous and immediately applied. Presuming that I've understood your followup points, I suspect that you're mainly just seeing a difference in what mint happens to report upon.

Your surfdata example worked properly up until Maple 2023.2. It doesn't work in Maple 2024.1.1 and 2024.2. I will submit a regression bug report.

But you can still work around that easily, by wrapping in plots:-display and passing the scaling option to that instead.

restart

N := 20; M := LinearAlgebra:-RandomMatrix(N, generator = rand(0 .. .2))

plots:-display(plots:-surfdata(M, 0 .. 1, 0 .. 1, labels = ["x", "y", "V"]), scaling = constrained, size = [600, 600])

Download Scaled_matrix_plot_with_axes_ac.mw

You can use custom tickmarks for the matrixplot approach.

restart; N := 20; M := LinearAlgebra:-RandomMatrix(N, generator = rand(0 .. .2))

plots:-matrixplot(N*M, labels = ["x", "y", "V"], scaling = constrained, axis = [tickmarks = [seq(i = evalf((i-1)/(N-1)), i = 1 .. N, (N-1)*(1/5))]], size = [400, 400])

Download Scaled_matrix_plot_with_axes_ac2.mw

Sometimes rendering of custom end-ticks can visually clobber each other, if the values are "long", upon manual rotation. (I've reported that previously...) So generally I prefer using surfdata to using matrixplot for such examples.

As far as the implicitplot command goes, the view option is not for specifying the ranges of the curves, in the sense of what data is used to compute them. It's just for specifying the limits of the axes and how far all features may extend visually (presuming they've been constructed to extend that far).

Your four can be done in a single call to implicitplot, so I've rolled them together. I've kept the order in which you had them, which denotes how they get visually layered (ie. the green appears on top).

ps. The implicitplot command is a relatively inefficient way to construct lines, though that's not really noticeable as a one-off. So I leave it as you have chosen it.

restart

l := 2*x+y+1 = 0; l1 := 4*x+2*y+2 = 0; l2 := 4*x+2*y-2 = 0; l3 := 4*x-2*y+6 = 0

2*x+y+1 = 0

4*x+2*y+2 = 0

4*x+2*y-2 = 0

4*x-2*y+6 = 0

plots:-implicitplot([l, l1, l2, l3], x = -2 .. 1, y = -2 .. 5, color = [black, red, blue, green], legend = [l, l1, l2, l3], thickness = [5, 1, 1, 1])


 

Download The_intersection_parallelism_and_coincidence_of_two_straight_lines_ac.mw

Your code mistakenly passed gridline as an option to the Explore command, rather than the plotting command that Explore is calling. Below, gridline is passed as an option to DensityPlot itself.

The range option of DensityPlot can be used to specify the horizontal range (domain). You could utilize this to force a common range for all the parameter values. I am not sure if that aspect is what was bothering you.

Explore(Statistics:-DensityPlot(Statistics:-RandomVariable(Normal(mu, sigma)),
                                range = -2-9 .. 2+9, gridlines),
        mu = -2 .. 2, sigma = 0.5 .. 3)

I couldn't quite figure out from your Question whether you wanted the left- and right sums plotted together, or whether you wanted one sequence after the other.

restart

with(Student:-Calculus1)

G := plot(x^2, x = -3 .. 3)

plots:-animate(proc (N) options operator, arrow; plots:-display(RiemannSum(x^2, x = 0 .. 2, method = right, output = plot, partition = trunc(N), caption = ""), RiemannSum(x^2, x = 0 .. 2, method = left, output = plot, partition = trunc(N), caption = "", boxoptions = [filled = [color = "Burgundy"]]), title = (n = trunc(N))) end proc, [n], n = 1 .. 25, frames = 25, background = G, paraminfo = false, size = [800, 300])

NULL

Download S7_Riemann_Animation_Aire_ac.mw

You can tweak the look&feel as you wish.

Note that this overall plot is made up of several parts, each of which you can include or not. The plots:-display command combines them.

There are separate Help pages for the textplot, arrow, plot, and pointplot commands.

This is not the only way to construct something that looks like your image.

restart

randomize()

a := evalf[2]((rand(3 .. 4.0))()); b := evalf[2]((rand(0 .. 3.0))())

3.4

1.9

opts := thickness = 2, linestyle = dash; plots:-display(plot([x, b, x = -1.5 .. 4.5], color = blue, opts), plot([a, y, y = -1.5 .. 3.5], color = orange, opts), plottools:-arrow([a, 3.5], [a, 3.8], 0., .17, .8, color = orange), plottools:-arrow([a, -1.6], [a, -1.9], 0., .17, .8, color = orange), plottools:-arrow([4.5, b], [4.8, b], 0., .17, .8, color = blue), plottools:-arrow([-1.5, b], [-1.8, b], 0., .17, .8, color = blue), plots:-textplot([a, b, sprintf("(%a,%a) \n", a, b)], align = [above, left]), plots:-textplot([a, 4.0, x = a]), plots:-textplot([4.9, b, y = b], align = right), plots:-pointplot([[a, b]], symbol = solidcircle, symbolsize = 20), view = [-2 .. 5, -2.5 .. 4.5])

 

 

Download xa_yb_plot_ac.mw

An example is,

    -(signum(n)-1)/2

plot( -(signum(n)-1)/2, n=-10..10,
       thickness=6, size=[500,100], axes=box );


ps. Of course you could also write that as (1-signum(n))/2

Copy&Pasting from pretty-printed 2D Output seems like a mistake to me. Why not construct your string as you want it, and then line-print it, and then Copy&Paste from that.

You can line-print your string, intead of pretty-printing it as 2D Output.

When line-printed, the escaped backslashes are displayed as in the actual string.

You can have your procedure itself do the line-printing (in addition to returning the string). Or you can line print the result afterwards.

You can line-print using either the lprint or printf commands.

For example,

restart;

MyTableElement2 := proc(L::list(nonnegint))
  ## L will have only two elements
  local M, x, y, res;
  M:=L;
  x:=convert(M[1],string);
  y:=convert(M[2],string);

  res :=  cat("\\begin{tabular}{c} ",x," \\\\ \\hline ",y," \\end{tabular}");

  printf("%a", res);

  return res;

end:

 

out := MyTableElement2([2,3]);

\\begin{tabular}{c} 2 \\\\ \\hline 3 \\end{tabular}

"\begin{tabular}{c} 2 \\ \hline 3 \end{tabular}"

 

lprint( out );

\\begin{tabular}{c} 2 \\\\ \\hline 3 \\end{tabular}


Download lineprinted_string.mw

The usual way to handle this is to utilize the global name on the lhs of the equation. Utilizing single right-quotes protects against the case that the global name might have been assigned a number.

restart

plots:-setoptions(size=[400,200]);

ecdf := proc(S, {color::string:="blue", thickness::posint:=1})
  local i;
  local N   := numelems(S):
  local M   := sort(S):
  local opt := [':-color'=color, ':-thickness'=thickness]:
  plots:-display(
    plot([ seq(op([[M[i], (i-1)/N], [M[i], i/N], [M[i+1], i/N]]), i=1..N-1) ], opt[])
    , plot([ [M[N], (N-1)/N], [M[N], 1] ], opt[])
    , plot([ [M[N], 1], [(max+(max-min)*0.2)(S), 1] ], opt[], linestyle=3)
    , plot([ [M[1], 0], [(min-(max-min)*0.2)(S), 0] ], opt[], linestyle=3)
  )
end proc:

S := Statistics:-Sample(Uniform(0, 1), 10):

ecdf(S)

ecdf(S, color="red", thickness=3)

color := 99; thickness := -4;

99

-4

ecdf(S, 'color'="green", 'thickness'=5)

 

Download ecdf_ac.mw

Now let's check,

maplemint(ecdf);
Procedure ecdf( S, { color::string := "blue", thickness::posint := 1 } ) 
  These names were used as global names but were not declared:  linestyle
  These local variables were used but never assigned a value:  i

Aha. That's informing us that we should also be cautious about the (unprotected) global name linestyle. We should also single left-quote that in the procedure's code, ie. replace with 'linestyle'. Otherwise it'd break if we assigned some values to the global name.

restart

with(LinearAlgebra)

A := `<,>`(`<|>`(-2*`&omega;__0`^2, `&omega;__0`^2), `<|>`(`&omega;__0`^2, -`&omega;__0`^2))

AA := subs(`&omega;__0` = 3, A)

Matrix(%id = 36893628142202658316)

evalf([Eigenvectors(AA)])

[Vector[column](%id = 36893628142202646388), Matrix(%id = 36893628142202638332)]

NULL

S := AA+3.43769410*IdentityMatrix(2)

Matrix(%id = 36893628142202635196)


Suppose you thought that you'd compute the RREF of S.

When you get to this stage below, what would you do? Would you state
that the bottom row was effectively all zero? Or would you divide
by the diagonal entry -1.728...e-9 to get a 1 on the diagonal?

This is an example of why it's not appropriate to utilize exact linear-algebra
algorithms for floating-point examples.

LUDecomposition(S, output = U)

Matrix(%id = 36893628142202633860)


Maple knows that it should not estimate the rank of floating-point Matrix S
using some inappropriate approach such as counting the non-zero rows
of an ill-computed RREF. Instead, it will consider how many singular-values
of S are close enough to its largest singular value.

Rank(S)

1

NULL


Let's compute the null-space of S. Maple will do this by utilizing a singular-value
decomposition, to get singular-vectors.

NullSpace(S); map(proc (V) options operator, arrow; V/V[2] end proc, %)

{Vector[column](%id = 36893628142202623748)}


In short, floating-point linear-algebra is done with different (suitable) algorithms.
The algorithms for exact linear-algebra are not all appropriate for floating-point
problems. (This distinction holds for other areas of math, not just linear-algebra.)

See also Computation section here. See also Rank in terms of singular values
section of the same page.
 

Download evcalc_ac.mw

Here is one way, using assumptions and the generated inert integral form. Note that it avoids doing,
     PDF(Dist, t) assuming 0 < t, t < 2

You could, of course, programmatically generate the sequence of conditions and `assuming` calls, given just the splitting points [0,2]. That would be straightforward and easy.

restart

kernelopts(version)

with(Statistics)

`Maple 2023.2, X86 64 LINUX, Nov 24 2023, Build ID 1762575`

fx1 := piecewise(t < -1, 0, And(t >= -1, t <= 1), 2*sqrt(-t^2+1)/Pi, t > 1, 0)

fx2 := piecewise(t < -1, 0, And(t >= -1, t <= 1), 2*sqrt(-t^2+1)/Pi, t > 1, 0)

X1 := RandomVariable(Distribution(PDF = unapply(fx1, t)))

X2 := RandomVariable(Distribution(PDF = unapply(fx2, t)))

Dist := abs(X1-X2)

ans :=

piecewise(t<0,
          `assuming`([simplify(value(PDF(Dist, t, inert)))], [ t<0 ]),
          t>0 and t<2,
          `assuming`([simplify(value(PDF(Dist, t, inert)))], [ t>0 and t<2 ]),
          t>2,
          `assuming`([simplify(value(PDF(Dist, t, inert)))], [ t>2 ])
         );

ans := piecewise(t < 0, 0, 0 < t and t < 2, (4*((t^2+4)*EllipticE((-2+t)/(t+2))-4*EllipticK((-2+t)/(t+2))*t))*(t+2)/(3*Pi^2), 2 < t, 0)

evalf(eval(ans,t=1.3));

.2558978187

PDF(Dist, 13/10, numeric);

.2558978190

plot(x->PDF(Dist, x, numeric), 0 .. 2, style=point,
     thickness=3, numpoints=15, size=[500,200]);

plot(ans, t=0 .. 2,
     thickness=3, size=[500,200]);

Download AbsDiff_ac.mw

Your Document contains a comment, "It sure looks like the righthand and lefthand sides of each expression are the same." [emphasis, mine]

You've printed simplify(result), and indeed both side of that are the same. You're visually comparing the two sides after simplify, but your code compares them without simplifying.

You can achieve your goal here with, say,
    result := simplify(eval(subs({x = sols[i]}, 'diff(x, t)' = A . x)))

evs_equal_ac.mw

Note that it can happen (in some other, possibly rare, example) that two expressions F,G can simplify to different forms even though simplify(F-G) becomes zero. In that case you can more strongly test simplify of the difference, ie. rhs-lhs.

From the main menubar,

  Insert -> Section

In my Maple 2024, a keyboard acceleration for that is Ctrl .   (Control period)

If the mouse focus in inside a Section then this action inserts a subsection below the cursor focus.

The following finds a solution with both fsolve (at reduced Digits) and DirectSearch, using procedures that return unevaluated if passed (only) symbolic arguments.

I used Maple 2023 (as did you, I believe).

shooting_question_ac.mw

It's impossible to state exactly which mistakes you've made, since you haven't attached your actual worksheet or full code. (In future Questions, you could do that using the green up-arrow in the Mapleprimes editor's menubar.)

But three kinds of potential problem appear in what you've shown:

1) You may have used = (equals sign) instead of := (colon equals)
   when assigning to y .  The former forms an equation, while the latter
   does an assignment.

2) You appear to have square brackets in the definition of y. Those kind of
   brackets denote lists in Maple. Only round brackets are expression delimiters/groups.

3) Your y expression has f__c, f__m with double underscores, but your parameter-values
   list appears to have f_c, f_m with just one underscore. Those need to
   match, for substitution.

 

y := (1 + M*cos(2*Pi*f__m*t))*A*sin(2*Pi*f__c*t)

(1+M*cos(2*Pi*f__m*t))*A*sin(2*Pi*f__c*t)

plot( eval(y, [ M = 0.5, A = 1, f__m = 2, f__c = 10]),
     t = 0 .. 1,
     gridlines,
     size = [600,400]);

Download pl_syntax_01.mw

First 6 7 8 9 10 11 12 Last Page 8 of 336