1494 Reputation

19 Badges

16 years, 46 days

Social Networks and Content at

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

Hi Sebgo,

What you'll want to do is first make sure you get dsolve to find a numerical solution for you. In order to achieve that,  you'll need to pass it the differential equations and initial conditions. Note also that there was a small mistake in the initial conditions that you posted: you had

ics := {Seq(y(j)[0] = exp(-(j-mu)^2/(2*sigma^2))/(sigma*sqrt(2*Pi)), j = 1 .. imax)}

where you probably want

ics := {seq(y[j](0) = exp(-(j-mu)^2/(2*sigma^2))/(sigma*sqrt(2*Pi)), j = 1 .. imax)}:

(note the seq being lowercase and the brackets for y[j](0)). If you have des defined as in your original posting and ics as in the line above this one, and furthermore, beta[i,j] has a numerical value for all sensible i and j, then you can call

dsnproc := dsolve([des[], ics[]], numeric):
odeplots := seq(plots:-odeplot(dsnproc, [t, y[i](t)], color='COLOR'('HUE', i * (1/2 + 1/2*sqrt(5)))), i=1..10):

Hope this helps,


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:

  proc(x :: identical(a1))
  option overload;
  proc(x :: identical(a2))
  option overload;
  proc(x :: identical(a3))
  option overload;

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