acer

32333 Reputation

29 Badges

19 years, 319 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

A:=Matrix(2, [[a,b],[c,d]]):

B:=Matrix(2, [[e,f],[g,h]]):

A . B;

                           [a e + b g  a f + b h]
                           [                    ]
                           [c e + d g  c f + d h]

LinearAlgebra:-Multiply(A,B);

                           [a e + b g  a f + b h]
                           [                    ]
                           [c e + d g  c f + d h]

LinearAlgebra:-MatrixMatrixMultiply(A,B);

                           [a e + b g  a f + b h]
                           [                    ]
                           [c e + d g  c f + d h]

with(LinearAlgebra):

Multiply(A,B);

                           [a e + b g  a f + b h]
                           [                    ]
                           [c e + d g  c f + d h]

MatrixMatrixMultiply(A,B);

                           [a e + b g  a f + b h]
                           [                    ]
                           [c e + d g  c f + d h]

You can make any of those into an assignment to the name C, using := in the usual way.

acer

What would a*a produce?

How about somehow registering a name. You could give it an attribute, for example, as the mechanism. And this would allow you to specify the order, too. (I haven't dealt with the mixed case, but you could alter the code to do so.)

It's unclear what you'd want done with c*d, for protected c and d, or for any other such special pair. What decides which product produces the 1, and which the -1? Alphabetic order, say, seems an strange control, but what do I know? This too could be accomplished: use just one kind of attribute to mark names as special, and then test their alphabetic precedence in the code's conditionals.

Note that :-`*` is the global (usual) star operator. So that's what this version falls back to, in cases which it doesn't recognize.

restart:

m:=module() option package;
   export `*`;
   `*`:= proc()
      if nargs=2 and type(args[1],name)
        and type(args[2],name) then
         if attributes(args[1])=lefty
           and attributes(args[2])=righty then
            return 1;
         elif attributes(args[2])=lefty
           and attributes(args[1])=righty then
            return -1;
         elif attributes(args[1])=lefty
           or attributes(args[2])=lefty
           or attributes(args[1])=righty
           or attributes(args[2])=righty then
            return 'procname'(args); # or :-`*`(args), or whatever you decide
         end if;
      end if;
      return :-`*`(args);
   end proc;
end module:

with(m);
                              [*]

17*1.2;
                              20.4

a*b; # nothing special about these yet
                              a b

b*a;
                              a b

setattribute(a,lefty):
setattribute(b,righty):

a*b;
                               1

b*a;
                               -1

a*b*a; # it inherits the "usual" associativity

                               a

b*a*b;
                               -b

An interesting situation might be where you have a*a returned untouched, and you want to be able to right-multiply this later on by b. (This doesn't happen, if you decide to code it to return say 1 for input a*a.) In such cases, you might need to start ripping apart unevaluated `*` calls when they are the inputs, to figure out what it should do. Eg,

a*a;
                            *(a, a)

%*b; # should it handle this more cleverly?
                           *(a, a) b

Have you considered examining the methodology used in the source of the quaternions package on the application center?

acer

The combination of two files, xxxx.lib and xxxx.ind, for a Library archive is out of date and should be deprecated. It was an outright bug in recent vesions up to Maple 14.01 that help-pages such as ?LibraryTools,Create still described using xxx.lib in Examples. This was fixed in Maple 15 and the Online Help, I think. The recommended way (for some years and major releases now) is to create a single xxxx.mla file for the Library archive.

A file xxxx.hdb is a help database file. See ?INTERFACE_HELP or ?makehelp.

It's really not a good idea to stick new files into your Maple installation's "lib" folder. You or someone else will end up forgetting all that you've added, some day. Better is to add it to another folder altogether, and then augment `libname` in worksheets intended to use it (eg. in Startup code, if you want that hidden from view).

You can also see chapter 10 (and especially section 10.3) of the new Programming Manual. That gets into some detail, as far as the Library side aspects of code autoring goes. But it doesn't show or link so nicely to material on the related aspect of Help Page authorship.

A good start-to-finish example worksheet, clearly covering all these topics in one place with a comprehensive but more straightforward example, on these topics would be a nice addition.

I believe that the InstallerBuilder is an underappreciated part of these tasks, as it allows one to build a self-unpacking .mla which can easily be configured to unpack all the .mla, .hdb, supporting example, source, and other files right into a neat "toolbox" folder. This has the benefit that libname automatically gets the child "lib" folder from such unpacked installations. But this too need an example, as its own help-pages are a bit obscure.

acer

Maple already has CLAPACK (v.3.0 I think) bundled.

Here's an example of setting up such a function for use as a Maple procedure.

Let us know, if you encounter troubles.

If you have a supported NAG Library installed and working, then the NAG package may allow such access already (functions from its chapter F06, F07. and F08).

Who thinks that a complete set of Maple entry points for all BLAS and CLAPACK would be worth the effort? (This should be easy to develop, as the appropriate wrappers from that NAG package could probably be used as templates.)

acer

Did you try loading Units:-Standard first? Doing so should make the multiplication of units combine automatically.

It is not true that ASCII m is an SI prefix equivalent to micro. It's the prefix for milli. See the Units,Prefixes help page. That page has a note,

  ...The correct symbol for the prefix micro is the greek letter m. Because the SI does not
 give an acceptable alternative in an ASCII environment, three prefix symbols have gained
 acceptance in various fields: u, mu, and mc. Any of these prefix symbols is valid in the
 Units package.

It looks like there is a problem with using the prefix `mu`, however, which might be related to why mu doesn't work either. This might be partially corrected by introducing a new unit muF. (Replacing the `farad` unit, to include the alternate prefix, might also be possible but I'm not sure...) This doesn't help with regard to applying the prefix to other units.

 

Error, (in Units:-Unit) `muF` is not a recognized unit

Error, (in Units:-Unit) ``μF`` is not a recognized unit

Units:-AddUnit(muF,context=SI,conversion=microfarad,symbol=`μF`,
               spellings={`&muF`});

 

Download microfarad.mw

acer

> counter:=proc() global c; c:=c+1; NULL; end proc:

> c:=0:

> [seq([seq(op([i,counter()]), j = i .. 5)], i = 1 .. 5)];

    [[1, 1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3], [4, 4], [5]]

> c;
                               15

Maybe simpler,

> restart:

> counter:=proc(x) global c; c:=c+1; x; end proc:

> c:=0:

> [seq([seq(counter(i), j = i .. 5)], i = 1 .. 5)];

    [[1, 1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3], [4, 4], [5]]

> c;
                               15

Here, the argument to `counter` is returned unchanged. So whetever lies at the heart of your innermost `seq` call can just be wrapped in a call to `counter`.

acer

I'm not sure that I understand why you have to enlarge (the image? how?) and then shrink the exported gif.

Is it because the quality of the displayed data portion of the density plot doesn't look good enough, unless the image is large?

I'm not sure whether this is useful to you, but I've had some success writing to image files using ImageTools, after computing the density data directly into Arrays. This can often produce high quality images that look better than what densityplot can do (esp. for color). See here. I'll add a short note about getting axes and text into the image, so that it looks more like a "plot".

acer

The data that you generate (x and f(x)) will have to be in a data structure in order to get plotted. You can insert them into a preconstructed Matrix, or form them as a list of lists, or even print and subsequently read them (into a Matrix) from a file.

Here are a few ways, (trying to keep to your loop methodology where appropriate and practical),

restart:

M:=Matrix(10001,2):
for x from 0 to 100 by 0.01 do
   M[trunc(x*100)+1,..] := <x,sin(x)>;
od:
plot(M);

N:=Matrix(10001,2):
for x from 0 to 100 by 0.01 do
   idx := trunc(x*100)+1;
   N[idx,1], N[idx,2] := x, sin(x);
od:
plot(N);

P:=Matrix(10001,2):
for i from 1 to 10001 do
   x := (i-1)*0.01;
   P[i,1], P[i,2] := x, sin(x);
od:
plot(P);

L:=[seq([x,sin(x)],x=0..100,0.01)]:
plot(L);

#FileTools:-Remove("thedatafile");
for x from 0 to 100 by 0.01 do
  fprintf("thedatafile", "%.10f, %.10f\n",x, sin(x));
od:
fclose("thedatafile");
Q := ImportMatrix("thedatafile", source=csv):
plot(Q);

LinearAlgebra:-Norm(M-Matrix(L));
LinearAlgebra:-Norm(M-N);
LinearAlgebra:-Norm(M-P);
LinearAlgebra:-Norm(M-Q);

acer

Since the upper limit of your integral will evaluate to a float (for nice numeric delta) then `int` will call out to do numeric quadrature. But better to keep things straight and use `Int`, so as to ensure that `int` never wastes time trying to do a mixed symbolic-float integral in some "exact" way (which is often a Bad Idea, as well as time wasting when it fails).

Also, NextZero may try an bump up Digits, which can be unfortunate for evalf(Int(...)) if it makes Digits too high for fast double precision computation, or it this interferes with the convergence acceptance. So I use a proc `fdf` which forces Digits=15 each time its called.

I find that these times below can vary from run to run, even when trying to measure the timings while clearing remember tables. (I suspect there may be a remember table that I am not always clearing.)

f:=Int((50-50*delta)*(50+50*delta)*(0.3e-1+(.36*(1-exp(-.39*t)))
       /(12.00000000*exp(-.39*t)+1))
       *(1-(1-exp(-.39*t))/(12.00000000*exp(-.39*t)+1))/1.08^t,
       t = 0 .. -2.564102564*ln((1.+5.*delta)/(53.+5.*delta)))
     +(500.*(-1.-5.*delta))*(-(1.*(1.+4.*ga))/(-53.+48.*ga))^.197336002905
      /((-1.+1.*ga)*(1.+delta)*((1.+5.*delta)/(53.+5.*delta))^.197336002905):

#plots:-display(seq(plot(eval(f,ga=m),delta=0..2),m=0.1..0.8,0.1));

df:=diff(eval(f,ga=0.1),delta):

forget(evalf); forget(`evalf/int`):st:=time():
fsolve(df=0,delta=0..1);
                          0.1706030333
time()-st;
                             0.219

fdf:=proc(m) Digits:=15: eval(df,delta=m); end proc:

forget(evalf); forget(`evalf/int`):st:=time():
RootFinding:-NextZero(fdf,0.0);
                          0.1706030333
time()-st;
                             0.156

forget(evalf); forget(`evalf/int`):st:=time():
fsolve(fdf,0..1);
                          0.1706030333
time()-st;
                             0.187

A little more time (maybe 15% off those times above) could be saved by specifying some evalf/Int options (such as method=_d01ajc, and maybe digits=15 and epsilon=1e-13). But it's awkward to get these optiona into the Int() call, since they muck with the `diff` call if they are present in the original `f`.

acer

I don't know whether this will help in your more complicated examples...

> restart:

> S:=sum(sum((b[i]-b[j]),i=1..n),j=1..n);

                            n   /          /  n       \\
                          ----- |          |-----     ||
                           \    |          | \        ||
                            )   |          |  )       ||
                     S :=  /    |-n b[j] + | /    b[i]||
                          ----- |          |-----     ||
                          j = 1 \          \i = 1     //

> with(student):

> expand(subs(sum=Sum,S));

                     /  n       \   /  n       \ /  n    \
                     |-----     |   |-----     | |-----  |
                     | \        |   | \        | | \     |
                     |  )       |   |  )       | |  )    |
                  -n | /    b[j]| + | /    b[i]| | /    1|
                     |-----     |   |-----     | |-----  |
                     \j = 1     /   \i = 1     / \j = 1  /

> simplify(value(expand(subs(sum=Sum,S))));

                                      0

acer

The single-backslash \ is being interpreted as an escape character. Try double-backslash like \\, or forward slash.

acer

I suspect that what is happening is that some (or at least one) of the calls to fsolve is not succeeding. When it fails to find a root, it returns as an unevaluated call (to itself). This is not numeric.

It only takes one non-numeric value in the Matrix for `matrixplot` to complain. (It doesn't matter whether some values of the Matrix, such as the [1,1] entry, are numeric. The `matrixplot` command expects all entries to be numeric. So even just one failing fsolve attempt in your code -- as it's currently written -- is going to ruin the `matrixplot` attempt.

You could put a test into your code, to check that Temp is of the expected type (eg, type(Temp,identical(T)=numeric) or what have you). See here (and esp. Joe's comment) for a note on that kind of check outside of a procedure. If any fsolve calls fail then you could try another root-finding mechanism, or insert a special value into the Matrix, or print a Warning, or write nothing new to the relevent Matrix entry, etc. You could code that kind of fallback action with a conditional on the type-check.

Could you please try not to post multiple Questions for the same essential issue? Thanks. If you have followup details or comments on a single issue (at essence) then you can just add a Comment to the original.

acer

The long ton is already present.

> restart:

> kernelopts(version);

          Maple 12.02, X86 64 WINDOWS, Dec 10 2008 Build ID 377066

> convert(1,units,ton[long],lb);

                                    2240
> restart:

> with(Units:-Standard):
> Units:-UseSystem(FPS);

> 2200*Unit(lb/s)+40*Unit(lb/s);

                                         /lb\
                                2240 Unit|--|
                                         \s /

> Units:-AddSystem(mysys,Units:-GetSystem(FPS),ton[long]);
> Units:-UseSystem(mysys);

> 2200*Unit(lb/s)+40*Unit(lb/s);

                                   /ton[long]\
                               Unit|---------|
                                   \ second  /

acer

I've been investigating this idea in some spare time, for a little while. I believe that I, be found a way. At the same time, I've been looking at animatio in Plot Components (with multiplie sliders) or using the "old" animate mechanisms. It's looking promising, although there are some GUI memory leaks that need fixing (but the need fing for plain old animat of 3d plot animate too!). But I'm on vacation for the next 8 days, without a computer or access. Here is a hint, for any adventurous code who has studied theExplore Library code: instead of loading the XML of the new exploring components into a new worksheet, load into a hdb to replace a pre-existing Task,xxxx topic, and then open that topic. Almost all the steps except Insert default Content can be programmed to happen without ned for mouse interaction!d

acer

Have you looked at (right-click) context-sentive menus, with annotations enabled as a GUI option?

One can customize those menus. It might be possible to kludge a set of new/modified context-menu actions which have close to what you want in look and feel. (Possibly with some print-extension stuff.)

Describing to us a complete and explicit example, from the simple algebra exercises say, would help.

Here's the kind of issue that might arise, and it'd be key to know how you'd like it handled: Will you need to simultanelously add and subtract the very same term to the RHS, where the added term is combined with the RHS and the subtracted term is left to augment the new resulting RHS? Do you need both to appear simultanteously on one line, before any combination? If so, then special means have to be used so that they can both be printed ( the `x` and the `-x`) without immediately cancelling. Eg,  LHS = RHS + x - x   as displayed output.

If I understand, you don't want any Maple commands around. Just high school math. So the "steps" returned by the Equation Manipulator assistant is likely not going to help you.

acer

First 276 277 278 279 280 281 282 Last Page 278 of 336