acer

32385 Reputation

29 Badges

19 years, 337 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

It is possible to create a customized system (derived from SI, say) in which seconds are represented as 1/hertz and 1/seconds are represented as hertz.

> Units:-AddSystem(mySI,Units:-GetSystem(SI),Hz,1/Hz):

Once such a system has been created, one can forcibly convert single expressions in that new system (without changing default behaviour),

> x := Unit(kg/s*m^2);
                                      [    2]
                                      [kg m ]
                                 x := [-----]
                                      [  s  ]

> convert(x,system,mySI);
                                  [       2]
                                  [kg Hz m ]

One can also change the ("default") behaviour of combining units in new expressions,

> Units:-UseSystem(mySI):

> x := Unit(kg/s*m^2);
                                     [       2]
                                x := [kg Hz m ]
 
> x := Unit(kg*s/m^2);
                                      [ kg  ]
                                 x := [-----]
                                      [    2]
                                      [Hz m ]

acer

It is possible to create a customized system (derived from SI, say) in which seconds are represented as 1/hertz and 1/seconds are represented as hertz.

> Units:-AddSystem(mySI,Units:-GetSystem(SI),Hz,1/Hz):

Once such a system has been created, one can forcibly convert single expressions in that new system (without changing default behaviour),

> x := Unit(kg/s*m^2);
                                      [    2]
                                      [kg m ]
                                 x := [-----]
                                      [  s  ]

> convert(x,system,mySI);
                                  [       2]
                                  [kg Hz m ]

One can also change the ("default") behaviour of combining units in new expressions,

> Units:-UseSystem(mySI):

> x := Unit(kg/s*m^2);
                                     [       2]
                                x := [kg Hz m ]
 
> x := Unit(kg*s/m^2);
                                      [ kg  ]
                                 x := [-----]
                                      [    2]
                                      [Hz m ]

acer

You don't need to issue with(Units) for this particular computation.

You might want to try these alternatives for some of the later commands in your worksheet (where it appeared to have problems),

plot(convert(combine(subs(const, L[vpeak](T)), 'units'), 'unit_free'), T = 2000 .. 5500);
plot(convert(simplify(subs(const, L[vpeak](T))), 'unit_free'), T = 2000 .. 5500);

evalf(combine(subs(const, L[vpeak](2000.0)), 'units'));
evalf(simplify(subs(const, L[vpeak](2000.0))));

map(t -> map(convert, combine(t, 'units'), 'unit_free'), const);
map(t -> map(convert, simplify(t), 'unit_free'), const);

When you attempted a units replacement at the end, using the context-menus, did you intend to replace kg/(s^2*K^3) by kg*Hz^2/K^3 ?

acer

You don't need to issue with(Units) for this particular computation.

You might want to try these alternatives for some of the later commands in your worksheet (where it appeared to have problems),

plot(convert(combine(subs(const, L[vpeak](T)), 'units'), 'unit_free'), T = 2000 .. 5500);
plot(convert(simplify(subs(const, L[vpeak](T))), 'unit_free'), T = 2000 .. 5500);

evalf(combine(subs(const, L[vpeak](2000.0)), 'units'));
evalf(simplify(subs(const, L[vpeak](2000.0))));

map(t -> map(convert, combine(t, 'units'), 'unit_free'), const);
map(t -> map(convert, simplify(t), 'unit_free'), const);

When you attempted a units replacement at the end, using the context-menus, did you intend to replace kg/(s^2*K^3) by kg*Hz^2/K^3 ?

acer

The reason that it looks shorter in python is because someone's already written its functions urlencode, urlopen, etc.

So one might reasonably ask how hard it would be to write the equivalent functions in maple, so as not to have to type all that out like John did. That's how to use Maple effectively -- to write re-usable procedures for repeating queries. Also possible is to distribute them (as the python community does) for others to use.

For example, are the undocumented HTTP:-Post and HTTP:-URLEncode close, or do they require changes in order to do this task?

acer

Is vim's maple mode primarily for editing (eg, syntax highlighting, autoindent, etc)? Does it also provide macros for pumping the buffer into a new commandline Maple session?

Perhaps people could post some of their favourite .vimrc gems that relate to Maple.

acer

Is vim's maple mode primarily for editing (eg, syntax highlighting, autoindent, etc)? Does it also provide macros for pumping the buffer into a new commandline Maple session?

Perhaps people could post some of their favourite .vimrc gems that relate to Maple.

acer

Live and learn. Thanks. Sorry to have doubted you, Alec.

acer

> StringTools:-Soundex("links");
                                    "L520"
 
> StringTools:-Soundex("lynx");
                                    "L520"

Alec may have been thinking of the lynx browser.

acer

For me, the most interesting bit of the above post is the methodology of programmatically importing data from tables in HTML files into a Maple session.

The use of StringTools:-Metaphone looks fun, in an over-the-top way.

I look forward to seeing the way the Sockets package was used to grab the HTML directly from the remote server. See also here.

For those who would wish to fully automate these tasks (to grab, manupulate, and analyze web-published data that changes often), such methods could be very useful.

acer

Ok, thanks. There is something going on with print of a proc from within a procedure, but I'm not sure exactly what.

I got the following to work, in the Standard GUI in Linux,

mint := proc(f,extras::string:="")
local fname,k,oldiface;
   fname := "/tmp/foo";
   oldiface := interface('verboseproc');
   interface('verboseproc'=3);
   writeto(fname);
   printf("%a := ", f);
   printf("%a",eval(f));
   printf(":\n");
   writeto(terminal):
   fclose(fname);
   interface('verboseproc'=oldiface);
   k:=ssystem(cat("/usr/local/maple/maple12.01/bin/mint ",extras," ",fname));
   if k[1]>=0 then printf("%s",k[2]); end if;
   NULL; 
end proc:

mint(`convert/CompSeq`);

It could be made nicer, by using StringTools to Drop the mint preamble text in the 2nd operand of the result from ssystem.

acer

Thanks Alejandro,

Does it work in the Standard GUI for you, if you set interface('verboseproc'=3) outside of the procedure?

Is it a surprise to anyone else, if verboseproc could not be set inside a proc in a Standard worksheet?

acer

It's a consequence of the module's having `option package`.

Without `option package`, one can assign to the export without having first unprotected it. In that case, issuing `with` on the module causes a Warning (but succeeds).

> restart:
> myD:=module() option package; export D; end module:
> with(myD);
                                      [D]
> D:=4: 17*D;
Error, attempting to assign to `D` which is protected
                                     17 D
 
> restart:
> myD:=module() export D; end module:
> with(myD);
Warning, myD is not a correctly formed package - option `package' is missing
                                      [D]

> D:=4: 17*D;
                                      68
It wasn't actually due to the fact that global :-D is protected.
> restart:
> myG:=module() option package; export G; end module:
> with(myG):
> G:=4;
Error, attempting to assign to `G` which is protected

> restart:
> myG:=module() export G; end module:
> with(myG):
Warning, myG is not a correctly formed package - option `package' is missing
> G:=4;
                                    G := 4

I guess that the idea is that one would want package exports (but not all other modules' exports) to be protected. Discounting the Warning message, there is some flexibility.

An alternative is to use bind directly,

> restart:
> myD:=module() export D; end module:

> bind(myD:-D);
                                       D
 
> D:=4: 17*D;
                                      68
 
> :-D(sin);
                                      cos
> convert(diff(f(x),x),:-D);
                                    D(f)(x)
 
> eval(%,f=tan);
                                            2
                                  1 + tan(x)

acer

It's a consequence of the module's having `option package`.

Without `option package`, one can assign to the export without having first unprotected it. In that case, issuing `with` on the module causes a Warning (but succeeds).

> restart:
> myD:=module() option package; export D; end module:
> with(myD);
                                      [D]
> D:=4: 17*D;
Error, attempting to assign to `D` which is protected
                                     17 D
 
> restart:
> myD:=module() export D; end module:
> with(myD);
Warning, myD is not a correctly formed package - option `package' is missing
                                      [D]

> D:=4: 17*D;
                                      68
It wasn't actually due to the fact that global :-D is protected.
> restart:
> myG:=module() option package; export G; end module:
> with(myG):
> G:=4;
Error, attempting to assign to `G` which is protected

> restart:
> myG:=module() export G; end module:
> with(myG):
Warning, myG is not a correctly formed package - option `package' is missing
> G:=4;
                                    G := 4

I guess that the idea is that one would want package exports (but not all other modules' exports) to be protected. Discounting the Warning message, there is some flexibility.

An alternative is to use bind directly,

> restart:
> myD:=module() export D; end module:

> bind(myD:-D);
                                       D
 
> D:=4: 17*D;
                                      68
 
> :-D(sin);
                                      cos
> convert(diff(f(x),x),:-D);
                                    D(f)(x)
 
> eval(%,f=tan);
                                            2
                                  1 + tan(x)

acer

> convert(simplify(diff(sqrt(u(x)^2),x)),abs) assuming u(x)::real;
                                     /d      \
                                u(x) |-- u(x)|
                                     \dx     /
                                --------------
                                   | u(x) |
 
> PDEtools:-declare(u(x));
                        u(x) will now be displayed as u
 
> convert(simplify(diff(sqrt(u(x)^2),x)),abs) assuming u(x)::real;
                                    u u[x]
                                    ------
                                    | u |

acer

First 508 509 510 511 512 513 514 Last Page 510 of 592