acer

32510 Reputation

29 Badges

20 years, 13 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

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

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(NCP);

acer

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

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

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

Put MAIN and the function mult into two separate source files.

Build a shared object from the mult source file. Something like,

g77 -c -o func.o func.for
g77 -shared -o libfunc.so func.o

Then compile your main program and link to the shared library object you just made. Something like,

g77 -o test2 test2.for -l func

or

g77 -o test2 test2.for -L locationofthesharedlib -lfunc

You would also have to add `-lf2c` and perhaps `-lm` to that last one. I don't know what the libf2c.so support library is called for your version of g77.

Giving any of these files the ms-windows filename extension .dll on Linux or OSX would be confusing and wrong.

Maple's define_external talks to shared library objects, not (runnable) executables. Sorry, I am not at a Linux box to test just now, so some detail of locations could be wrong but this is the general idea.

acer

Add either a colon or a semicolon to the end of the lines within the loop.

I notice that you continue to use round bracket Array indexing like newaa(i,j) on the left-hend side of assignment statements, which is a bad idea as mentioned in responses to your earlier posts.

acer

The web page mentioned in this thread's Question has already been updated with new timings. Those new results show 64bit MS-Windows versions of Maple 2015.0 and Mma 10.02 with matching timing performance for computing the rank of a double-precision Matrix up to size 8000x8000.

Actually there is a modification in that tester's code for Mma 10, which sets the session's kernel history length to a value shorter than the default. That is, it sets $HistoryLength = 0 in Mma syntax. According to a post on community.wolfram.com this nondefault setting had to be used since otherwise Mma 10 did not succeed on the code's testing for sizes above 7500x7500 without memory use exceeding the 16GB RAM on the tester's machine.

acer

You seem to be having trouble with 2D Math.

There is an extra space between kernel__data and (m,n) which I suggest you remove, so that it doesn't get interpreted as implicit multiplication of those terms.

Your use of new2zpic(i, j) on the left-hand side of an assignment statement is ambiguous. I suggest you change all your rtable (Array or Matrix) indexing to use [] square brackets instead of () round brackets.

It seems as if Maple might be interpreting the subscripted name used for an upper loop index value as the oldstyle atomic identifier `#msub(mi("kernel"),mi("length"))` which is not the same name as kernel__length. Your sheet did the earlier assignment of a value to the subscripted name kernel__length.

How about saving yourself all this trouble and coding this program in 1D Notation (in execution groups, or entirely in a Worksheet) instead of in 2D Input in paragraphs in a Document?

acer

Here is code for the surface of revolution of a Reuleaux triangle, which runs in Mapler 15. I extracted it from this MathApp (the .mw file for which is here, but which does not seem to run as is with Maple 15).

This is not the only way to construct it.

restart:
c1:=piecewise(x>0,sqrt(1-(x+1/2)^2),sqrt(1-(x-1/2)^2)):
c2:=sqrt(1-1/2^2)-sqrt(1-(x)^2):
opts := showfunction=false, showrotationline=false, revolutionpoints=100:
std := output=plot,axis=vertical,scaling=constrained:
s1 := Student:-Calculus1:-SurfaceOfRevolution(c1,x=-1/2..1/2,std,opts):
s2 := Student:-Calculus1:-SurfaceOfRevolution(c2,x=-1/2..1/2,std,opts):
S:=plots:-display(s1,s2,caption=``,axes=box):
subsindets(S,specfunc(anything,{PROJECTION,VIEW}),t->NULL);

[edited] I had originally written here that this code produces a Reuleaux tetrahedron, but that is a different surface. The surface of revolution of a Reuleaux triangle is the minimum volume surface of revolution with constant width, which makes it interesting but not what you asked, sorry.

acer

As Carl points out, the performance regression seems due to plot3d no longer using evalhf for procedure J. That is a shame, and I don't see a rationale for it so I'd call this regression a bug.

I'm not sure what Yiannis means by saying the values like lim, lambda, etc, have to be globals. It's easy enough to burn them into a generated procedure, though I note that doing so does not by itself make Maple 18.02 utilize evalhf.

By the way, in Maple 18 the colors from Maple 13 can be duplicated by using the lightmodel=none option, though it looks ugly when inlined into this sight, for some strange reason. I notice also that in the session that it's computed it has the matching colors, but after saving then when reopened in Maple 18 it initially appears different and applies a default lightmodel (until recomputed, sigh).

On my Windows 7 machine with 64bit Maple 18.02 it takes about 14 seconds to produce this plot using evalhf around a wrapped procedure call.

Download Euler_modif.mw

Using the Compiler package it is possible to make both the 3D plot and the 2D densityplot compute even faster. I also separated out the real and imaginary parts, while doing so. (That separation, and even some amount of shoehorning custom formula into a template of procedure J can be programmatic, but making it automatic can be tricky. Here, I did some manual copy and pasting after a few evalc computations.)

The end 3D plot appears the same as above, but computes in a about 3 seconds on my machine.

Euler_compiled.mw

It would be even faster to write an evalhf'ble or compilable procedure which would act inplace on a float[8] Array argument and populate it inplace using the iteration scheme. Such an Array could then be stuffed into a GRID substructure of a PLOT3D structure. It's often much faster to populate an Array all within a single procedure call than to have to invoke a scalar-valued procedure for each entry. (That's how Maple 18's Fractals:-EscapeTime package's commands do it.)

acer

My guess is that you are in the habit of sometimes reexecuting out of order some commands in your Worksheet/Document. That is particularly problematic when you utilize assume. The code below mimics the kind of trouble you can get into when you repeatedly execute calls to assume and assignments with the assumed names.

restart:

interface(showassumed=1):

U := x*P^2/3;
                                      1    2
                                 U := - x P 
                                      3     

assume(P>0);

diff(U,P);

                                    2    
                                    - x P
                                    3    

U := x*P^2/3;

                                      1    2
                                 U := - x P 
                                      3     

assume(P>0);

diff(U,P);

                                      0

Such endeavors are often easier and less problematic if you utilize assuming instead of assume. You can even make an assignment like,

   conds := P>0, Q>0:

and then later on do computations to take that into effect.  Eg,

   some_commmand(something) assuming conds;

 

acer

First 229 230 231 232 233 234 235 Last Page 231 of 337