acer

32303 Reputation

29 Badges

19 years, 307 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@mmcdara I see, using union was just an experiment.

It's very handy that the HTML entities begin with ampersand (&), so that they can be used in this way. I showed you `≅`, but as dharr mentioned you can used others, many available from the Palettes. Your choice.

A few more notes, just in case. I'm still not quite sure whether you might have wanted to use T, literally. If so, please see the attached.

note. The infix notation is not a consequence of being a binary operator, and that's true mathematically as well as in Maple. Being a binary operator brings extra conditions to a binary function, eg. same domain for each argument, and (depending on who you read) same codomain. But infix notation is not a requirement. (eg. exponentiation). It just happens that some common algebraic operations have infix notation for operators.

restart;

 

`print/T` := proc(x,y)
   uses Typesetting;
   mrow(Typeset(x), mo("⁢"),
        mo("T",fontweight="bold"), mo("⁢"),
        Typeset(y));
end proc:

 

T(a,b);

T(a, b)

T(sqrt(s),t);

T(s^(1/2), t)


You could also get infix input, if you're ok with resorting to
using the &T infix operator.

alias(T=`&T`):
`print/&T`:=`print/T`:

 

a &T b;

T(a, b)

`&T`(a, b)

T(a, b)

Download infix_note.mw

note: I don't see & neutral operators in use so much any more. Physics has its sophisticated own stuff. Once upon a time, evalm used &* commonly for denoting noncommutative matrix multiplication.

@mmcdara Here are a few notes (my interpretations, right or wrong) on trying to force the harder order of the integrations, with nested 1D methods.

Using Maple 2024.1.


We can force specific methods for nested 1D numeric
integrations. We can experiment with doing that the
with the harder order of the variables.

 

This can be a tricky thing to balance.

note: I've put each block in a single execution group,
with restart. That is because even with,
   forget(evalf); forget(`evalf/int`);
I've sometimes seen "remembered" results that differ
from a clean re-run, which is awkward.

restart;
G := proc(x,y)
  if not ( x::numeric and y::numeric ) then
    return 'procname'(x,y);
  else
    piecewise(y<=1/(1+sinh(2*x)*ln(x)^2), 1);
  end if;
end proc:
CodeTools:-Usage(
  evalf[15](Int(Int(G(x,y), x=0.8..3,
                    epsilon=1e-12, method=_d01ajc),
                y=0..3, epsilon=1e-5, method=_Gquad))
);

memory used=53.43MiB, alloc change=34.00MiB, cpu time=1.68s, real time=1.68s, gc time=15.81ms

.676480297813865

 


If the inner integral cannot always succeed then the
outer integration can fail (sometimes quickly).

restart;
G := proc(x,y)
  if not ( x::numeric and y::numeric ) then
    return 'procname'(x,y);
  else
    piecewise(y<=1/(1+sinh(2*x)*ln(x)^2), 1);
  end if;
end proc:
CodeTools:-Usage(
  evalf[15](Int(Int(G(x,y), x=0.8..3,
                    epsilon=1e-13, method=_d01ajc),
                y=0..3, epsilon=1e-5, method=_Gquad))
);

memory used=2.47MiB, alloc change=0 bytes, cpu time=35.00ms, real time=35.00ms, gc time=0ns

Int(Int(G(x, y), x = .8 .. 3.), y = 0. .. 3.)


If the outer integration's accuracy request is tighter, it
may succeed, but more slowly.

restart;
G := proc(x,y)
  if not ( x::numeric and y::numeric ) then
    return 'procname'(x,y);
  else
    piecewise(y<=1/(1+sinh(2*x)*ln(x)^2), 1);
  end if;
end proc:
CodeTools:-Usage(
  evalf[15](Int(Int(G(x,y), x=0.8..3,
                    epsilon=1e-12, method=_d01ajc),
                y=0..3, epsilon=1e-6, method=_Gquad))
);

memory used=188.99MiB, alloc change=36.00MiB, cpu time=5.62s, real time=5.62s, gc time=70.51ms

.676479990641045


If the outer integration's accuracy request is too tight, it
may fail, since the inner integral is not (relatively)
accurate enough.

restart;
G := proc(x,y)
  if not ( x::numeric and y::numeric ) then
    return 'procname'(x,y);
  else
    piecewise(y<=1/(1+sinh(2*x)*ln(x)^2), 1);
  end if;
end proc:
CodeTools:-Usage(
  evalf[15](Int(Int(G(x,y), x=0.8..3,
                    epsilon=1e-12, method=_d01ajc),
                y=0..3, epsilon=1e-8, method=_Gquad))
);

memory used=188.57MiB, alloc change=36.00MiB, cpu time=5.61s, real time=5.62s, gc time=71.51ms

Int(Int(G(x, y), x = .8 .. 3.), y = 0. .. 3.)


In my previous Answer I suggested using a bare piecewise instead
of a black-box (a proc that returns unevaluated for nonnumeric
x and y).

I suggested that only because I prefer to start off simply. But
in practice I find that I often move to a black-box to enforce
control of what `evalf/int` does internally.

Here we see that the first example above (success in 1.67 sec)
takes longer without the black-box veil, though here it happens
to get the very same result.

restart;
G := piecewise(y<=1/(1+sinh(2*x)*ln(x)^2), 1);
CodeTools:-Usage(
  evalf[15](Int(Int(G, x=0.8..3,
                    epsilon=1e-12, method=_d01ajc),
                y=0..3, epsilon=1e-5, method=_Gquad))
);

G := piecewise(y <= 1/(1+sinh(2*x)*ln(x)^2), 1, 0)

memory used=1.15GiB, alloc change=138.00MiB, cpu time=15.99s, real time=15.28s, gc time=1.25s

.676480297813865

 

 

Download integration_issue_ac3.mw

Changing the order of the bounds (ie. which is the "inner" integral) makes a huge difference here.  The other order took so long I interrupted it.

restart;

CodeTools:-Usage(
  evalf(Int(piecewise(y<=1/(1+sinh(2*x)*ln(x)^2), 1),
            [ y=0..3, x=0.8..3 ]))
);

memory used=217.60MiB, alloc change=132.00MiB, cpu time=2.67s, real time=2.59s, gc time=242.09ms

.6768400757


Download Integration_issue_ac2.mw

@Ditteon That first link is just to a youtube page. You don't need any Maplesoft login to watch it.

My Chrome browser lets me watch it without signing in to Google.

Is there a special reason for not using a bare piecewise?

restart;

C := piecewise(x>=0 and x<=1, 1, 0);

C := piecewise(0 <= x and x <= 1, 1, 0)

int(C, x=-1..2);

1

plot(C, x=-1..2, adaptive=true,
     thickness=3, size=[400,200]);

Download charfcn_plot_pw.mw

So that we can compare and double check suggestions, what version of Maple are you using?

Also, how many correct decimal digits do you need in the answer?

@segfault You should provide the actual example.

You might look at some of the approaches in these responses to these old postings: 1, 2, 3

note: Considerable portions of those approaches can now be done more straightforwardly, ie. in modern Maple. For example, using the background option of the plot command, using convert(plot(...),Image) rather than exporting a plot to an external temp file, etc. When I first used an image here, in the year 2012, even the ImageTools:-Embed command did not yet exist, so I had to first insert a Label Component manually.

How are you currently exporting your plots, for use in LaTeX?

What specific steps (mouse+GUI, or programmatic commands) are you using? What target file format? What resolution?

@paulmcquad For your examples, you can also use mmcdara's straightforward Answer.

@Kitonum I gave it a vote, and marked it as a favorite.

@erik10 Yes, the integrand has a singularity where z^2/(p^2*v__lin(z)^2) - 1, and is complex-valued for z making that expression negative.

For your positive data, at z=p*v__lin(z) .

Seismology_acc_ev_ac_ev_ac.mw

@erik10 So what is happening in your new sheet is that you are passing x(r) and y(r) to the plot command, and those evaluate to expressions involving theta(r).

But your procedure assigned to theta is not prepared to be called with symbolic r (ie. not an actual number). If you were to issue just theta(r) as a separate statement then you'd see the same error. So, those function calls passed to plot are evaluating prematurely.

One way around that is to use the so-called operator-form calling sequnce of the plot command, eg,
    plot([x, y, r__0 .. R], ...options)

Another way is to instead construct the theta procedure so that it returns unevaluated when called with a symbolic argument such as just a name. You could do that using MakeProcedure (unapply) with its numeric option, as I showed before for your Z__spline, etc. Or you could write it all out, which I do in the attachment.

I also add the numeric integration option epsilon=1e-5 here, which relaxes the accuracy tolerance for the theta computation (the outer integration). That makes your nested numeric integration faster, as I mentioned earlier that I suspected. It's now fast enough that you can get smooth adaptive plotting without too long a wait.

Seismology_acc_ev_ac.mw

@erik10 The adaptive=false option instructs the plot command to not do adaptive sampling of the domain. It makes it use an evenly spaced number of values in the domain.

The numpoints=N option instructs the plot command to use N values in the domain, initially. If adaptive=false then that means N evenly spread values, and otherwise it means N values initially in whichever adaptive sampling scheme it's using.

In other words, if one wants only N data points, evenly spaced, then one can supply,
   adaptive=false, numpoints=N
This is a way to know exactly how many evaluations of the function will be done, so is handy when it might be time consuming. When going this route I experiment to find the smallest number of values which make the curve appear smooth "enough". (Sometimes I start with N=3, as sanity-check experiment that things are working at all...)

Of course, an alternative is to use seq or Vector to get a specific number of evenly spaced data points. But I prefer to use the above options since if everything goes well or if I speed it up then I can just remove those options.

@erik10 You could use the MakeFunction (unapply) approach that I'd shown above:

Seismology_ac.mw

Or you could use an operator-form for your new integrand, as variantion on what I'd shown before for that kind of idea. (This variant now gains a slight inefficiency of a separate procedure construction for each call to theta, though in practice that can be relatively reasonable if the numeric quadrature is itself expensive enough.)

Seismology_acc.mw

[edit] I suspect that the final plot (of theta) might be computed faster if the epsilon tolerance were loosened on one of the (nested) numeric integrations. But for that you'd need to give up the pretty 2D integral look. I left it with non-adaptive plotting and a prettier integral, in these two worksheet attachments, and not too much of a wait.

ps. Often it's more useful to supply the background example up front.

pps. It's a good question, though, and has come up before. The "evalf-Int" routines fail to deal with the constructed interpolating function (an object) in as versatile a way as they do regular appliable procedures. I should make a(nother) bug report on it.

First 16 17 18 19 20 21 22 Last Page 18 of 591