epostma

1484 Reputation

19 Badges

15 years, 185 days
Maplesoft

Social Networks and Content at Maplesoft.com

Maple Application Center
I am the manager of the Mathematical Software Group, working mostly on the Maple library. I have been working at Maplesoft since 2007, mostly on the Statistics and Units packages and on contract work with industry users. My background is in abstract algebra, in which I completed a PhD at Eindhoven University of Technology. During my studies I was always searching for interesting questions at the crossroads of math and computer science. When I came to Canada in 2007, I had nothing but a work permit, some contacts at Maplesoft (whom I had met at a computer algebra conference a year earlier), and a plan to travel around beautiful Canada for a few months. Since Maplesoft is a company that solves more interesting math and computer science related questions than just about anywhere else, I was quite eager to join them, and after about three months, I could start.

MaplePrimes Activity


These are answers submitted by epostma

This idea has actually come up before, and we're looking into it.

Thanks for the suggestion!

On the other hand, if you need to do this programmatically, you could do it like this:

b := numer(a)/combine(frontend(expand, [denom(a)]), exp);

Note that I apply these constructs specifically to the denominator; if you need it to apply to the numerator as well, you can adjust it accordingly.

Hi Thomas,

I'm not sure which version of Maple you are using, but Maple 12 has a very powerful new system replacing stop_cond, called events. It allows for expressing the type of thing that you are interested in very naturally:

dsn := dsolve([D(D(x))(t)=-x(t), x(0)=0, D(x)(0)=1], numeric, events=[[[x(t), t > 4], halt]]):
plots:-odeplot(dsn, numpoints=2000);

This will nicely plot sin(t) till 2 Pi and give you the following warning:

Warning, cannot evaluate the solution further right of 6.2831854, event #1 triggered a halt

Note that dsolve did a pretty good job of finding the value of 2 Pi, which is 6.283185308 according to evalf with the standard setting of Digits=10.

The events system also allows for much more complicated events: you can set the values of the functions you're integrating, set discrete variables used in other events et cetera. I'd recommend a look at ?dsolve,events if you have Maple 12.

This reply is probably obsolete for now for Wolfie7873, the original author of the post, who has already indicated that goto is good enough for now, but I thought I'd just add this for future reference.

If you would be looking to replicate the switch/case statement found in other languages as closely as possible, so you have some literal constants a1, a2, a3 that you are comparing to, and you would want to use overload, then the most useful class of types would be the "identical" types - see type,identical. An example mirroring the initial construct in the post:

overload([
  proc(x :: identical(a1))
  option overload;
    b1;
  end,
  proc(x :: identical(a2))
  option overload;
    b2;
  end,
  proc(x :: identical(a3))
  option overload;
    b3;
  end])(a);

Now if you have really many cases, and care about efficiency, there is usually some structure to the set of possible values for a: at least an ordering or so. Then this is certainly a bad way to do it: it would simply try whether a is equal to a1 first, then a2, et cetera. What you'd want to do is use the structure; in this case, use binary search for the value. That would require writing some custom code.

First 9 10 11 Page 11 of 11