pagan

5147 Reputation

23 Badges

17 years, 124 days

 

 

"A map that tried to pin down a sheep trail was just credible,

 but it was an optimistic map that tried to fix a the path made by the wind,

 or a path made across the grass by the shadow of flying birds."

                                                                 - _A Walk through H_, Peter Greenaway

 

MaplePrimes Activity


These are answers submitted by pagan

Keep in mind that the formal parameters of the procedure are not the same as the global names (which you might mean when you write "variables").

> f:=proc(x,y) x*y; end proc:

> op(1,eval(f));
                              x, y

One difficulty with approach 1 below is that you have to remember to make and retain separate references to each assumed instance (distinct local). A possible difficulty with approach 2 below is that the convert(expr3,`global`) would affect any other assumed names as well.

restart:

assume(a>0);

expr2:=a^(1/2);
(1/2)
a

# save a reference to current local a, for re-use later
a2:=a:

additionally(a>1);

expr3:=sqrt(a)+expr2;
(1/2) (1/2)
a + a

subs(a=2,expr3); # the problem
(1/2) (1/2)
2 + a

# approach 1, using earlier reference
subs([a=2,a2=2],expr3);
(1/2)
2 2

# approach 2, but also affecting any other assumed names in expr3
subs(convert(a,`global`)=2,convert(expr3,`global`));
(1/2)
2 2

getlocs:=(ex,nm)->
[select(t->evalb(convert(t,`global`)=convert(nm,`global`)),
indets(ex,And(name,`local`)))[]]:

# approach 3, convert just those locals in expr3 whose global
# form matches the global a.
subs(seq(t=2,t=getlocs(expr3,a)), expr3);
(1/2)
2 2

As you mention, another alternative is to change fundamentally your interleaving of assignments and changes/updates to assumptions.

The trickiest part of what you're asking is that 4*(1+3*w) will automatically become 4+12*w unless you somehow artificially prevent it. But this might only be a problem for the constant term (of the expression considered as a polynomial in beta).

One choice is to accept this, and factor out terms from the higher coefficients only. Or you can use some techniques to prevent the automatic simplification. Some such tricks involve altering the expression, and require a corresponding technique to revert back to the usual form.

restart:
expr:=-3*w*beta^2+12*w-16*beta+4+3*beta^2;
                    2                              2
           -3 w beta  + 12 w - 16 beta + 4 + 3 beta 

collect(expr,beta);
                            2                     
             (-3 w + 3) beta  - 16 beta + 12 w + 4

factorsum:=proc(ee::`+`,
                {method::identical(none,ampersand,name):=none},
                {dummy::name:=1})
  local z,s,t;
  z:=op(ee);
  t:=gcd(z);
  if method='ampersand' then
    (t)&*add(s/t,s in z);
  elif method=name then
    ``(t)*add(s/t,s in z);
  else
    t*(add(s/t,s in z))*dummy;
  end if;
end proc:

`value/&*`:=proc() `*`(args) end proc:

factorcoeffs:=proc(G,x,{method::identical(none,ampersand,name):=none})
  local L, temp, locdummy;
  uses PolynomialTools;
  L:=CoefficientList(G,x);
  temp,L[1]:=L[1],0;
  eval(factorsum(temp,':-method'=method,':-dummy'=locdummy)
       + FromCoefficientList(
           subsindets(L,`+`,factorsum,
                           ':-method'=none,':-dummy'=locdummy),
           x),locdummy=1);
end proc:

factorcoeffs(expr,beta);
                                                 2
              4 + 12 w - 16 beta + 3 (1 - w) beta 

factorcoeffs(expr,beta,method=ampersand);
                                                    2
           4 &* (1 + 3 w) - 16 beta + 3 (1 - w) beta 

value(%);
                                                 2
              4 + 12 w - 16 beta + 3 (1 - w) beta 

factorcoeffs(expr,beta,method=name);
                                                   2
           (4) (1 + 3 w) - 16 beta + 3 (1 - w) beta 

expand(%);
                    2                              2
           -3 w beta  + 12 w - 16 beta + 4 + 3 beta 

You can also enter e the base of the natural logarithm in 2d Math input (ie. as the Roman e) by using command-completion.

That is, type the letter e, then type simultaneously the keys Ctrl-spacebar (on MS-Windows). This should result in a popup menu, the top choice of which is that desired e which is exp(1).

The letter E lost its special association with the base of the natural log in Maple with the release of version MapleV R4 in 1996. See the help page updatesR4/compatibility .

I recall there being a sort of staged upgrade path. Basically, you'd hit old .m or .mws files with a chain of updating programs. Each of those came with the various Maple product releases, but which individually might handle only some of the stages to get current to its own version (depending on how old were your sheets' original version).

I'm talking about before Maple 7, as there really haven't been the same degree of incompatible language syntax changes since then. I mean changes like the ditto's becoming %, etc.

I hope that you only try it out on copies of your originals. Sorry, had to say it.

Look here, for the supposed MapleV -> Maple 6 (or 7?) updtsrc. The FTP links don't work, but there's still something at the end of the HTTP links. I checked the old FTP site, and while there's lots of old stuff there, the updtsrc progs seem gone now. It's not clear from the wording which version(s) it handles, ie. R5, or R4, or R3, etc. I would guess that it is for MapleV R5 to Maple6 conversion.

Which version of MapleV do you have? Can we suppose that you have MapleV R5 (or 5.1) and have already run the updtsrc.exe (or the updt3to4.exe for old R3 .m files) that came bundled with it on any older R4 material you had? If so, then the Maple6 updtsrc link above might be enough to get the most outstanding language changes handled.

If your material is from MapleV R4, and you don't have MapleV R5's updtsrc.exe, then it's not so clear whether the Maple6 updtsrc will be enough. You might need to apply MapleV R5 updtsrc first. I forget whether it needs a full, licensed and functional R5 installation to work. I see one such R5 updtsrc.exe here. I'd try the Maple6 one before resorting to using this first.

If your material is MapleV R3 then you may even more to do, in the update chain. See here, for a lovely view of the kind of language incompatibilities Maple versions used to bring.

Of course, we're talking about getting the old code to run, not to modernize it to use the latest and greatest bits of Maple. If you can apply the Maple6 updtsrc to material that functions ok in R5, then hopefully most of the biggest problems will be resolved. If there are still some problems then at that point I'd suggest uploading an example to this site, so that we could look in detail.

Oh, another memory lane view (cancel the frameset).

You have a few choices. You might need more than just Re(), because you might only want it applied when appropriate (ie. selectively throughout some expresion or list) and to leave other larger complex floats alone.

You can use the fnormal command to zero the 'negligible" parts. Then you can suppress the printing (only) of the zero-imaginary component, or you can get rid of it using simplify.

restart:

fnormal(27293.1844462+1.42305652280*10^(-84)*I);

                       27293.18445 + 0. I

interface(display_zero_complex_part=false):

fnormal(27293.1844462+1.42305652280*10^(-84)*I);

                          27293.18445

interface(display_zero_complex_part=true): # back to the default

fnormal(27293.1844462+1.42305652280*10^(-84)*I);

                       27293.18445 + 0. I

simplify(fnormal(27293.1844462+1.42305652280*10^(-84)*I));

                          27293.18445

expr := exp( x * 27293.1844462+1.42305652280*10^(-84)*I ) - 4.0+5*I * y;

       /                                -84  \              
    exp\27293.1844462 x + 1.423056523 10    I/ - 4.0 + 5. I y

subsindets(expr, complex(numeric), z->simplify(fnormal(z)));

                exp(27293.18445 x) - 4. + 5. I y

Alec's answer is excellent.

It could also be mentioned that `add` is intended for adding up a finite (literal integer) number of terms, and `sum` is for symbolic summation. For adding up 7 values (not from a formula) you should normally be using `add`, regardless of whether you'd otherwise run into premature evaluation.

Searching for "bad index into" on this Mapleprimes site returns some relevant hits with explanations. Hopefully an initial search will help more for your next issue.

In the Standard GUI, that error message is a hyperlink, and clicking on it should take your web browser (if configured ok in Maple's options) to this explanation.

This is certainly a very frequently asked topic. So maybe it could also be added under the Maplesoft Maple FAQ section.

Your procedures are not (yet) members of a module. So, as you've got it so far, that `with(NewArchive)` is not appropriate. There is no one-to-one relationship between modules and library archives. You can store procedures inside an archive, without their necessarily having to be exports of a module. (But, on the other hand, there's nothing to stop you doing that it you want.)

Here it is, without a module for the two procedures. You can put all manner of file-checking a try..catch and bullet-proofing around it, if you want. It's important to put the valid, writable new archive first in libname, so that what gets saved does get saved there and not elsewhere.

restart:

# keep only the assignment to loc that you want.
loc:="Z:/Documents/NewArchive.mla":
loc:=cat(kernelopts(homedir),"\\My Documents\\NewArchive.mla"):

try
  FileTools:-Remove(loc);
catch:
end try:

foo:=proc(x) sin(x); end proc:
bar:=proc(x) cos(x); end proc:

try
  LibraryTools:-Create(loc);
  libname:=loc,libname;
  print("saving");
  savelib(foo);
  savelib(bar);
catch "error":
end try:

                            "saving"

Now they should be saved and ready for re-use. Start a new session, to check.

restart:

libname:=cat(kernelopts(homedir),"\\My Documents\\NewArchive.mla"),libname:

foo(7);

                             sin(7)

bar(11);

                            cos(11)

And if you want, you can put that libname adjustment line in your (personal) maple initialization file.

And now with the two procedures inside a module.

restart:

# keep only the assignment to loc that you want.
loc:="Z:/Documents/NewArchive.mla":
loc:=cat(kernelopts(homedir),"\\My Documents\\NewArchive.mla"):

try
  FileTools:-Remove(loc);
catch:
end try:

NewModule:=module()
option package;
export foo, bar;
   foo:=proc(x) arcsin(x); end proc:
   bar:=proc(x) arccos(x); end proc:
end module:

try
  LibraryTools:-Create(loc);
  libname:=loc,libname;
  print("saving");
  savelib(NewModule);
catch "error":
end try:

                            "saving"

Now test it, in a new session.

restart:

libname:=cat(kernelopts(homedir),"\\My Documents\\NewArchive.mla"),libname:

foo(7);

                             foo(7)

bar(11);

                            bar(11)

with(NewModule);

                           [bar, foo]

foo(7);

                           arcsin(7)

bar(11);

                           arccos(11)

There is an alternative to placing the .mla in a location with which you must prepend libname (in each new session, or in an initialization file). The alternative is to place the .mla archive as if it belonged to some made-up Maple toolbox. For example, using Maple 15 you could place it here (using Windows backslash, but use forwardslash if you prefer)

  cat(kernelopts('homedir'),"\\maple\\toolbox\\15\\misc\\lib\\NewArchive.mla");

Such locations are "special" in the sense that Maple automatically includes them in libname, hence removing the need for you to adjust libname in an initialization file. In order for that to take effect, you'll have to quit all open M15 GUI instances and relaunch the whole GUI. You can query the name `libname`, to see if the presence of that folder, even if empty, causes it to get added to libname. It should also work for Maple 11, if you replace the 15 in that folder path with an 11.

Sum(f(2*i-1), i=1..n/2):
value(eval(%,n=10));
                f(1) + f(3) + f(5) + f(7) + f(9)

Sum(f(2*i-1), i=1..n):
value(eval(%,n=5));
                f(1) + f(3) + f(5) + f(7) + f(9)

Sum(f(2*i+1), i=0..(n/2-1)):
value(eval(%,n=10));
                f(1) + f(3) + f(5) + f(7) + f(9)

Sum(f(2*i+1), i=0..n-1):
value(eval(%,n=5));
                f(1) + f(3) + f(5) + f(7) + f(9)

If you're in a Document, then you can toggle that behaviour with Tools/Options/Display/Typesetting level.

Setting the Typesetting level to Extended should echo the full assignment, in a Document with 2D Math Notation or Typeset Notation for the Ouput display.

Explore doesn't allow for its arguments to be a reference. It's arguments have to be "self-contained".

This can sometimes be accomplished using subs. For example (skip `t` in the popup window)

sys:={diff(x(t),t)=sin(a*x(t)+b)-cos(b*y(t)), diff(y(t),t)=b*x(t)}:

eval(subs(SYS=sys,
'Explore(DEtools[DEplot](SYS,[x(t),y(t)],t=.01..4.,
[[x(0)=1,y(0)=1],[x(0)=1.5,y(0)=1.5],[x(0)=2,y(0)=2]]))'));

It means that the command has computed that the Matrix is not invertible.

What is the result of issuing the command

interface(prettyprint);

If it is not "3", in your Standard GUI, and especially if it is "1", then that explains your situation. You might also check the GUI menubar setting Tools -> Options then in the popup window look at the Display tab. Look for the entry named "Output display". It might have the value "Character Notation", which corresponds to a value of 1 for the prettyprint interface setting. Whatever the value for that box, change it using its drop-down menubox to be "2-D Math Notation". Close the whole pop-up using the "Apply Globally" button at bottom.

I've inadvertantly changed this GUI setting on myself by saving a worksheet after setting interface(prettyprint=1). (It seems like a bug, that it retains this setting globally-across-future-sessions merely by saving a worksheet.)

Let us know, if this doesn't help at all.

Firstly, it's not clear whether you want the entire result rounded to just 2 or 3 decimal places (as a total for places both before and after the decimal point), or whether you want the number of places (only) after the decimal point to be restricted. Or something else. Your example is a bit too simple and allows for more than one interpretation.

Supposing that you just want to restrict the number of displayed decimal figures after the decimal point, you can control that in two ways:

The first way, in the Standard GUI, is using the top menu to go to Tools -> Options, then select the "Precision" tab. Then check the box marked "Round screen display to" and type the number 2 in its entry box. The choose either the Apply to Session or the Apply Globally buttons to finsh, according to whether you want it done for every new worksheet or just the current one.

You should also be able to do that by using the command

interface(displayprecision=2):

which you could issue right inside the worksheet, at the beginning say. Or you could hide that command, using the top menu's Edit -> Startup Code, which would be one of the few ways to ensure that it applied for anyone else running the worksheet on another Maple installation. Or you could put it in your initialization file, if you wanted it for all future sessions.

I attach a worksheet with that command embedded already in its Startup Code. When you accept the auto-execute, and run its content, you should be able to see the output change to just 0.20 as you wrote it.

displayprecision.mw

Whatever you do, do not set Digits low (not lower than 5, ever). That is not a good way to get this done. You could compute the float result at default Digits=10, with output suppressed using a full colon to terminate the command. And then afterwards evalf[2](...) that prior numeric value so as to display it how you describe. Or you could use the printf command to format it with full control over the displayed digits. But a lot of Maple's numerics breaks down pretty hard when Digits is set lower than 4 or so. You can end up with results whose last digit is wrong by more than 1 unit. You probably don't want such inaccuracy. Much better to compute at least at default working precision, and only display at lower precision.

There are different evaluation rules for locals of a procedure. See ?proc and this note in particular

"Within a procedure, during the execution of its statementSequence, local variables have single level evaluation. This means that using a variable in an expression will yield the current value of that variable, rather than first evaluating that value. This is in contrast to how variables are evaluated outside of a procedure, but is similar to how variables work in other programming languages."

Note that your loop index variable `i` is a local as used inside the procedure `test`.

Remove the uneval quotes around the 'i' inside that `assign` call within the procedure.

First 14 15 16 17 18 19 20 Last Page 16 of 48