## 6542 Reputation

17 years, 176 days
University of British Columbia
Associate Professor Emeritus

## Sorting sublists...

@Markiyan Hirnyk : There's a subtle bug in your code: sorting a named list changes the value of the list, but sorting a sublist does not.  Consider:

`> LL:= [[1,3,2],[2,3,1]];   for i from 1 to 2 do sort(LL[i],`>`) end do;   LL;`

What you want to do instead is

`> LL:= map(sort, LL, `>`);`

## Trapezoid...

Let's say you have values at intervals of 0.1 for x from 0 to 450, in lists.

> Fdata:= [ ... ]: Gdata:= [ ... ]:

Thus Fdata[i] is f(x) where x = (i-1)*0.1, i = 1 to 4501.  Note that this means i = 1 + 10*x.

`> Integrand:= proc(x) local i;if type(x,numeric) then i:= round(1+10*x): (Fdata[i] - Gdata[i])^2else 'procname'(x) end ifend proc;`
`> 1/2 * Student[Calculus1][ApproximateInt](Integrand(x), x = 0 .. 450,       method=trapezoid, partition = 4500);`

## Trapezoid...

Let's say you have values at intervals of 0.1 for x from 0 to 450, in lists.

> Fdata:= [ ... ]: Gdata:= [ ... ]:

Thus Fdata[i] is f(x) where x = (i-1)*0.1, i = 1 to 4501.  Note that this means i = 1 + 10*x.

`> Integrand:= proc(x) local i;if type(x,numeric) then i:= round(1+10*x): (Fdata[i] - Gdata[i])^2else 'procname'(x) end ifend proc;`
`> 1/2 * Student[Calculus1][ApproximateInt](Integrand(x), x = 0 .. 450,       method=trapezoid, partition = 4500);`

## @elango8 : if you want to evaluate somet...

@elango8 : if you want to evaluate something at specific values, say  t=1.2  and w=3.4, try

> eval(something, {t=1.2, w=3.4});

## @elango8 : if you want to evaluate somet...

@elango8 : if you want to evaluate something at specific values, say  t=1.2  and w=3.4, try

> eval(something, {t=1.2, w=3.4});

## Compatibility...

Java has the slogan "Write once, run anywhere".  Of course in practice it's "Write once, debug everywhere".  But in principle it should be possible to port Maple to any platform that runs Java.  Unfortunately the iPad doesn't support Java, which means to put the Maple GUI on the iPad you have to rebuild it from scratch.  It looks to me (from a brief web search) like the BlackBerry PlayBook does support Java, so in principle it ought to be much easier to port Maple to it.  However there's still that "debug everywhere".  In the end, I suppose it will come down to a question of whether the potential market is enough to offset the cost of making a version of Maple that runs on any particular system.

## transform...

@PatrickT : One of the problems with the plottools[transform] approach is that it doesn't perform hidden element removal: patches of surface that are closer to the viewer don't hide patches that are farther away along the same line of sight.  You might notice some strange effects near the bottom of your .pdf file because of this (in the postscript file, some elements hide others, but the order that they are presented is not consistent).

## transform...

@PatrickT : One of the problems with the plottools[transform] approach is that it doesn't perform hidden element removal: patches of surface that are closer to the viewer don't hide patches that are farther away along the same line of sight.  You might notice some strange effects near the bottom of your .pdf file because of this (in the postscript file, some elements hide others, but the order that they are presented is not consistent).

## Minimum number of patterns...

To minimize the number of different patterns used, we could add binary variables yi, require them to be 1 when pattern i is used by constraints

and try to minimize the sum of the yi. Unfortunately this takes a very long time.  I tried

Optimization:-Minimize(add(y[i],i=1..npatterns),{add(x[i],i=1..npatterns)=73} union cons union {seq(x[i] <= 73 * y[i], i=1..npatterns)}, binaryvariables=[seq(y[i],i=1..npatterns], assume=nonnegint, nodelimit=10000);

with the nodelimit option to make it finish (maybe with a sub-optimal solution) in a reasonable time, but the result (after several hours) was rather disappointing, using 17 patterns.

## Minimum number of patterns...

To minimize the number of different patterns used, we could add binary variables yi, require them to be 1 when pattern i is used by constraints

and try to minimize the sum of the yi. Unfortunately this takes a very long time.  I tried

Optimization:-Minimize(add(y[i],i=1..npatterns),{add(x[i],i=1..npatterns)=73} union cons union {seq(x[i] <= 73 * y[i], i=1..npatterns)}, binaryvariables=[seq(y[i],i=1..npatterns], assume=nonnegint, nodelimit=10000);

with the nodelimit option to make it finish (maybe with a sub-optimal solution) in a reasonable time, but the result (after several hours) was rather disappointing, using 17 patterns.

## local for global...

Hmm.  Here's a procedure that takes a procedure definition and a name of a local variable in that procedure and returns a version where that variable has been made global.

`> globalize:= proc(P::procedure, v::name)       local Pin, Ls, nlocals, vs, i, Pout;       Pin:= ToInert(eval(P));       Ls:= indets(Pin, specfunc(anything, _Inert_LOCALSEQ))[1];       nlocals:= nops(Ls);       vs:= convert(v, string);       if not member(_Inert_NAME(vs), Ls, i)          then error "Local variables are %1 but not %2", map(op, convert(Ls,list)), v        end if;       Pout:= subs(_Inert_LOCAL(i)=_Inert_NAME(vs),               seq(_Inert_LOCAL(j)=_Inert_LOCAL(j-1),j=i+1..nlocals),            subs(_Inert_NAME(vs)=NULL,Pin));       FromInert(Pout)    end proc;`

For example:

`> globalize(proc(x) local u,y,v; y:= u+x; v - u end proc, y);`

proc (x) local u, v; y := u+x; v-u end proc

And here's a procedure that takes a procedure definition and a name of a global variable and returns a version where that variable has been made local.

`> localize:= proc(P::procedure, v::evaln)       local Pin, Ls, nlocals, vs, Pout;       Pin:= ToInert(eval(P));       Ls:= indets(Pin, specfunc(anything, _Inert_LOCALSEQ))[1];       nlocals:= nops(Ls)+1;       vs:= convert(v, string);       Pout:= subs(_Inert_NAME(vs)=_Inert_LOCAL(nlocals),               Ls= _Inert_LOCALSEQ(op(Ls),_Inert_NAME(vs)), Pin);       FromInert(Pout)end proc;`

For example:

`> localize(proc (x) local u, v; v := u+y; v-y end proc, y);`

proc (x) local u, v, y; v := u+y; v-y end proc

## local for global...

Hmm.  Here's a procedure that takes a procedure definition and a name of a local variable in that procedure and returns a version where that variable has been made global.

`> globalize:= proc(P::procedure, v::name)       local Pin, Ls, nlocals, vs, i, Pout;       Pin:= ToInert(eval(P));       Ls:= indets(Pin, specfunc(anything, _Inert_LOCALSEQ))[1];       nlocals:= nops(Ls);       vs:= convert(v, string);       if not member(_Inert_NAME(vs), Ls, i)          then error "Local variables are %1 but not %2", map(op, convert(Ls,list)), v        end if;       Pout:= subs(_Inert_LOCAL(i)=_Inert_NAME(vs),               seq(_Inert_LOCAL(j)=_Inert_LOCAL(j-1),j=i+1..nlocals),            subs(_Inert_NAME(vs)=NULL,Pin));       FromInert(Pout)    end proc;`

For example:

`> globalize(proc(x) local u,y,v; y:= u+x; v - u end proc, y);`

proc (x) local u, v; y := u+x; v-u end proc

And here's a procedure that takes a procedure definition and a name of a global variable and returns a version where that variable has been made local.

`> localize:= proc(P::procedure, v::evaln)       local Pin, Ls, nlocals, vs, Pout;       Pin:= ToInert(eval(P));       Ls:= indets(Pin, specfunc(anything, _Inert_LOCALSEQ))[1];       nlocals:= nops(Ls)+1;       vs:= convert(v, string);       Pout:= subs(_Inert_NAME(vs)=_Inert_LOCAL(nlocals),               Ls= _Inert_LOCALSEQ(op(Ls),_Inert_NAME(vs)), Pin);       FromInert(Pout)end proc;`

For example:

`> localize(proc (x) local u, v; v := u+y; v-y end proc, y);`

proc (x) local u, v, y; v := u+y; v-y end proc

## Local variable...

The reason subs doesn't work here is that i is a local variable of the procedure.  It would work if i was a global variable.

## Local variable...

The reason subs doesn't work here is that i is a local variable of the procedure.  It would work if i was a global variable.

## @elango8 : Leave out the line assigning ...

@elango8 : Leave out the line assigning a value to t at the start of your E.mw.  You will get everything as expressions involving t.  Then you can evaluate these at particular values of t, you can do so using eval or seq.  For example, if you want K1 at t=0.8, t=0.9 and t=1.0, you could do this:

> K1vals:= [seq](K1, t= [ 0.8, 0.9, 1.0 ]);

 4 5 6 7 8 9 10 Last Page 6 of 187
﻿