acer

32622 Reputation

29 Badges

20 years, 44 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@John Dolese One of the fastest and easiest ways to get an integer from a float is to use the `trunc` command. It is a built-in kernel function and very fast. If you don't like the way it rounds (for a mix of negative and positive values, say) then you can use `floor` or `ceil`. These are not mysterious, or rare.

Using the MTM package is relatively rare, on the other hand. It may have been designed for Matlab runtime interaction or emulation, but it is not especially fast. Several of the functions include a thin but not inexpensive layer of Library side interpretative code, with the main "benefit" being to emulate a particular coding style. The MTM package is not close to the top of my list of places to look when I want an efficient floating-point code solution.

The computations you've been doing with colorspaces are naturally purely floating-point. That is not, historically, typical Maple usage. Maple started out as a computer algebra system (CAS), and its abilities to do high performance floating-point computations came considerably later in its long history. I've lost track of the number of times I've read people write things with the sentiment: Why isn't this general purpose thing geared primarily for MY kind of task?

If you want to do intensive floating-point computations in Maple in a fast and efficient way then make use of the several mechanisms available for doing so. I've suggested doing so to you in other places. Perhaps read this or this to see how much improvement is possible.

I mentioned evalhf and datatype=float[8] to you once before and you replied that (after an apparently over-simple direct attempt at drop-in use of one of those) it did not improve your code's performance. I was not kidding when I wrote earlier than I suspect the kinds of computations that is now taking your code minutes if not hours could likely be done in seconds in modern Maple. But you'd need to refactor the code; there isn't a silver bullet for every coding style. Start off with float[8] data structures, procedures which are vectorized (same operation, applied across entries), inplace operations, etc. Then when the style is naturally efficient you'd be in a better place to run it under specialized acceleration methods.

 

Regarding you other question, and again using Maple 13.01,

restart;

# Since we know this...
simplify( convert( (exp(2*a)-1)/(exp(2*a)+1) - tanh(a), exp) );

                                      0

# We can construct a rule like this...
tanhrule := (exp(2*a::anything)-1)/(exp(2*a::anything)+1) = tanh(a):

expr := V0*(exp(2*t/T)-1)/(exp(2*t/T)+1):

applyrule( tanhrule, expr );

                                     /t\   
                                 tanh|-| V0
                                     \T/   

@upslol Why not split the original (by comma, say) and then deal with each separately? Building up `others` by iterated concatenation seems unnecessarily costly (and problematic). Perhaps build three tables of the separate results, and then convert to list or concatenate each of the three (just once) only when finished processing.

@sideshow My advice:

1) Stop using round brackets to refer to the entries of the Matrices A[k]. Especially do NOT use them on the left hand side of assignment statements. Use square brackets. I replaced them all.

2) Your main (outer loop) has a bit at the end where it assigns into A[k+1]. But you forgot to make A[k+1] a Matrix before that happens. So you were just creating A[k+1] as a table, implicitly. I added a line to create A[k+1] as a Matrix (zeroed by default) in a place that seemed suitable.

3) You are relying on implicit multiplication, and it seemed to me that there was a muddle here and there, with either missing spaces or confusion with dot (for dot product). I suggest that you stop using 2D Input and switch over to 1D Maple Notation. See the preferences for the GUI, ie. using the menubar Tools->Options->Display and then change the first drop menu "Input display" from being your current "2-D Math Notation" to being "Maple Notation". Doing so will give you plaintext code mode in which you use * and . explicitly (and space is not allowed for multiplication).

4) I see a problem with the line on which you assign to u[j], where `u` is a Vector. You have it as,

     1/sqrt((1/2)*RSQ * A[k] * w[j]

but later on you treat u[j] as if it were a scalar when assigning to entries of Matrix A[k+1]. I believe that you need to fix that line of code, and suspect that you need to make u[j] a scalar. As you had thing it seems that the entries of `u` were becoming Matrices rather than scalar, and that this cascaded into the entries of Vector `z` and Matrix A[k+1]. If I have misunderstood your purpose then you'll likely have to explain your goal better if you want help with this aspect.

5) It was difficult to find the offending piece of 2D Input that gave you original parsing error. I suspect it was the line

     q := q + A[k][j, k]^2

but I'm not 100% sure because of the round-bracket and other issues. I believe you'd find that with 1D Maple Notation input mode the GUI would also (generally) do better with pointing you to the location of syntax errors.

Matexample_modif.mw

@sideshow Why are you still using round brackets to reference entries of A[k] ? Didn't you read or understand my earlier answer?

Why are you STILL trying to represent 2D Input by pasting here as text?

Why aren't you uploading a worksheet with your full code, or pasting here from valid input as text?

Have you tried using a Worksheet with 1D Maple Notation, since you're having trouble with 2D Input?

@gkokovidis 2D Input strikes again.

@terryma

1) Try to compute your (6) with,

int( simplify(f), s ) assuming real;

or,

simplify( int( simplify(f), s ) ) assuming real.

2) I don't understand what you are trying to say about your expression (5). Where did the x go?

@terryma If your followup comment you are wrong, in at least two cases.

The first case is that the exponent 0.5 is not the same as the exponent 1/2. Maple is capable of both floating-point and exact calculations. You're confusing the two.

((1/7)^2)^(0.5) <> 1/7;

                                       1
                       0.1428571429 <> -
                                       7

The above example makes the earlier results I showed from `is` and `simplify` seem suspect and overzealous. That's why I included the exact exponent 1/2 in my original response. Compare also with,

(x^0.5)^2;

                               1.0
                              x   

simplify(%);

                              1. x

which falls down on say,

sqrt(2)^(1.0);

                          1.414213562

1.0*sqrt(2);

                                (1/2)
                           1.0 2     

And what's a good rule without exceptions to exceptions to the rule?

exp(1)^(1.0);

                                  1.0
                          (exp(1))   

A second case now is that in your followup explanation you left out the earlier qualifier that x is positive (or even nonnegative). But I believe you are already aware of this, from before.

((-2.0)^2)^(0.5) <> -2.0;

                      2.000000000 <> -2.0

You should be very cautious about using a float exponent if you don't have to. So that's one thing for you to take away: power 0.5 is different from power 1/2.

Another thing to keep in mind is that it is the command `sqrt` which computes. You can call the `simplify` command on x^(1/2) , but otherwise raising to 1/2 will not do much of anything. Compare these results:

sqrt( x^2 ) assuming x>0;

                               x

( x^2 )^(1/2) assuming x>0;

                               (1/2)
                           / 2\     
                           \x /     

simplify( ( x^2 )^(1/2) ) assuming x>0;

                               x

@Mac Dude I obtain a plot much like yours, using the following code. But I see this as wrong, because it does not account for the fact the the first column (presumably the independent data) is not equally spaced.

restart;

M:=ImportMatrix(cat(kernelopts(homedir),"/Documents/mapleprimes/Tyr_rv9_Maple.csv")):

freq:=DiscreteTransforms:-FourierTransform(M[..,2]):

plots:-listplot(abs~(freq)[1..floor(op(1,freq)/2)],
                axis[2]=[mode=log],gridlines=false,axes=box,size=[480,300]);

Download hmm.mw

I did some other analysis earlier today. I'll try to clean it up now.

@Maple4evergr8 Did you say what OS you use? Sorry, if i missed that. It might be key to why the popup plot device is not working from you from the Command Line Interface.

I think that I don't properly understand why you have to use the CLI. It sounds to me like part of your requirements are some modal (confirmation) dialogue stuff. So altogether it seems you want console/plot separation, confirmation dialogues, ... (other?). Maplets are useful for all that, as are Embedded Components. But you might be able to get by with the readline command in the CLI for confirmation.

It might not be important to you, but the commandline interface also has plot drivers which do not fully respect some modern plot features, sich as programmatic 2D plot size, background image, and some other stuff.

@Maple4evergr8 You wrote, "So, is there an easy way in general to save "frames" of an animation, which you afterwards then use to re-create the animation?"

See the code in the proc in my answer (even if you don't like the idea of console-like output in a GUI block) for saving each frame as a table entry and then recombining (plots:-display) in sequence to obtain an animation.

@Elzas Is there some reason why B(z) is no better than a some linear interpolation?

If you only want float values for F(t) then have you tried evalf(Int(...)) to force only numeric integration, rather than using lowercase evalf(int()) where Maple spends time attempting a symbolic integral for every t value?

You wrote expt and I'm not sure what you meant there.

If MTM:-sort and :-sort both did the very same thing for all kinds of input then there'd be no reason for the existence of both.

You can read the ?MTM help page and see that the commands were designed to support the runtime of the Maple Toolbox for Matlab.

You can force use of that package version, even when the MTM package is not loaded, by calling it like MTM:-sort( V ) .

You can force the use of the global version, even when the MTM package is loaded, by calling it like :-sort( V ) .

So such problems may be resolvable, whether the package is loaded or not.

In your examples it also not clear why you had to load the MTM package.

Start by stating clearing you operating system and version, and you Maple version.

acer

Is your F evalhf'able? I mean, does F work if you call it like evalhf(F( somenumericvalue )) ?

Why not show us your F? Perhaps we could find suggestions to make it faster, even if it's not evalhf'able.

The `plot` command will try to work adaptively, by default. It may figure out that fewer points are required in some subregions of `t`, and more in others. And it may well be computing fewer points than you imagine. You could use getdata to figure out just how many points are in the plot structure.

The plot renderer may also be interpolating to make the curve show smooth. Perhaps you could do something similar, by generating a modest number of values and then calling ArrayInterpolation to extend to 1000 values.

It's difficult to suggest more without knowing details of F or the resulting plot.

acer

First 318 319 320 321 322 323 324 Last Page 320 of 596