acer

32348 Reputation

29 Badges

19 years, 330 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

Alec, you mentioned evaluation of "functions" in this forum post. How do you feel about Maple's having expressions, and procedures, but not mathematical functions with an associated domain?

The help-page ?function just describes a function call. Where in the product's internal help-system (not manuals) does it fully describe domains for mathematical functions, let alone restrictions of domains?

With such a given set up as that, does it really then matter which particular dance steps have to happen, to get evaluation at a point to behave?

acer

Some aspects of Mathematica are the opposite of cool.

acer

Some aspects of Mathematica are the opposite of cool.

acer

Using addressof, once again, one can see that there is an instance of clean in the lexical table which is not the global :-clean. It must be a local.

> d:=[disassemble(addressof(eval(RealDomain:-limit)))]:

> pointto(d[9]);
               r2c_handler, r2c_handler, p, limit, clean, clean

> disassemble(d[9]);
           30, 6522504, 6522344, 6655128, 6539768, 6559816, 6654840

> addressof(:-clean);
                                    6559816

You can also see this using op() to get at the lexical table,

> select(t->type(convert(t,`global`),identical(clean)),
>        [op(7,eval(RealDomain:-limit))]);
                                [clean, clean]
 
> map(addressof,%);
                              [6559816, 6654840]
 
> addressof(:-clean);
                                    6559816

And, mixing and matching the fun and games,

> ToInert(pointto(6654840));
_Inert_ASSIGNEDLOCALNAME("clean", "PROC", 6654840, _Inert_ATTRIBUTE(
 
    _Inert_EXPSEQ(_Inert_EQUATION(_Inert_NAME("modulename"),
 
    _Inert_ASSIGNEDNAME("RealDomain", "MODULE", _Inert_ATTRIBUTE(_Inert_EXPSEQ(
 
    _Inert_NAME("protected", _Inert_ATTRIBUTE(_Inert_NAME("protected"))),
 
    _Inert_NAME("_syslib"))))))))

acer

Are you operating in a Document or a Worksheet? All I can imagine, offhand, is that sometimes there is a muddle in how you are entering the command within a Document.

If you are relatively new to Maple then I suggest using a Worksheet with 1D Maple input (rather than 2D Math input) for your programming experimentation. It makes programming more clear -- what you see is what is there. Perhaps leave Document mode for final presentations (if you need it).

You can open either type of sheet from the top-bar's File menu, and you can even change the default for entry from 2D to 1D under the options menus.

acer

Are you operating in a Document or a Worksheet? All I can imagine, offhand, is that sometimes there is a muddle in how you are entering the command within a Document.

If you are relatively new to Maple then I suggest using a Worksheet with 1D Maple input (rather than 2D Math input) for your programming experimentation. It makes programming more clear -- what you see is what is there. Perhaps leave Document mode for final presentations (if you need it).

You can open either type of sheet from the top-bar's File menu, and you can even change the default for entry from 2D to 1D under the options menus.

acer

Doesn't the procedure use_a() that I posted above produce P(a)?

And it does it quickly too, without having to solve once again for all other discrete solution points X[i].

acer

Doesn't the procedure use_a() that I posted above produce P(a)?

And it does it quickly too, without having to solve once again for all other discrete solution points X[i].

acer

Right you are.

For a 2D Math typeset caption in a plot I got the popup error "TITLE must be a NAME", when trying to export from the maplet plot window under Maple's commandline interface.

The maplet plotter displayed it OK, but its Export function failed.

acer

I didn't make many stylistic adjustments to Taylor5. But I changed a few things about how it works. It is quite a bit faster now, for your example. And hopefully I fixed the second loop, which you had mentioned broke when you removed assignment of the S[k] to outside the loops.

At the end, I give a short procedure which computes p(a), given listlist P of previous data. All it does it search P for the greatest X[i] that is less that 'a'. It relies on the fact that listlist output P from Taylor5 is ordered with respect to P's individual list elements first operands, X[i]. The procedure calls Taylor5 to do just one single step, starting from that located X[i] and ending at 'a'.

restart:

Taylor5 := proc (eqcond::set, fonc::function, A::`=`, n::integer)
local f, h, X, T, k1, k2, k3, k4, i, F1, F2, F3, F4, F5, fct, cond, t, N, bd, bg, S, k;
  if nargs = 4 then N := n else N := 1000 end if;
  cond := op(1, args[1]);
  T[0] := op(1, lhs(cond));
  X[0] := rhs(cond); fct := rhs(op(2, eqcond));
  t := op(1, fonc); bd := op(2, rhs(args[3]));
  bg := op(1, rhs(args[3])); h := (bd-T[0])/N;
  Digits := 24;
  F1 := unapply(fct, [t]);
  f := unapply(fonc, t);
  F2 := D[1](F1); F3 := D[1](F2); F4 := D[1](F3); F5 := D[1](F4);
  k1 := (D[1](f))(t); k2 := diff(k1, t); k3 := diff(k2, t); k4 := diff(k3, t);
  S[1] := simplify(subs(t = T[i], f(T[i]) = X[i], F1(t)));
  S[2] := simplify(subs(k1 = F1(t), t = T[i], f(T[i]) = X[i], F2(t)));
  S[3] := simplify(subs(k1 = F1(t), k2 = S[2], t = T[i], f(T[i]) = X[i], F3(t)));
  S[4] := simplify(subs(k1 = F1(t), k2 = S[2], k3 = S[3], t = T[i], f(T[i]) = X[i], F4(t)));
  S[5] := simplify(subs(k1 = F1(t), k2 = S[2], k3 = S[3], k4 = S[4], t = T[i], f(T[i]) = X[i], F5(t)));
  for i from 0 to N while T[i] <= bd do
    X[i+1] := X[i]+add(evalf(eval(S[k])*h^k/factorial(k)), k = 1 .. 5);
    T[i+1] := evalf(T[i]+h);
  end do;
  h := (T[0]-bg)/N;
  for i from 0 by -1 to -N while bg <= T[i] do
    X[i-1] := X[i]+add(evalf(eval(S[k])*(-h)^k/factorial(k)), k = 1 .. 5);
    T[i-1] := evalf(T[i]-h);
  end do;
  [seq([T[i], X[i]], i = -N .. N)];
end proc:

deq := diff(x(t), t) = 3*x(t)/t+(9/2)*t-13;

ci := x(3) = 6;

st:=time(): P := Taylor5({ci, deq}, x(t), t = -1 .. 4, 1000): time()-st;

plots[pointplot](P);

use_a := proc(a, P, tay)
local jj, res;
  for jj from 1 to nops(P)-1 do
    if P[jj+1][1] > a then
      break;
    end if;
  end do;
  res := tay({x(P[jj][1])=P[jj][2],deq},x(t),t=P[jj][1]..a,1);
  res[-1];
end proc:

st:=time(): use_a(2, P, Taylor5); time()-st;

acer

I didn't make many stylistic adjustments to Taylor5. But I changed a few things about how it works. It is quite a bit faster now, for your example. And hopefully I fixed the second loop, which you had mentioned broke when you removed assignment of the S[k] to outside the loops.

At the end, I give a short procedure which computes p(a), given listlist P of previous data. All it does it search P for the greatest X[i] that is less that 'a'. It relies on the fact that listlist output P from Taylor5 is ordered with respect to P's individual list elements first operands, X[i]. The procedure calls Taylor5 to do just one single step, starting from that located X[i] and ending at 'a'.

restart:

Taylor5 := proc (eqcond::set, fonc::function, A::`=`, n::integer)
local f, h, X, T, k1, k2, k3, k4, i, F1, F2, F3, F4, F5, fct, cond, t, N, bd, bg, S, k;
  if nargs = 4 then N := n else N := 1000 end if;
  cond := op(1, args[1]);
  T[0] := op(1, lhs(cond));
  X[0] := rhs(cond); fct := rhs(op(2, eqcond));
  t := op(1, fonc); bd := op(2, rhs(args[3]));
  bg := op(1, rhs(args[3])); h := (bd-T[0])/N;
  Digits := 24;
  F1 := unapply(fct, [t]);
  f := unapply(fonc, t);
  F2 := D[1](F1); F3 := D[1](F2); F4 := D[1](F3); F5 := D[1](F4);
  k1 := (D[1](f))(t); k2 := diff(k1, t); k3 := diff(k2, t); k4 := diff(k3, t);
  S[1] := simplify(subs(t = T[i], f(T[i]) = X[i], F1(t)));
  S[2] := simplify(subs(k1 = F1(t), t = T[i], f(T[i]) = X[i], F2(t)));
  S[3] := simplify(subs(k1 = F1(t), k2 = S[2], t = T[i], f(T[i]) = X[i], F3(t)));
  S[4] := simplify(subs(k1 = F1(t), k2 = S[2], k3 = S[3], t = T[i], f(T[i]) = X[i], F4(t)));
  S[5] := simplify(subs(k1 = F1(t), k2 = S[2], k3 = S[3], k4 = S[4], t = T[i], f(T[i]) = X[i], F5(t)));
  for i from 0 to N while T[i] <= bd do
    X[i+1] := X[i]+add(evalf(eval(S[k])*h^k/factorial(k)), k = 1 .. 5);
    T[i+1] := evalf(T[i]+h);
  end do;
  h := (T[0]-bg)/N;
  for i from 0 by -1 to -N while bg <= T[i] do
    X[i-1] := X[i]+add(evalf(eval(S[k])*(-h)^k/factorial(k)), k = 1 .. 5);
    T[i-1] := evalf(T[i]-h);
  end do;
  [seq([T[i], X[i]], i = -N .. N)];
end proc:

deq := diff(x(t), t) = 3*x(t)/t+(9/2)*t-13;

ci := x(3) = 6;

st:=time(): P := Taylor5({ci, deq}, x(t), t = -1 .. 4, 1000): time()-st;

plots[pointplot](P);

use_a := proc(a, P, tay)
local jj, res;
  for jj from 1 to nops(P)-1 do
    if P[jj+1][1] > a then
      break;
    end if;
  end do;
  res := tay({x(P[jj][1])=P[jj][2],deq},x(t),t=P[jj][1]..a,1);
  res[-1];
end proc:

st:=time(): use_a(2, P, Taylor5); time()-st;

acer

Hi Mario,

I would like to experiment a little more. Would it be possible for you to upload your later revision of the code?

ps. In an earlier post in this thread, you wrote that you wanted to do something like,

p:=Taylor4(......)
p(a)
plots[odeplot](p)

It was from that that I misunderstood, and got the idea that you would know point 'a' before viewing the plot. I now see that it is the other way around: you first view the plot, and only then (due to some qualitative aspect of the plot, perhaps) know the point 'a' at which you then also want the computation p(a).

There may still be hope. Having computed all the [t[i],X[t[i]]] pairs in the data set, it should be possible to find the largest t[i] smaller than 'a' (or second largest, if the largest is too close to 'a'.) Maybe one could then use that X[t[i]] as a new "initial" point and 'a' as new final point.

acer

Hi Mario,

I would like to experiment a little more. Would it be possible for you to upload your later revision of the code?

ps. In an earlier post in this thread, you wrote that you wanted to do something like,

p:=Taylor4(......)
p(a)
plots[odeplot](p)

It was from that that I misunderstood, and got the idea that you would know point 'a' before viewing the plot. I now see that it is the other way around: you first view the plot, and only then (due to some qualitative aspect of the plot, perhaps) know the point 'a' at which you then also want the computation p(a).

There may still be hope. Having computed all the [t[i],X[t[i]]] pairs in the data set, it should be possible to find the largest t[i] smaller than 'a' (or second largest, if the largest is too close to 'a'.) Maybe one could then use that X[t[i]] as a new "initial" point and 'a' as new final point.

acer

Ok, the general idea of what I was saying should hold for your particular code. The actual implementation would have to accomodate the fact that you use a slightly different scheme, according to whether T[i]<=bd. But what I wrote above should work.

Some other advice, if I may:

  • Use `add` instead of `sum` in that routine, where you add up a finite number of values. It is faster.
  • Instead of all those `subs` calls, you should be able to do it faster with `eval`. Now, I remember that you asked about it elsewhere, and that you do need the successive substitutions, in order. But why not substitute into the S[i-1] (to get "new" S[i-1] formulae) outside of the 'i' loop? That is to say, get your hands on fully explicit algebraic substitution formulae, newS[i],i=1..5, just once outside the loops. And then use just a single call to eval(X[i]*F||i(t),[..newS[i]=..] inside the loop. It would run much faster, I suspect. And the routine is slow.
  • Remove N as a declared local and the first line which assigns to N using n, and change the parameter n::integer to N::integer:=1000.
  • I would write procedures in 1D Maple input, not 2D Math. It looks bad in 2D. And I can actually see the delay which the GUI parses and displays the code. And it is wholly unclear visually whether the subscripted names are table references or not.
  • Use the parameter names instead of args[i], all over, for consistency.

acer

Ok, the general idea of what I was saying should hold for your particular code. The actual implementation would have to accomodate the fact that you use a slightly different scheme, according to whether T[i]<=bd. But what I wrote above should work.

Some other advice, if I may:

  • Use `add` instead of `sum` in that routine, where you add up a finite number of values. It is faster.
  • Instead of all those `subs` calls, you should be able to do it faster with `eval`. Now, I remember that you asked about it elsewhere, and that you do need the successive substitutions, in order. But why not substitute into the S[i-1] (to get "new" S[i-1] formulae) outside of the 'i' loop? That is to say, get your hands on fully explicit algebraic substitution formulae, newS[i],i=1..5, just once outside the loops. And then use just a single call to eval(X[i]*F||i(t),[..newS[i]=..] inside the loop. It would run much faster, I suspect. And the routine is slow.
  • Remove N as a declared local and the first line which assigns to N using n, and change the parameter n::integer to N::integer:=1000.
  • I would write procedures in 1D Maple input, not 2D Math. It looks bad in 2D. And I can actually see the delay which the GUI parses and displays the code. And it is wholly unclear visually whether the subscripted names are table references or not.
  • Use the parameter names instead of args[i], all over, for consistency.

acer

First 528 529 530 531 532 533 534 Last Page 530 of 592