acer

32587 Reputation

29 Badges

20 years, 37 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

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)?

You might be able to use this kind of approach.

restart

first define input x and output y as vector/list

x := [x1, x2, x3, x4, x5];

[x1, x2, x3, x4, x5]

[y1, y2, y3]

define output values

y1 := exp(-x1/T)*x2+log(x3)*x4+x5^2;

exp(-x1/T)*x2+ln(x3)*x4+x5^2

sin(x1)*x5+x3*x4*x5

c1*x1+c2*x2^2+c3*x3^3*x5+x1*x2*x4*exp(-x1/T)

calculate Jacobian and Hessian matrices

Jac := VectorCalculus:-Jacobian(y, x)

Jac := Matrix(3, 5, {(1, 1) = -exp(-x1/T)*x2/T, (1, 2) = exp(-x1/T), (1, 3) = x4/x3, (1, 4) = ln(x3), (1, 5) = 2*x5, (2, 1) = cos(x1)*x5, (2, 2) = 0, (2, 3) = x4*x5, (2, 4) = x3*x5, (2, 5) = sin(x1)+x3*x4, (3, 1) = c1+x2*x4*exp(-x1/T)-x1*x2*x4*exp(-x1/T)/T, (3, 2) = 2*c2*x2+x1*x4*exp(-x1/T), (3, 3) = 3*c3*x3^2*x5, (3, 4) = x1*x2*exp(-x1/T), (3, 5) = c3*x3^3})

H1 := VectorCalculus:-Hessian(y1, x); H2 := VectorCalculus:-Hessian(y2, x); H3 := VectorCalculus:-Hessian(y3, x)

H1 := Matrix(5, 5, {(1, 1) = exp(-x1/T)*x2/T^2, (1, 2) = -exp(-x1/T)/T, (1, 3) = 0, (1, 4) = 0, (1, 5) = 0, (2, 1) = -exp(-x1/T)/T, (2, 2) = 0, (2, 3) = 0, (2, 4) = 0, (2, 5) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = -x4/x3^2, (3, 4) = 1/x3, (3, 5) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 1/x3, (4, 4) = 0, (4, 5) = 0, (5, 1) = 0, (5, 2) = 0, (5, 3) = 0, (5, 4) = 0, (5, 5) = 2})

H2 := Matrix(5, 5, {(1, 1) = -sin(x1)*x5, (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (1, 5) = cos(x1), (2, 1) = 0, (2, 2) = 0, (2, 3) = 0, (2, 4) = 0, (2, 5) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0, (3, 4) = x5, (3, 5) = x4, (4, 1) = 0, (4, 2) = 0, (4, 3) = x5, (4, 4) = 0, (4, 5) = x3, (5, 1) = cos(x1), (5, 2) = 0, (5, 3) = x4, (5, 4) = x3, (5, 5) = 0})

H3 := Matrix(5, 5, {(1, 1) = -2*x2*x4*exp(-x1/T)/T+x1*x2*x4*exp(-x1/T)/T^2, (1, 2) = x4*exp(-x1/T)-x1*x4*exp(-x1/T)/T, (1, 3) = 0, (1, 4) = exp(-x1/T)*x2-x1*x2*exp(-x1/T)/T, (1, 5) = 0, (2, 1) = x4*exp(-x1/T)-x1*x4*exp(-x1/T)/T, (2, 2) = 2*c2, (2, 3) = 0, (2, 4) = x1*exp(-x1/T), (2, 5) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 6*c3*x3*x5, (3, 4) = 0, (3, 5) = 3*c3*x3^2, (4, 1) = exp(-x1/T)*x2-x1*x2*exp(-x1/T)/T, (4, 2) = x1*exp(-x1/T), (4, 3) = 0, (4, 4) = 0, (4, 5) = 0, (5, 1) = 0, (5, 2) = 0, (5, 3) = 3*c3*x3^2, (5, 4) = 0, (5, 5) = 0})

CodeGeneration:-C(Jac, optimize);

t1 = 0.1e1 / T;

t2 = x1 * t1;
t3 = exp(-t2);
t4 = (int) (x3 * x3);
cg[0][0] = -t1 * t3 * x2;
cg[0][1] = t3;
cg[0][2] = 0.1e1 / x3 * (double) x4;
cg[0][3] = log(x3);
cg[0][4] = 2 * x5;
cg[1][0] = cos(x1) * (double) x5;
cg[1][1] = 0;
cg[1][2] = x4 * x5;
cg[1][3] = x3 * (double) x5;
cg[1][4] = sin(x1) + x3 * (double) x4;
cg[2][0] = -x2 * (double) x4 * t3 * (-0.1e1 + t2) + c1;
cg[2][1] = x1 * (double) x4 * t3 + 0.2e1 * c2 * x2;
cg[2][2] = 3 * c3 * t4 * x5;
cg[2][3] = x1 * x2 * t3;
cg[2][4] = (double) c3 * x3 * (double) t4;

CodeGeneration:-C(codegen[makeproc]([
                     seq(seq('Jac'[i,j]=Jac[i,j],j=1..5),i=1..3)
                     , 'NULL'],[]), optimize);

#include <math.h>

void cg0 (void)
{
  double t1;
  double t12;
  double t20;
  double t3;
  double t7;
  double t8;
  t1 = 0.1e1 / T;
  t3 = exp(-x1 * t1);
  Jac[0][0] = -t1 * t3 * x2;
  Jac[0][1] = t3;
  Jac[0][2] = 0.1e1 / x3 * x4;
  Jac[0][3] = log(x3);
  Jac[0][4] = (double) (2 * x5);
  t7 = cos(x1);
  Jac[1][0] = t7 * (double) x5;
  Jac[1][1] = 0.0e0;
  Jac[1][2] = x4 * (double) x5;
  Jac[1][3] = x3 * (double) x5;
  t8 = sin(x1);
  Jac[1][4] = x3 * x4 + t8;
  t12 = x1 * x2;
  Jac[2][0] = -t1 * t12 * x4 * Jac[0][1] + x2 * x4 * Jac[0][1] + c1;
  Jac[2][1] = x1 * x4 * Jac[0][1] + 0.2e1 * c2 * x2;
  t20 = x3 * x3;
  Jac[2][2] = 0.3e1 * c3 * t20 * (double) x5;
  Jac[2][3] = t12 * Jac[0][1];
  Jac[2][4] = c3 * t20 * x3;
  ;
}

CodeGeneration:-C(codegen[makeproc]([
                     seq(seq('Jac'[i,j]=Jac[i,j],j=1..5),i=1..3)
                     , seq(seq('H1'[i,j]=H1[i,j],j=1..5),i=1..5)
                     , seq(seq('H2'[i,j]=H2[i,j],j=1..5),i=1..5)
                     , seq(seq('H3'[i,j]=H3[i,j],j=1..5),i=1..5)
                     ],[]));

#include <math.h>

double cg1 (void)
{
  Jac[0][0] = -0.1e1 / T * exp(-x1 / T) * x2;
  Jac[0][1] = exp(-x1 / T);
  Jac[0][2] = 0.1e1 / x3 * x4;
  Jac[0][3] = log(x3);
  Jac[0][4] = (double) (2 * x5);
  Jac[1][0] = cos(x1) * (double) x5;
  Jac[1][1] = 0.0e0;
  Jac[1][2] = x4 * (double) x5;
  Jac[1][3] = x3 * (double) x5;
  Jac[1][4] = sin(x1) + x3 * x4;
  Jac[2][0] = c1 + x2 * x4 * exp(-x1 / T) - x1 * x2 * x4 / T * exp(-x1 / T);
  Jac[2][1] = 0.2e1 * c2 * x2 + x1 * x4 * exp(-x1 / T);
  Jac[2][2] = 0.3e1 * c3 * x3 * x3 * (double) x5;
  Jac[2][3] = x1 * x2 * exp(-x1 / T);
  Jac[2][4] = c3 * pow(x3, 0.3e1);
  H1[0][0] = pow(T, -0.2e1) * exp(-x1 / T) * x2;
  H1[0][1] = -0.1e1 / T * exp(-x1 / T);
  H1[0][2] = 0.0e0;
  H1[0][3] = 0.0e0;
  H1[0][4] = 0.0e0;
  H1[1][0] = -0.1e1 / T * exp(-x1 / T);
  H1[1][1] = 0.0e0;
  H1[1][2] = 0.0e0;
  H1[1][3] = 0.0e0;
  H1[1][4] = 0.0e0;
  H1[2][0] = 0.0e0;
  H1[2][1] = 0.0e0;
  H1[2][2] = -pow(x3, -0.2e1) * x4;
  H1[2][3] = 0.1e1 / x3;
  H1[2][4] = 0.0e0;
  H1[3][0] = 0.0e0;
  H1[3][1] = 0.0e0;
  H1[3][2] = 0.1e1 / x3;
  H1[3][3] = 0.0e0;
  H1[3][4] = 0.0e0;
  H1[4][0] = 0.0e0;
  H1[4][1] = 0.0e0;
  H1[4][2] = 0.0e0;
  H1[4][3] = 0.0e0;
  H1[4][4] = 0.2e1;
  H2[0][0] = -sin(x1) * (double) x5;
  H2[0][1] = 0.0e0;
  H2[0][2] = 0.0e0;
  H2[0][3] = 0.0e0;
  H2[0][4] = cos(x1);
  H2[1][0] = 0.0e0;
  H2[1][1] = 0.0e0;
  H2[1][2] = 0.0e0;
  H2[1][3] = 0.0e0;
  H2[1][4] = 0.0e0;
  H2[2][0] = 0.0e0;
  H2[2][1] = 0.0e0;
  H2[2][2] = 0.0e0;
  H2[2][3] = (double) x5;
  H2[2][4] = x4;
  H2[3][0] = 0.0e0;
  H2[3][1] = 0.0e0;
  H2[3][2] = (double) x5;
  H2[3][3] = 0.0e0;
  H2[3][4] = x3;
  H2[4][0] = cos(x1);
  H2[4][1] = 0.0e0;
  H2[4][2] = x4;
  H2[4][3] = x3;
  H2[4][4] = 0.0e0;
  H3[0][0] = -0.2e1 * x2 * x4 / T * exp(-x1 / T) + x1 * x2 * x4 * pow(T, -0.2e1) * exp(-x1 / T);
  H3[0][1] = x4 * exp(-x1 / T) - x1 * x4 / T * exp(-x1 / T);
  H3[0][2] = 0.0e0;
  H3[0][3] = exp(-x1 / T) * x2 - x1 * x2 / T * exp(-x1 / T);
  H3[0][4] = 0.0e0;
  H3[1][0] = x4 * exp(-x1 / T) - x1 * x4 / T * exp(-x1 / T);
  H3[1][1] = 0.2e1 * c2;
  H3[1][2] = 0.0e0;
  H3[1][3] = x1 * exp(-x1 / T);
  H3[1][4] = 0.0e0;
  H3[2][0] = 0.0e0;
  H3[2][1] = 0.0e0;
  H3[2][2] = 0.6e1 * c3 * x3 * (double) x5;
  H3[2][3] = 0.0e0;
  H3[2][4] = 0.3e1 * c3 * x3 * x3;
  H3[3][0] = exp(-x1 / T) * x2 - x1 * x2 / T * exp(-x1 / T);
  H3[3][1] = x1 * exp(-x1 / T);
  H3[3][2] = 0.0e0;
  H3[3][3] = 0.0e0;
  H3[3][4] = 0.0e0;
  H3[4][0] = 0.0e0;
  H3[4][1] = 0.0e0;
  H3[4][2] = 0.3e1 * c3 * x3 * x3;
  H3[4][3] = 0.0e0;
  H3[4][4] = 0.0e0;
  return(H3[4][4]);
}

CodeGeneration:-C(codegen[makeproc]([
                     seq(seq('Jac'[i,j]=Jac[i,j],j=1..5),i=1..3)
                     , seq(seq('H1'[i,j]=H1[i,j],j=1..5),i=1..5)
                     , seq(seq('H2'[i,j]=H2[i,j],j=1..5),i=1..5)
                     , seq(seq('H3'[i,j]=H3[i,j],j=1..5),i=1..5)
                     ,'NULL'],[]), optimize);

#include <math.h>

void cg2 (void)
{
  double t1;
  double t10;
  double t12;
  double t18;
  double t20;
  double t21;
  double t24;
  double t25;
  double t27;
  double t3;
  double t6;
  double t7;
  double t8;
  t1 = 0.1e1 / T;
  t3 = exp(-x1 * t1);
  Jac[0][0] = -t1 * t3 * x2;
  Jac[0][1] = t3;
  t6 = 0.1e1 / x3;
  Jac[0][2] = t6 * x4;
  Jac[0][3] = log(x3);
  Jac[0][4] = (double) (2 * x5);
  t7 = cos(x1);
  Jac[1][0] = t7 * (double) x5;
  Jac[1][1] = 0.0e0;
  Jac[1][2] = x4 * (double) x5;
  Jac[1][3] = x3 * (double) x5;
  t8 = sin(x1);
  Jac[1][4] = x3 * x4 + t8;
  t10 = x2 * x4;
  t12 = x1 * x2;
  Jac[2][0] = -t1 * t12 * x4 * Jac[0][1] + t10 * Jac[0][1] + c1;
  t18 = x1 * x4;
  Jac[2][1] = 0.2e1 * c2 * x2 + t18 * Jac[0][1];
  t20 = x3 * x3;
  t21 = c3 * t20;
  Jac[2][2] = 0.3e1 * t21 * (double) x5;
  Jac[2][3] = t12 * Jac[0][1];
  Jac[2][4] = c3 * t20 * x3;
  t24 = T * T;
  t25 = 0.1e1 / t24;
  H1[0][0] = t25 * Jac[0][1] * x2;
  t27 = t1 * Jac[0][1];
  H1[0][1] = -t27;
  H1[0][2] = 0.0e0;
  H1[0][3] = 0.0e0;
  H1[0][4] = 0.0e0;
  H1[1][0] = H1[0][1];
  H1[1][1] = 0.0e0;
  H1[1][2] = 0.0e0;
  H1[1][3] = 0.0e0;
  H1[1][4] = 0.0e0;
  H1[2][0] = 0.0e0;
  H1[2][1] = 0.0e0;
  H1[2][2] = -0.1e1 / t20 * x4;
  H1[2][3] = t6;
  H1[2][4] = 0.0e0;
  H1[3][0] = 0.0e0;
  H1[3][1] = 0.0e0;
  H1[3][2] = H1[2][3];
  H1[3][3] = 0.0e0;
  H1[3][4] = 0.0e0;
  H1[4][0] = 0.0e0;
  H1[4][1] = 0.0e0;
  H1[4][2] = 0.0e0;
  H1[4][3] = 0.0e0;
  H1[4][4] = 0.2e1;
  H2[0][0] = -t8 * (double) x5;
  H2[0][1] = 0.0e0;
  H2[0][2] = 0.0e0;
  H2[0][3] = 0.0e0;
  H2[0][4] = t7;
  H2[1][0] = 0.0e0;
  H2[1][1] = 0.0e0;
  H2[1][2] = 0.0e0;
  H2[1][3] = 0.0e0;
  H2[1][4] = 0.0e0;
  H2[2][0] = 0.0e0;
  H2[2][1] = 0.0e0;
  H2[2][2] = 0.0e0;
  H2[2][3] = (double) x5;
  H2[2][4] = x4;
  H2[3][0] = 0.0e0;
  H2[3][1] = 0.0e0;
  H2[3][2] = (double) x5;
  H2[3][3] = 0.0e0;
  H2[3][4] = x3;
  H2[4][0] = H2[0][4];
  H2[4][1] = 0.0e0;
  H2[4][2] = x4;
  H2[4][3] = x3;
  H2[4][4] = 0.0e0;
  H3[0][0] = t12 * t25 * x4 * Jac[0][1] - 0.2e1 * t10 * t27;
  H3[0][1] = -t18 * t27 + x4 * Jac[0][1];
  H3[0][2] = 0.0e0;
  H3[0][3] = -t12 * t27 + Jac[0][1] * x2;
  H3[0][4] = 0.0e0;
  H3[1][0] = H3[0][1];
  H3[1][1] = 0.2e1 * c2;
  H3[1][2] = 0.0e0;
  H3[1][3] = x1 * Jac[0][1];
  H3[1][4] = 0.0e0;
  H3[2][0] = 0.0e0;
  H3[2][1] = 0.0e0;
  H3[2][2] = 0.6e1 * c3 * x3 * (double) x5;
  H3[2][3] = 0.0e0;
  H3[2][4] = 0.3e1 * t21;
  H3[3][0] = H3[0][3];
  H3[3][1] = H3[1][3];
  H3[3][2] = 0.0e0;
  H3[3][3] = 0.0e0;
  H3[3][4] = 0.0e0;
  H3[4][0] = 0.0e0;
  H3[4][1] = 0.0e0;
  H3[4][2] = H3[2][4];
  H3[4][3] = 0.0e0;
  H3[4][4] = 0.0e0;
  ;
}

 

Download Jacobian_Hessian_CG_1.mw

This seems harder that I would have guessed at first, for a few esoteric reasons.

I'm supposing that what you want is a specific order of the derivatives in the pretty-printing of the differential equation, and that you don't actually want the expression's internal representation to be altered necessarily. (The latter would affect how the op command pulls out the terms.)

While I suppose that your D^4 in your Question is just a convenient shorthand (to illustrate your point quickly), it's not completely clear to me whether you mean a call to diff or Diff or D.

So here is a procedure that can print differential equations in a sorted manner.

restart;

`print/pre`:=proc(expr::{scalar,scalar=scalar})
  local T,TT;
  uses PDEtools;
  if type(expr,`=`) then return map(procname,expr); end if;
  if type(expr,`+`) then
    T:=sort([op(expr)],(a,b)->difforder(a)>difforder(b));
    if interface(':-typesetting')=':-standard' then
      TT:=subs([:-diff=`tools/gensym`(:-diff),
                :-Diff=`tools/gensym`(:-Diff),
                :-D=`tools/gensym`(:-D)],T);
      `+`(op(TT));
    else
      `+`(op(subs([:-diff=:-%diff,
                   :-Diff=:-%Diff,
                   :-D=`tools/gensym`(:-D)],T)));
    end if
  else
    expr;
  end if;
end proc:

ee1:=diff(f(x),x)+diff(f(x),$(x,4))+diff(f(x),$(x,6))+7=f(t):
ee2:=Diff(f(x),x)+Diff(f(x),$(x,4))+Diff(f(x),$(x,6))+7=f(t):
ee3:=D(f)(x)+(D@@4)(f)(x)+(D@@6)(f)(x)+7=f(t):
ff1:=diff(x(t),t)+diff(x(t),$(t,4))+diff(x(t),$(t,6))+7=f(t):

interface(typesetting=standard):

ee1;

diff(f(x), x)+diff(diff(diff(diff(f(x), x), x), x), x)+diff(diff(diff(diff(diff(diff(f(x), x), x), x), x), x), x)+7 = f(t)

pre(ee1);

pre(diff(f(x), x)+diff(diff(diff(diff(f(x), x), x), x), x)+diff(diff(diff(diff(diff(diff(f(x), x), x), x), x), x), x)+7 = f(t))

ee2;

Diff(f(x), x)+Diff(f(x), x, x, x, x)+Diff(f(x), x, x, x, x, x, x)+7 = f(t)

pre(ee2);

pre(Diff(f(x), x)+Diff(f(x), x, x, x, x)+Diff(f(x), x, x, x, x, x, x)+7 = f(t))

ee3;

(D(f))(x)+((D@@4)(f))(x)+((D@@6)(f))(x)+7 = f(t)

pre(ee3);

pre((D(f))(x)+((D@@4)(f))(x)+((D@@6)(f))(x)+7 = f(t))

interface(typesetting=extended):

ee1;

diff(f(x), x)+diff(diff(diff(diff(f(x), x), x), x), x)+diff(diff(diff(diff(diff(diff(f(x), x), x), x), x), x), x)+7 = f(t)

pre(ee1);

pre(diff(f(x), x)+diff(diff(diff(diff(f(x), x), x), x), x)+diff(diff(diff(diff(diff(diff(f(x), x), x), x), x), x), x)+7 = f(t))

ff1;

diff(x(t), t)+diff(diff(diff(diff(x(t), t), t), t), t)+diff(diff(diff(diff(diff(diff(x(t), t), t), t), t), t), t)+7 = f(t)

pre(ff1);

pre(diff(x(t), t)+diff(diff(diff(diff(x(t), t), t), t), t)+diff(diff(diff(diff(diff(diff(x(t), t), t), t), t), t), t)+7 = f(t))

ee2;

Diff(f(x), x)+Diff(f(x), x, x, x, x)+Diff(f(x), x, x, x, x, x, x)+7 = f(t)

pre(ee2);

pre(Diff(f(x), x)+Diff(f(x), x, x, x, x)+Diff(f(x), x, x, x, x, x, x)+7 = f(t))

ee3;

(D(f))(x)+((D@@4)(f))(x)+((D@@6)(f))(x)+7 = f(t)

pre(ee3);

pre((D(f))(x)+((D@@4)(f))(x)+((D@@6)(f))(x)+7 = f(t))

 

Download sortdiff.mw

The above also seems to work in Maple 2017.0, with the default typesetting level of extended, with the prime and dot derivative notations for diff toggled on. Eg, after say,

Typesetting:-Settings(typesetprime=true):
Typesetting:-Settings(typesetdot=true):

We've seen requests along these lines before. Here's one idea (from here).

restart;

twostep:=proc(expr::uneval)
  uses Typesetting;
  (Typeset(expr) =
   subsindets(expr,
     And(name,
         satisfies(t->type(eval(t),
           {constant,
            '`*`'({constant,
                   'specfunc'(anything,
                              Units:-Unit)})}))),
     z->Typeset(EV(z))))
   = combine(eval(expr),':-units');
end proc:

v:=2.256*10^8*Unit(m/s);

225600000.0*Units:-Unit(('m')/('s'))

f:=4.74*10^14*Unit(1/s);

0.4740000000e15*Units:-Unit(1/('s'))

lambda:=twostep(v/f);

(Typesetting:-mfrac(Typesetting:-mi("v"), Typesetting:-mi("f")) = Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mn("2.256000000"), Typesetting:-mo("&InvisibleTimes;"), Typesetting:-msup(Typesetting:-mn("10"), Typesetting:-mn("8"), Typesetting:-msemantics = "^")), Typesetting:-mo("&InvisibleTimes;"), Typesetting:-mfenced(Typesetting:-mfrac(Typesetting:-mi("m"), Typesetting:-mi("s")), open = "&lobrk;", close = "&robrk;", Typesetting:-msemantics = "Unit"))/Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mn("4.740000000"), Typesetting:-mo("&InvisibleTimes;"), Typesetting:-msup(Typesetting:-mn("10"), Typesetting:-mn("14"), Typesetting:-msemantics = "^")), Typesetting:-mo("&InvisibleTimes;"), Typesetting:-mfenced(Typesetting:-mfrac(Typesetting:-mn("1"), Typesetting:-mi("s")), open = "&lobrk;", close = "&robrk;", Typesetting:-msemantics = "Unit"))) = 0.4759493671e-6*Units:-Unit('m')

 


Download 2step.mw

For your examples, how about just,

not ( evalb( normal( expr ) = expr ) )

And of course you could replace that `normal` with something stronger if necessary. Like `simplify `.

In Maple 2016 (or earlier, mostly) a number of special functions are typeset tersely like that, if interface(typesetting) has been set to extended. But, while that setting can be set by the user, that does not cover all the pre-formed Help pages.

For example, using Maple 2016,

interface(typesetting=standard):

LerchPhi(3,4,5);

LerchPhi(3, 4, 5)

interface(typesetting=extended):

LerchPhi(3,4,5);

LerchPhi(3, 4, 5)

 

LerchPhi_2016.mw

In Maple 2017.0, such terse (and obscure, IMHO) pretty-printing of special functions has been turned off, even with the new default of interface(typesetting) as extended . It can, however, be reinstated even on a function-by-function basis, using commands from the Typesetting package. For example,

interface(typesetting=standard):

LerchPhi(3,4,5);

LerchPhi(3, 4, 5)

interface(typesetting=extended):

LerchPhi(3,4,5);

LerchPhi(3, 4, 5)

Typesetting:-QueryTypesetRule("LerchPhi");

{"LerchPhi" = false}

Typesetting:-EnableTypesetRule("LerchPhi"):

LerchPhi(3,4,5);

LerchPhi(3, 4, 5)

Typesetting:-DisableTypesetRule("LerchPhi"):

LerchPhi(3,4,5);

LerchPhi(3, 4, 5)

 

LerchPhi_2017.mw

If your Maple procedure has been read from a file, then showsource can show you what that source looked like, including comments.

In addition, if the procedure is saved to a .mla Library archive, then even after a restart the source may still be shown using that command.

Note that the argument to showsource is the name of a Maple procedure, not some source file name (string). The name of the source file and any names which get assigned procedures (within that source file) are not necessarily the same or even similar. I just happened to call my source text file f.mpl , which contains the source that assigns a procedure to name f.

restart;

kernelopts(keepdebuginfo=true):

read "C:/TEMP/f.mpl";

proc (x) local res; res := x^2; return res end proc

showsource(f);


--- C:/TEMP/f.mpl -------------------------------------------------------------
1     proc(x)
2       local res;
4,1     # This is my procedure.
5       res:=x^2;
6,2     # This is another comment.
7       return res;

showstat(f);


f := proc(x)
local res;
   1   res := x^2;
   2   return res
end proc

s:="C:/TEMP/nm.mla";

"C:/TEMP/nm.mla"

LibraryTools:-Create(s);

LibraryTools:-Save(f, s);

restart;

kernelopts(keepdebuginfo=true):

s:="C:/TEMP/nm.mla";

"C:/TEMP/nm.mla"

libname:=s,libname:

f(3);

9

showsource(f);


--- C:/TEMP/f.mpl -------------------------------------------------------------
1     proc(x)
2       local res;
4,1     # This is my procedure.
5       res:=x^2;
6,2     # This is another comment.
7       return res;

showstat(f);


f := proc(x)
local res;
   1   res := x^2;
   2   return res
end proc

 

 

Download showsource.mw


 

restart;

col:=proc(ee, c::string)
  uses Typesetting;
  subsindets(Typeset(ee),
             'specfunc'(anything,{mi,mo,mn,ms,mfenced}),
             u->op(0,u)(op(u),':-mathcolor'=c));
end proc:

captext1 := col( "A plot of: ", "green" ):
capother := col( sin(x), "red" ):
captext2 := col( " from ", "green" ),
            col( -Pi, "green" ),
            col( " to ", "green"),
            col( Pi, "green" ):

plot(sin(x), x=-Pi..Pi, caption=typeset(captext1, capother, captext2));

 

 

Download colored_caption.mw

First 198 199 200 201 202 203 204 Last Page 200 of 338