acer

13310 Reputation

29 Badges

11 years, 265 days

On google groups. (comp.soft-sys.math.maple and sci.math.symbolic)

On stackoverflow.

On math.stackexchange.com.

MaplePrimes Activity


These are answers submitted by acer

Why not use the -c option of cmaple, to assign the filename string (and read MyCode too if you want).

Then you just need Eclipse to form the full call to cmaple.

To get the dot notation for the derivatives you can issue this command at the top of the Document.

Typesetting:-Settings(typesetdot=true, usedot=true, dot=t):

If you didn't need the derivatives to be pretty-printed in dot notation then you could simply set the typesetting level to standard. Getting the formatting effect you describe, without setting typesetting to standard, requires fooling the system into not recognizing that common 1/2 factor as being a rational number. There are a few ways to do that, some fancier than others. See this attachment formatting.mw .

As far as grouping with respect to particular variable names goes, see the collect command.

These should also produce a plot as shown in Adri's answer:

restart;
S:=proc(u,v) 10*u^2+20*u*v+15; end proc:
p:=proc(u,v) if u<v then S(u,v); else S(u,v)+10; end if; end proc:
h:=proc(u) 2*u; end proc:
plot3d([(u,v)->40*u,(u,v)->80*v,p], 0..1, 0..h);


restart;
ee:=10*u^2+20*u*v+15:
plot3d([40*u,80*v,piecewise(u<v,ee,ee+10)], u=0..1, v=0..2*u);


restart;
S:=proc(u,v) 10*u^2+20*u*v+15; end proc:
p:=proc(u,v)
    if not ( u::numeric and v::numeric ) then
      return 'procname'(args);
    end if;
    if u<v then
      S(u,v);
    else
      S(u,v)+10;
    end if;
end proc:
plot3d([40*u,80*v,p(u,v)], u=0..1, v=0..2*u);

Apply the procedure to some name(s).

Maple is telling you, correctly, that it cannot cast an unassigned name to a hardware double-precision floating-point number.

And your command instructs Maple to convert every element of K to a double-precision float.

Do you think that the name actually has a value which should evaluate to a float?

Is there some possibility that there are two similar names in play (perhaps a copy and paste mismatch of atomic identifiers)? It's hard to be more specific if you don't bother to upload a worksheet that exhibits the problem.

I'm not really content with having to break up the original condition, let alone the speed, but...

kernelopts(version);

   Maple 2017.0, X86 64 LINUX, May 17 2017, Build ID 1231047

sol:=CodeTools:-Usage(
       SolveTools:-SemiAlgebraic(
         { evalc(abs(a+b*I+3-2*I))^2 =(K1)^2,
           evalc(abs(a+b*I-3-8*I))^2 = (K2)^2,
           K1>=0, K2>=0, (K1+K2)^2=(6*sqrt(2))^2},
           {K1,K2} ) ):
memory used=47.74GiB, alloc change=1.12GiB, cpu time=8.79m, real time=5.81m, gc time=4.39m

sollist:=PiecewiseTools:-ToList(sol):
bettersol:=solve(Or(seq(sollist[i,1],i=1..nops(sollist)-1)));

       bettersol := {a = b - 5, 2 <= b, b <= 8}

expr:=eval(evalc(abs(a+b*I)),op(1,bettersol));

                            2    2 1/2
            expr := ((b - 5)  + b )

brng:=`..`(op([2,..],convert(And(op(2..3,bettersol)),RealRange)));

                   brng := 2 .. 8

simplify( [ minimize( expr, b=brng, location) ] ):
op(1,%), op([2,1,1,..],%), eval(op(1,bettersol), op([2,1,1],%));

                1/2
             5 2
            ------, b = 5/2, a = -5/2
              2

simplify( [ maximize( expr, b=brng, location) ] ):
op(1,%), op([2,1,1,..],%), eval(op(1,bettersol), op([2,1,1],%));

                 1/2
               73   , b = 8, a = 3

Use procedures as much as possible. Have the procedures be exports of a module. Keep all the procedures' sources (including those for all module members, whether locals or exports) in individual plaintext files, and keep the module's source in another text file. Use the $include directive to reference the module-members' sources from within that of the parent module.

That way all our procedures are defined in separate plaintext files, and they can all be used with full revision control. (Over the last 20 years I have used at least 4 different revision control systems on large Maple projects, with all the source in text files. Mostly unix/linux/cygwin. )

Next, write a short bit of code that uses the Maple `read` command, which pulls in and interprets all the above (e.g. read the master module defn file). This can build everything in a few lines. Optionally a separate short command can savelib the modules to ".mla" Library archive.

If you like you can make regular use of the $define directive at each text file's head, to specify common keywords. I do this to keep all references to other, stock package exports (e.g. LinearAlgebra) terse. You can even put such stuff in "include files".  

I keep module defns in text files with extension ".mpl", and module members (local or exported procedures or submodules) in text files with extension ".mm", and other included common stuff in files ".mi".

Of course, all the files then have their own revision histories.

All the above makes my Maple project development scheme match that of my C/C##/etc projects, at least as far as "action code" goes.

You wrote "application". Does that mean an assembly of interactive components? For that kind of application I now generate the full worksheet and its components programatically, using text files there too. So my project's graphical interface bits are revision controlled just like my project's engine bits.

For this example,
 

restart;

SS:=eval(S,isolate(((2*a*sin(S)*cos(S)^(2)))/(1-sin(S)^(3))=1,S)):
SS:=simplify(SS) assuming a>1:

shi:=eval(SS,a=1):

conds:=[S<SS,a>1,S>-Pi/2]:

plots:-inequal(conds,S=-Pi/2..shi,a=1..10,xtickmarks=piticks);


 

op(conds),S<shi;

S < arctan((1/2)*(-2*a+1+(4*a^2+4*a-3)^(1/2))*2^(1/2)/((2*a-1)^(1/2)*((4*a^2+4*a-3)^(1/2)+2*a-3)^(1/2))), 1 < a, -(1/2)*Pi < S, S < arctan((1/2)*(5^(1/2)-1)^(1/2)*2^(1/2))

trigsol.mw

z:=a+b*I:                                                     

extrema(evalc(abs(z)),evalc({abs(z+1)+4*abs(z-1)=25}),
        {a,b});

                           {22/5, 28/5}

extrema(evalc(abs(z)),evalc({abs(z+1)+4*abs(z-1)=25}),
        {a,b}, 's');

                           {22/5, 28/5}

s;

               {{a = -22/5, b = 0}, {a = 28/5, b = 0}}
On stackexchange you seem to have come up with abs(z)=sqrt(591/17). So what point z (with that modulus) satisfies the additional constraint?

There's likely an easier way... (especially to obtain gg from ff).

ee:=int((0.0064-0.06851*I)/(0.0402+0.0868*I)
        *exp((-0.9696+0.7611*I)
             /(0.0402+0.0868*I)*(t-tau)),tau=0..t):

ff:=simplify(ee);

0.3840233117e-1-0.4051359914e-1*I+(-0.3840233117e-1+0.4051359914e-1*I)*exp((2.96007991+12.54141950*I)*t)

gg:=subsindets(
      eval(simplify(
             subsindets(ff,'complex(float)',
                        u->``(csgn(u))
                           *convert(u/csgn(u),polar))),
           ``=(u->u)),
      'specfunc(anything,polar)',
      evalc);

(0.3840233118e-1-0.4051359914e-1*I)*(-exp((2.960079912+12.54141950*I)*t)+1)

subsindets(gg,
           'specfunc(anything,exp)',
           u->simplify((Re+Im*I)(u))) assuming t::real;

(0.3840233118e-1-0.4051359914e-1*I)*(-exp(2.960079912*t)*(I*sin(12.5414195*t)+cos(12.5414195*t))+1)

 

Download simpp.mw

It's not completely clear to me why (a/b)^p is wanted but not (w__2/w__1)^p.

And it's not clear to me whether the order of the multiplicands in the desired target form will matter.

Also, I might elect for a mechanism that did not rely on the happenstance position of any of the multiplicands, at any intermediate stage.

So below are two more ways to follow up Kitonum's Answer's first stage, which focus deliberately on a/b. For this example it's not necessary to assume y>0 so I wrote out all the other assumptions for that first stage, despite it being longer code. (You might know that you can assume all positive, however.) The second way makes extra effort, just to ensure that the (a/b)^p term appears at left, as the first multiplicand in the final form.

restart;

x__1 := y^(1/(a+b))/(w__1*b/(a*w__2))^(b/(a+b)):
B := combine(expand(x__1)) assuming a>0, b>0, w__1>0, w__2>0:

map(normal,eval(simplify(eval(B,a=Q*b)),Q=a/b)) assuming a>=0, b>=0;

y^(1/(a+b))*w__1^(-b/(a+b))*(a/b)^(b/(a+b))*w__2^(b/(a+b))

restart;

x__1 := y^(1/(a+b))/(w__1*b/(a*w__2))^(b/(a+b)):
B := combine(expand(x__1)) assuming a>0, b>0, w__1>0, w__2>0:

map(`*`@op,[selectremove(type,[op(B)],identical(a,b)^anything)]):
`*`(op(normal(eval(simplify(eval(%,a=Q*b)),Q=a/b)))) assuming a>=0, b>=0;

(a/b)^(b/(a+b))*y^(1/(a+b))*w__1^(-b/(a+b))*w__2^(b/(a+b))

 

Download algform.mw

Have you tried mapping the fnormal command onto the Matrix (possibly with extra arguments for it's optional parameters digits and epsilon)?

Since mat1 is that string then have you tried %s rather than %a in the format of this call to fprintf?

fprintf(filename2,"\n    arr = np.array([%a",mat1): 

restart; Digits := 20; a := 1.689; f := proc (n, Z) options operator, arrow; a*(sum(Z^(2*i)*hypergeom([n-i+2, 1/2], [3/2], cos(-Z^2/a))*(sum(pochhammer(n^2, j)*sin(Pi*Z^2/n), j = 0 .. i))/factorial(i)^2, i = 0 .. 100)) end proc; str := time[real](); simplify(fnormal(f(3, 1)), zero); simplify(fnormal(f(5, 1.1)), zero); simplify(fnormal(f(3, .92)), zero); (time[real]()-str)*seconds

1572.6261454761299422

68711.440007753956843

2648.5507166498596403

3.665*seconds

restart; Digits := 20; a := 1.689; f := proc (n, Z) options operator, arrow; a*(Sum(Z^(2*i)*hypergeom([n-i+2, 1/2], [3/2], cos(-Z^2/a))*(Sum(pochhammer(n^2, j)*sin(Pi*Z^2/n), j = 0 .. i))/factorial(i)^2, i = 0 .. 100)) end proc; str := time[real](); simplify(fnormal(evalf(f(3, 1))), zero); simplify(fnormal(evalf(f(5, 1.1))), zero); simplify(fnormal(evalf(f(3, .92))), zero); (time[real]()-str)*seconds

1572.6261454761299423

68711.440007753956845

2648.5507166498596401

.148*seconds

 

Optimizing the summand allows for a quicker computation.

 

restart; Digits := 20; a := 1.689; K := Sum(pochhammer(n^2, j)*sin(Z^2*Pi/n), j = 0 .. i); K := subsindets(K, specfunc(anything, pochhammer), proc (u) options operator, arrow; convert(u, GAMMA) end proc); S := a*(Sum(Z^(2*i)*hypergeom([n-i+2, 1/2], [3/2], cos(-Z^2/a))*K/factorial(i)^2, i = 0 .. 100)); f := `assuming`([unapply(simplify(S), [n, Z])], [n::posint, Z > 0]); str := time[real](); simplify(fnormal(evalf(f(3, 1))), zero); simplify(fnormal(evalf(f(5, 1.1))), zero); simplify(fnormal(evalf(f(3, .92))), zero); (time[real]()-str)*seconds

1572.6261454761299422

68711.440007753956839

2648.5507166498596402

0.82e-1*seconds

 

But perhaps you are trying to approximate the infinite sum?

It looks like `evalf/Sum` can figure that out even quicker.

Optimizing the summand helps here too (though not as much of a gain.

 

restart; Digits := 20; a := 1.689; f := proc (n, Z) options operator, arrow; a*(Sum(Z^(2*i)*hypergeom([n-i+2, 1/2], [3/2], cos(-Z^2/a))*(Sum(pochhammer(n^2, j)*sin(Pi*Z^2/n), j = 0 .. i))/factorial(i)^2, i = 0 .. infinity)) end proc; str := time[real](); simplify(fnormal(evalf(f(3, 1))), zero); simplify(fnormal(evalf(f(5, 1.1))), zero); simplify(fnormal(evalf(f(3, .92))), zero); (time[real]()-str)*seconds

1572.6261454761299423

68711.440007753956845

2648.5507166498596401

0.75e-1*seconds

restart; Digits := 20; a := 1.689; K := Sum(pochhammer(n^2, j)*sin(Z^2*Pi/n), j = 0 .. i); K := subsindets(K, specfunc(anything, pochhammer), proc (u) options operator, arrow; convert(u, GAMMA) end proc); S := a*(Sum(Z^(2*i)*hypergeom([n-i+2, 1/2], [3/2], cos(-Z^2/a))*K/factorial(i)^2, i = 0 .. infinity)); f := `assuming`([unapply(simplify(S), [n, Z])], [n::posint, Z > 0]); str := time[real](); simplify(fnormal(evalf(f(3, 1))), zero); simplify(fnormal(evalf(f(5, 1.1))), zero); simplify(fnormal(evalf(f(3, .92))), zero); (time[real]()-str)*seconds

1572.6261454761299423

68711.440007753956841

2648.5507166498596403

0.62e-1*seconds

 


Download eval-evalf_1.mw

What do you see displayed if you replace that * (asterisk) with a . (period)?

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