acer

9 years, 178 days


These are answers submitted by acer

sigh

3 hours ago acer 10953

This is not good.

I merge execution groups (using the F4 key, say) often when programming in 1D mode. And prior to Maple 2015 I've relied on the fact that lines which begin with a prompt and those which don't are not treated differently, as far as multiple line statements go. And now in Maple 2015 this is broken.

This is a serious regression bug. Its cause is new behaviour in the Standard GUI of Maple 2015, in which a 1D Maple Notation input line need not be terminated with either colon or semicolon. I suppose this was intended as a convenience, implemented without giving adequate consideration to the fact that it introduces ambiguity to the language and breaks previously valid syntax.

Here is a simple example. This example of 1D Maple Notation code works in Maple 18 and earlier, but fails with a syntax error in the Standard GUI of Maple 2015. Note that these lines all occur within the same Execution Group.

for i from 1

  to 3 do

  i end do;

Error, `;` unexpected

Download multilineregression.mw

1D Maple Notation programming in an Execution Group of a Worksheet was one of the few (if only) adequately stable, reliable, and usable modes of programming in the Standard GUI.

The OP's plotting example is a good illustration of the kinds of things that are typical usage. Suppose you have three plot calls in three seeparate execution groups. You can merge the execution groups using just F4, with no need for cut & paste. And then remove a few terminators, and wrap in a `print` call, and the plotting's all combined. Easy. No need to mark out long lines wih the mouse cursor. And by having the print call on a separate line it's even easy to undo it, or toggle the merging on and off just by adding a few # symbols. Easy and useful. But now, a previously valid and straightforwardly natural way to accomplish this has been broken.

It might be ok to remove the need for a colon/semicolon terminator at the end of the last line of an Execution Group. But it's very much wrong to have the parser try and execute every line (lacking a colon/semicolon terminator) before the last line of an Execution Group.

acer

FormalPowerSeries

Yesterday at 4:43 PM acer 10953
convert(BesselJ(0,x),FormalPowerSeries);

                          infinity
                           -----       k  (-k)  (2 k)
                            \      (-1)  4     x
                             )     ------------------
                            /                2
                           -----         (k!)
                           k = 0

acer

procedure form

March 25 2015 acer 10953

If instead of working with expressions you are ok working with procedures  (or operators, as `unapply` can give you) which each accept multiple arguments then you might look at this old post of mine. It is not written with a particular number of procedure arguments (or variables, if you will) hard-coded.

Note that one can find example problems which appear to converge to a point which is neither a root nor even close to a root, when using an implementation of Newton's method with only the iteration number and the norm-of-change-in-variables as its stopping criteria. A good rootfinding implementation should also offer a check on forward error (plugging the candidate solution back into the equations), to test if an actual root has been detected.

acer

Tips and Techniques

March 24 2015 acer 10953

The articles here and here, from the Maple Reporter Tips and Techniques series, might be of some use to you.

acer

module

March 23 2015 acer 10953

@itsme The Explore "command" is an appliable module, not a procedure. When you call `Explore(...)` what you're actually invoking is the module local Explore:-ModuleApply. And so you'd need to change that local, not `Explore` itself. If you just assign some edited proc to the unprotected name `Explore` then you're blowing away the rest of the module.

usual access

March 22 2015 acer 10953

The fact that the display shows only a summary has nothing to do with accessing the entries of the Matrix in the usual ways (other than crude cut & paste). Even with the displayed summary you can still assign the Matrix to a name and then access its rows, columns, or individual entries by using the usual square-bracket indexing. Or you can do further computation using other commands, including those available via the right-click context-menus.

If you really wish to see all the entries displayed explicitly then you can change the values of the interface(rtablesize) setting. See the interface help page for a description. Eg,

interface(rtablesize=50):

acer

``?

March 22 2015 acer 10953

Did you intend to write ``(1600) instead of (1600) ? And similarly for the (1500).

If so then can you not just switch the order in which you do those two eval calls?

param:= {mu[2] = ``(1600), mu[4] = ``(1500)}:
R := unapply(1/(1+exp((1/50)*x)), x):
evalf(eval(eval(R(abs(mu[4]-mu[2])), param), ``=(x->x)));

                          0.1192029220

acer

add

March 16 2015 acer 10953
add( x*ln(x), x = X );

This uses the kernel builtin add for efficiency (not producing a temporary list as collectible garbage).

Your example data seems to be just integers. If you are expecting a float result then you might want to wrap evalf around the expression argument. Ie, evalf(x*ln(x)).

acer

On my 64bit Maple 18.02 running on Windows 7 I see the extra space added when exporting as a .pdf file.

On 64bit Maple 2015.0 on the same machine I am not seeing that extra space on such export.

So on my machine this seems to have been fixed in Maple 2015.0.

Perhaps someone with OS X can confirm.

acer

statement terminators

March 15 2015 acer 10953

Where are your statement separators (colon or semicolon) between the statements within the loop? 

Why is lowercase letter o used as the lower index value for the j-loop? Did you intend the number 0 instead?

Why do try to use n (to form Arrays) before you actually assign a value to n?

Where you use N did you intend n?

acer

print

March 13 2015 acer 10953
print(NCP);

acer

eval

March 11 2015 acer 10953
eval(splcurve) assuming v>=3, v<4.2;

acer

Actually, it is the inner name-quotes (single left quotes) that you are not seeing.

That's because you have interface(prettyprint) too high.

Try it with prettyprint=1 instead. Note the _syslib attribute needs to be stripped off, in order for the proc body to be displayed when prettyprint=1. Below I do this to a copy of dsolve, since I don't want to mess with my session's actual dsolve procedure.

restart:
interface(prettyprint=1):
interface(verboseproc=3):
print( setattribute(copy(dsolve)) );

[edit] I was surprised to need to strip the _syslib attribute above. I was running the code in the Standard GUI, to see for myself what I'd guessed about the problem of doing it with prettyprint=3. I knew that prettyprint=0 made verboseproc irrelevant here, but didn't expect it for prettyprint=1. But sure enough I was definitely seeing an elided proc body for the printing of dsolve with the setting as above. Now when I try it again it seems to work as expected, without needing setattribute and copy. This is not the first time that the GUI's own interface implementation has acted up in a transient manner.

acer

Compatibility Section

March 10 2015 acer 10953

According to the "Compatibility" section of the ?add help page for Maple 2015,

  "The step parameter was introduced in Maple 2015."

That new option could be better documented in the Examples section, IMO. Eg,

seq(i, i=1...7, 2 );

                                 1, 3, 5, 7

add(i, i=1...7, 2 );
                                     16

seq(1+2*(i-1), i=1..4 );

                                 1, 3, 5, 7

add(1+2*(i-1), i=1..4 );
                                     16

acer

codegen[optimize]

March 10 2015 acer 10953

The bodies procedures in the attached worksheet are computation sequences, and they each return a list of three results that correspond to X, Y, and Z.

The point is that common subexpressions (eg. t31, t45, t50...) may be used in more than one of the three. The idea is to try and keep the total arithmetic operation count down.

It might be possible to produce initial expressions that are even shorter than what simplify(...,size) provides. If I get big success I'll let you know.


restart:

X := L10*cos(q5) - L16*(sin(q10)*(sin(q5)*sin(q8) - cos(q8)*(cos(q5)*cos(q6)*cos(q7) - cos(q5)*sin(q6)*sin(q7))) - cos(q10)*(sin(q9)*(cos(q8)*sin(q5) + sin(q8)*(cos(q5)*cos(q6)*cos(q7) - cos(q5)*sin(q6)*sin(q7))) + cos(q9)*(cos(q5)*cos(q6)*sin(q7) + cos(q5)*cos(q7)*sin(q6)))) - d2*(cos(q10)*(sin(q5)*sin(q8) - cos(q8)*(cos(q5)*cos(q6)*cos(q7) - cos(q5)*sin(q6)*sin(q7))) + sin(q10)*(sin(q9)*(cos(q8)*sin(q5) + sin(q8)*(cos(q5)*cos(q6)*cos(q7) - cos(q5)*sin(q6)*sin(q7))) + cos(q9)*(cos(q5)*cos(q6)*sin(q7) + cos(q5)*cos(q7)*sin(q6)))) + L15*(sin(q9)*(cos(q8)*sin(q5) + sin(q8)*(cos(q5)*cos(q6)*cos(q7) - cos(q5)*sin(q6)*sin(q7))) + cos(q9)*(cos(q5)*cos(q6)*sin(q7) + cos(q5)*cos(q7)*sin(q6))) - L11*cos(q5)*sin(q6) + d1*cos(q5)*cos(q6) - L13*sin(q5)*sin(q8) + L14*cos(q9)*(cos(q8)*sin(q5) + sin(q8)*(cos(q5)*cos(q6)*cos(q7) - cos(q5)*sin(q6)*sin(q7))) + L13*cos(q8)*(cos(q5)*cos(q6)*cos(q7) - cos(q5)*sin(q6)*sin(q7)) - L14*sin(q9)*(cos(q5)*cos(q6)*sin(q7) + cos(q5)*cos(q7)*sin(q6)) + L12*cos(q5)*cos(q6)*cos(q7) - L12*cos(q5)*sin(q6)*sin(q7):

 

Y := L10*sin(q5) - L9 + L16*(sin(q10)*(cos(q5)*sin(q8) - cos(q8)*(sin(q5)*sin(q6)*sin(q7) - cos(q6)*cos(q7)*sin(q5))) - cos(q10)*(sin(q9)*(cos(q5)*cos(q8) + sin(q8)*(sin(q5)*sin(q6)*sin(q7) - cos(q6)*cos(q7)*sin(q5))) - cos(q9)*(cos(q6)*sin(q5)*sin(q7) + cos(q7)*sin(q5)*sin(q6)))) + d2*(cos(q10)*(cos(q5)*sin(q8) - cos(q8)*(sin(q5)*sin(q6)*sin(q7) - cos(q6)*cos(q7)*sin(q5))) + sin(q10)*(sin(q9)*(cos(q5)*cos(q8) + sin(q8)*(sin(q5)*sin(q6)*sin(q7) - cos(q6)*cos(q7)*sin(q5))) - cos(q9)*(cos(q6)*sin(q5)*sin(q7) + cos(q7)*sin(q5)*sin(q6)))) - L15*(sin(q9)*(cos(q5)*cos(q8) + sin(q8)*(sin(q5)*sin(q6)*sin(q7) - cos(q6)*cos(q7)*sin(q5))) - cos(q9)*(cos(q6)*sin(q5)*sin(q7) + cos(q7)*sin(q5)*sin(q6))) + L13*cos(q5)*sin(q8) - L11*sin(q5)*sin(q6) + d1*cos(q6)*sin(q5) - L14*cos(q9)*(cos(q5)*cos(q8) + sin(q8)*(sin(q5)*sin(q6)*sin(q7) - cos(q6)*cos(q7)*sin(q5))) - L13*cos(q8)*(sin(q5)*sin(q6)*sin(q7) - cos(q6)*cos(q7)*sin(q5)) - L14*sin(q9)*(cos(q6)*sin(q5)*sin(q7) + cos(q7)*sin(q5)*sin(q6)) + L12*cos(q6)*cos(q7)*sin(q5) - L12*sin(q5)*sin(q6)*sin(q7):

 

Z := L15*(cos(q9)*(cos(q6)*cos(q7) - sin(q6)*sin(q7)) - sin(q8)*sin(q9)*(cos(q6)*sin(q7) + cos(q7)*sin(q6))) - L11*cos(q6) - L8 - d1*sin(q6) + L16*(cos(q10)*(cos(q9)*(cos(q6)*cos(q7) - sin(q6)*sin(q7)) - sin(q8)*sin(q9)*(cos(q6)*sin(q7) + cos(q7)*sin(q6))) - cos(q8)*sin(q10)*(cos(q6)*sin(q7) + cos(q7)*sin(q6))) - d2*(sin(q10)*(cos(q9)*(cos(q6)*cos(q7) - sin(q6)*sin(q7)) - sin(q8)*sin(q9)*(cos(q6)*sin(q7) + cos(q7)*sin(q6))) + cos(q8)*cos(q10)*(cos(q6)*sin(q7) + cos(q7)*sin(q6))) - L13*cos(q8)*(cos(q6)*sin(q7) + cos(q7)*sin(q6)) - L14*sin(q9)*(cos(q6)*cos(q7) - sin(q6)*sin(q7)) - L12*cos(q6)*sin(q7) - L12*cos(q7)*sin(q6) - L14*cos(q9)*sin(q8)*(cos(q6)*sin(q7) + cos(q7)*sin(q6)):
length(X), length(Y), length(Z);

                              1817, 1822, 1197

unknwns := [indets([X,Y,Z],And(name,Non(constant)))[]];

unknwns := [L10, L11, L12, L13, L14, L15, L16, L8, L9, d1, d2, q10, q5, q6,

  q7, q8, q9]

f := unapply([X,Y,Z],[indets([X,Y,Z],And(name,Non(constant)))[]]):

fopt := codegen[optimize](f,tryhard);

fopt := proc(L10, L11, L12, L13, L14, L15, L16, L8, L9, d1, d2, q10, q5, q6,
  q7, q8, q9)
local result, t1, t10, t11, t12, t14, t15, t16, t17, t18, t19, t2, t20, t21,
  t22, t23, t24, t25, t26, t27, t28, t29, t3, t30, t5, t6, t7, t8, t9;
  t18 := sin(q7);
  t19 := sin(q6);
  t23 := cos(q7);
  t24 := cos(q6);
  t12 := t18*t24 + t19*t23;
  t17 := sin(q8);
  t30 := t12*t17;
  t22 := cos(q8);
  t29 := t12*t22;
  t25 := cos(q5);
  t20 := sin(q5);
  t27 := t18*t19 - t23*t24;
  t8 := t27*t20;
  t6 := t17*t25 - t22*t8;
  t11 := t27*t25;
  t28 := -t11*t22 - t17*t20;
  t26 := -L11*t19 - L12*t27 + d1*t24 + L10;
  t21 := cos(q9);
  t16 := sin(q9);
  t15 := cos(q10);
  t14 := sin(q10);
  t10 := t12*t25;
  t9 := t12*t20;
  t7 := t17*t8 + t22*t25;
  t5 := -t11*t17 + t20*t22;
  t3 := -t16*t30 - t21*t27;
  t2 := t16*t7 - t21*t9;
  t1 := t10*t21 + t16*t5;
  result := [-L16*(-t1*t15 - t14*t28) - d2*(t1*t14 - t15*t28) + L15*t1
   + (-t10*t16 + t21*t5)*L14 + t28*L13 + t26*t25, -L9 + L16*(t14*t6 - t15*t2)
   + d2*(t14*t2 + t15*t6) - L15*t2 + (-t16*t9 - t21*t7)*L14 + t6*L13 + t26*t20, L15*t3
   - L11*t24 - L8 - d1*t19 + L16*(-t14*t29 + t15*t3) - d2*(t14*t3 + t15*t29)
   - L13*t29 + (t16*t27 - t21*t30)*L14 - t12*L12];
end proc;

A,B,C := simplify(X,size), simplify(Y,size), simplify(Z,size):
length(B), length(B), length(C);

                                996, 996, 787

g := unapply([A,B,C],[indets([A,B,C],And(name,Non(constant)))[]]):
gopt := codegen[optimize](g,tryhard);

gopt := proc(L10, L11, L12, L13, L14, L15, L16, L8, L9, d1, d2, q10, q5, q6,
  q7, q8, q9)
local result, t31, t32, t34, t36, t37, t39, t40, t41, t42, t43, t44, t45, t46,
  t47, t48, t49, t50, t52, t58, t61, t63;
  t39 := sin(q10);
  t40 := cos(q10);
  t37 := L16*t40 - d2*t39 + L15;
  t41 := sin(q9);
  t46 := cos(q9);
  t34 := L14*t46 + t37*t41;
  t36 := L16*t39 + d2*t40 + L13;
  t42 := sin(q8);
  t47 := cos(q8);
  t32 := -t34*t42 - t36*t47 - L12;
  t43 := sin(q7);
  t48 := cos(q7);
  t52 := L14*t41 - t37*t46;
  t63 := -t32*t48 - t43*t52 + d1;
  t61 := t32*t43 - t48*t52 - L11;
  t58 := -t34*t47 + t36*t42;
  t50 := cos(q5);
  t49 := cos(q6);
  t45 := sin(q5);
  t44 := sin(q6);
  t31 := t44*t61 + t49*t63 + L10;
  result := [t31*t50 - t58*t45, t31*t45 + t58*t50 - L9, -t44*t63 + t49*t61 - L8
  ];
end proc;

codegen[cost]( f );

             93 additions + 229 multiplications + 289 functions

codegen[cost]( fopt );

28 storage + 29 assignments + 12 functions + 65 multiplications + 40 additions

codegen[cost]( g );

             119 multiplications + 93 additions + 119 functions

codegen[cost]( gopt );

21 storage + 22 assignments + 12 functions + 20 additions + 24 multiplications

# check fopt
simplify( fopt(unknwns[]) - [X, Y, Z] );

                                  [0, 0, 0]

# check gopt
simplify( gopt(unknwns[]) - [X, Y, Z] );

                                  [0, 0, 0]

CodeGeneration[Matlab](gopt);

function goptreturn = gopt(L10, L11, L12, L13, L14, L15, L16, L8, L9, d1, d2, q10, q5, q6, q7, q8, q9)

  t39 = sin(q10);
  t40 = cos(q10);
  t37 = L16 * t40 - d2 * t39 + L15;
  t41 = sin(q9);
  t46 = cos(q9);
  t34 = L14 * t46 + t37 * t41;
  t36 = L16 * t39 + d2 * t40 + L13;
  t42 = sin(q8);
  t47 = cos(q8);
  t32 = -t34 * t42 - t36 * t47 - L12;
  t43 = sin(q7);
  t48 = cos(q7);
  t52 = L14 * t41 - t37 * t46;
  t63 = -t32 * t48 - t43 * t52 + d1;
  t61 = t32 * t43 - t48 * t52 - L11;
  t58 = -t34 * t47 + t36 * t42;
  t50 = cos(q5);
  t49 = cos(q6);
  t45 = sin(q5);
  t44 = sin(q6);
  t31 = t44 * t61 + t49 * t63 + L10;
  result = [t31 * t50 - t58 * t45 t31 * t45 + t58 * t50 - L9 -t44 * t63 + t49 * t61 - L8];
  goptreturn = result;

 


Download optimfun.mw

acer

1 2 3 4 5 6 7 Last Page 1 of 108