acer

32405 Reputation

29 Badges

19 years, 349 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

For your second example, here is one way,

restart;

kernelopts(version);

`Maple 2024.0, X86 64 LINUX, Mar 01 2024, Build ID 1794891`

e := -1/2*(-2*x*sqrt(4*x^2 + 1) + (16*x^3*sinh(3/2*arcsinh(2*x)) - 8*x^2*cosh(3/2*arcsinh(2*x))*sqrt(4*x^2 + 1) + 4*sinh(3/2*arcsinh(2*x))*x - cosh(3/2*arcsinh(2*x))*sqrt(4*x^2 + 1))*sqrt(-2 + 2*sqrt(4*x^2 + 1)))/sqrt(4*x^2 + 1);

-(1/2)*(-2*x*(4*x^2+1)^(1/2)+(16*x^3*sinh((3/2)*arcsinh(2*x))-8*x^2*cosh((3/2)*arcsinh(2*x))*(4*x^2+1)^(1/2)+4*sinh((3/2)*arcsinh(2*x))*x-cosh((3/2)*arcsinh(2*x))*(4*x^2+1)^(1/2))*(-2+2*(4*x^2+1)^(1/2))^(1/2))/(4*x^2+1)^(1/2)

simplify(evala(convert(e,arctan))) assuming x<0;

0


Download nm_simp_exh.mw
 

Also, for x>0,

combine(evala(simplify(convert(e,arctan)))) assuming x>0;

2*x


Of course, there may well be shorter alternatives.

You have,

   xM2 = rhs(sol2[1]);
   yM2 = rhs(sol2[2]);
   xM3 = rhs(sol3[1]);
   yM3 = rhs(sol3[2]);

which are not assignments. Those are just equations.

Change = to := and it works.

You don't need the assume call.

JAMET_2.mw

I've deliberately done this in stages, for a little more clarity.

The idea is to replace a subexpression of the form Int(Sum(...)) with Sum(Int(...)), i.e. bring the integration inside the sum.

restart:

with(IntegrationTools):

NULL

eq1:=int(1-(sum(p[i]*(1-exp(-((t-xi)/tau[i]))),i=1..n)),xi=0..t);

int(1-(sum(p[i]*(1-exp(-(t-xi)/tau[i])), i = 1 .. n)), xi = 0 .. t)

temp := IntegrationTools:-Expand(eq1);

t-(sum(p[i], i = 1 .. n))*t+int(sum(p[i]*exp(xi/tau[i])/exp(t/tau[i]), i = 1 .. n), xi = 0 .. t)

temp := subsindets(temp, specfunc({specfunc(sum),name=range},int),
                   u->Sum(Int(op([1,1],u),op(2,u)),op([1,2],u)));

t-(sum(p[i], i = 1 .. n))*t+Sum(Int(p[i]*exp(xi/tau[i])/exp(t/tau[i]), xi = 0 .. t), i = 1 .. n)

simplify(temp);

t-(sum(p[i], i = 1 .. n))*t+Sum(p[i]*(Int(exp((-t+xi)/tau[i]), xi = 0 .. t)), i = 1 .. n)

value(%);

t-(sum(p[i], i = 1 .. n))*t+sum(p[i]*(-tau[i]*exp(-t/tau[i])+tau[i]), i = 1 .. n)

simplify(combine(%));

-(sum(p[i]*(tau[i]*exp(-t/tau[i])+t-tau[i]), i = 1 .. n))+t


Download 1111_ac.mw

@Dkunb You could examine the results from, say,

   collect(combine(convert(eq13,trig)),[sin,cos],simplify)

which could also be done with, say, assuming n::even,m::odd etc.

In such a case I don't know whether you'd prefer the collecting of terms by real/imaginary (ie. factor of I) or by sin/cos arguments, or by denominator factors.

The command log (with no index supplied, ie. no base specified) is the same in Maple as the command ln, i.e. the logarithm with respect to the default base e=exp(1), ie. the natural logarithm.

log(0.5/1.65)
                          -1.193922469

ln(0.5/1.65)
                          -1.193922469

log[exp(1)](0.5/1.65)
                          -1.193922469

log10(0.5/1.65)
                         -0.5185139399

log[10](0.5/1.65)
                         -0.5185139399

See also the second paragraph here.

This is also described on the Maple Help-page viewed by executing  ?log .

If you're going to use eval[recurse] then why not utilize the functionality to recurse, with,

   eval['recurse'](Pt[1],[Pt[2][],valsh[]])

instead of,

    eval['recurse'](eval['recurse'](Pt,valsh)[])

 

To address your observation: simplify(S1) and S2 differ as starting forms for simplification, and the starting form can make a significant difference to the heuristics of simplify.  You're asking for a "simpler" form, which is not the same as asking for some kind of canonical form.


By the way, there are a variety of metrics readily available, including length , MmaTranslator:-Mma:-LeafCount , `simplify/size/size` and even codegen:-cost .

My least favorite is length, not least because results can depends on choices of names(!). Switch a pair of names for each other and the measure can change.

Also, for fun, and all using Maple 2024.0,

simplify(combine(rationalize(simplify(S1))));
length(%);  # length 509

simplify(combine(rationalize(S2)));
length(%);  # length 467

Moving on, the following both get the same (even smaller) length.

simplify(combine(expand(radnormal(S2)))):
length(%);  # length 466

I beseeched my oracle, and the sybil whispered to me commands for an even more compact form,

collect(S2,[t],u->simplify(evala(u)));
length(%);   # length 398

note: You're measuring a list of two expressions. The size of the list accounts for both expressions. All these mentioned approaches are each applied to both expressions. So their individual sizes may play off each other in the goal of minimizing the total measure the the list containing both. You may well be able to find a separate approach for each, that makes the combined total size smaller still.

If you are going to pass multiple geometry objects to draw then they should be in a list. 

You made a similar mistake with textplot: the multiple lists of items need to be grouped within a parent list.

That's on top of all the errant `*` and/or bracketing issues.

Suggestions:
1) Stop using 2D Input since it's likely related to your recurrent problems with errant `*` and implicit mutiplication versus function calls.
2) Indent your code, with separate lines, so that you can more easily see the structure of long statements, nested calls, and syntax mistakes.
3) When you have problems with a long complicated display call, try each of its parts separately.
4) Read the text of error messages; sometimes they're confusing but often they give a hint
5) When having a problem with a specific command, read all of its Help page carefully.

restart;

with(plots):
with(geometry):

_EnvHorizontalName := 'x':
_EnvVerticalName := 'y':

x0 := 10: y0 := 9: a := 7: b := 5: c := sqrt(a^2 - b^2):

ellipse(el, x^2/a^2 + y^2/b^2 - 1):
point(F1, -c, 0): point(F2, c, 0): point(P, x0, y0):

eq := simplify((a^2 - x0^2)*(y - y0)^2 + (b^2 - y0^2)*(x - x0)^2 + 2*x0*y0*(x - x0)*(y - y0)) = 0;
eq := (a^2 - x0^2)*m^2 + 2*x0*y0*m + b^2 - y0^2 = 0;
sol := solve(%, m);

-56*x^2+(180*y-500)*x-51*y^2-882*y+6469 = 0

-51*m^2+180*m-56 = 0

30/17-(2/51)*1311^(1/2), 30/17+(2/51)*1311^(1/2)

m1 := sol[1]: m2 := sol[2]:

line(tang1, (y - y0 - m1) + (-x + x0)):
line(tang2, (y - y0 - m2) + (-x + x0)):

display(textplot([[-c, 0, "F1"], [c, 0, "F2"], [coordinates(P)[], "P"]],
                 align = {"above", 'right'}),
        draw([el(color = red), P(color = black, symbol = solidcircle, symbolsize = 16),
              tang1(color = green), tang2(color = green),
              F1(color = blue, symbol = solidcircle, symbolsize = 16),
              F2(color = red, symbol = solidcircle, symbolsize = 16)]),
        axes = none);

Download JAMET_x.mw

One way is to replicate the plot, but with a singleton point (defined, and within range) and a lower thickness.

It's not perfect, but at least the legend entries are more distinguishable than in the original.

The limit at which it works on my system is thickness=2 .
 

restart;

 

P := plot([sin(x)/x,sin(x),cos(x)], x=0..2*Pi, color="Burgundy",
          linestyle= [solid, longdash, dash],
          thickness = [4, 4, 4], legend=[a,b,c]);

plots:-display(
  plot([sin(x)/x,sin(x),cos(x)], x=0..2*Pi, color="Burgundy",
       linestyle= [solid, longdash, dash],
       thickness = [4, 4, 4]),
  plot([sin(x)/x,sin(x),cos(x)], x=1..1, color="Burgundy",
       linestyle= [solid, longdash, dash],
       thickness = 2, legend=[a,b,c])
);

Download legend_thick_hack.mw

It varies by example of course, but doesn't save much typing, say,

with(plots):
display(display(P,legend=""),
  plottools:-transform((x,y)->[Pi,0])(display(P,overrideoption,thickness=2)))

Here's a quick attempt at something flexible.

restart;


First, a procedure to do the work.

V := proc(expr, cutoffin::nonnegint:=0, Q::symbol:=':-Q',
          {special::list(name):=[]})
  local TT, W, new, cutoff;
  if cutoffin=0 then
    cutoff := ceil(min(length~(op~(1,indets(eqn,radical))))/2);
  else cutoff := cutoffin; end if;
  TT := table([]);
  map(proc(u) TT; local A,B;
        A,B := selectremove(hastype,u,{radical,identical(special[])});
        if length(B) > cutoff then
          TT[B] := LargeExpressions:-Veil[Q](B);
        end if; NULL; end proc,
      [indets(expr,And({`+`,`*`}))[]]):
  W:=ListTools:-Reverse(sort([indices(TT,nolist)[]],key=length)):
  new := eqn:
  while W <> [] do
    new := subsindets(new,And({`+`,`*`}),
                      proc(u) local A,B;
                      A,B := selectremove(hastype,u,{radical,identical(special[])});
                      B := subs(W[1]=TT[W[1]], B);
                      op(0,u)(A,B);
                      end proc);
  W := W[2..]; end do;
  return new;
end proc:


Now, that example,

vars[1]:=x: vars[2]:=y:

eqn:= 8*(2*((a^2-2*a*c+b^2+c^2)*(4*a*c*f-a*e^2-b^2*f+b*d*e-c*d^2)^2)^(1
                /2)+(-8*a*f+2*d^2)*c^2+(8*a^2*f-2*a*d^2+2*a*e^2+2*b^2*f-2*b*d*e)*c-2*a^2*e^2-2*
                a*b^2*f+2*a*b*d*e)^(1/2)*(a*c-1/4*b^2)/(4*a*c-b^2)^2*(vars[1]-(1/4*b*e-1/2*c*d)/(a*c-\
                1/4*b^2))-8*csgn((4*a*c*f-a*e^2-b^2*f+b*d*e-c*d^2)*(Complex(1)*a+Complex(-1)*c-
                b))*(a*c-1/4*b^2)*(2*((a^2-2*a*c+b^2+c^2)*(4*a*c*f-a*e^2-b^2*f+b*d*e-c*d^2)^2)^
                (1/2)+(8*a*f-2*d^2)*c^2+(-8*a^2*f+2*a*d^2-2*a*e^2-2*b^2*f+2*b*d*e)*c+2*a^2*e^2+
                2*a*b^2*f-2*a*b*d*e)^(1/2)/(4*a*c-b^2)^2*(vars[2]-(-1/2*a*e+1/4*b*d)/(a*c-1/4*b^2)):

 

eqn;

8*(2*((a^2-2*a*c+b^2+c^2)*(4*a*c*f-a*e^2-b^2*f+b*d*e-c*d^2)^2)^(1/2)+(-8*a*f+2*d^2)*c^2+(8*a^2*f-2*a*d^2+2*a*e^2+2*b^2*f-2*b*d*e)*c-2*a^2*e^2-2*a*b^2*f+2*a*b*d*e)^(1/2)*(a*c-(1/4)*b^2)*(x-((1/4)*b*e-(1/2)*c*d)/(a*c-(1/4)*b^2))/(4*a*c-b^2)^2-8*csgn((4*a*c*f-a*e^2-b^2*f+b*d*e-c*d^2)*(I*a-I*c-b))*(a*c-(1/4)*b^2)*(2*((a^2-2*a*c+b^2+c^2)*(4*a*c*f-a*e^2-b^2*f+b*d*e-c*d^2)^2)^(1/2)+(8*a*f-2*d^2)*c^2+(-8*a^2*f+2*a*d^2-2*a*e^2-2*b^2*f+2*b*d*e)*c+2*a^2*e^2+2*a*b^2*f-2*a*b*d*e)^(1/2)*(y-(-(1/2)*a*e+(1/4)*b*d)/(a*c-(1/4)*b^2))/(4*a*c-b^2)^2

 

Now, a compact form, using default settings,

 

ans := V(eqn);

2*(2*Q[1]^(1/2)+2*Q[10])^(1/2)*Q[6]-2*(2*Q[1]^(1/2)-2*Q[10])^(1/2)*Q[7]

 

indets(ans,specindex(posint,Q));

{Q[1], Q[6], Q[7], Q[10]}

map(q->print(q=LargeExpressions:-Unveil[Q](q)),%):

Q[1] = (a^2-2*a*c+b^2+c^2)*(4*a*c*f-a*e^2-b^2*f+b*d*e-c*d^2)^2

Q[6] = (4*a*c*x-b^2*x-b*e+2*c*d)/(4*a*c-b^2)^2

Q[7] = csgn((4*a*c*f-a*e^2-b^2*f+b*d*e-c*d^2)*(I*a-I*c-b))*(4*a*c*y-b^2*y+2*a*e-b*d)/(4*a*c-b^2)^2

Q[10] = 4*a^2*c*f-a^2*e^2-a*b^2*f+a*b*d*e-4*a*c^2*f-a*c*d^2+a*c*e^2+b^2*c*f-b*c*d*e+c^2*d^2

 

simplify(eqn - LargeExpressions:-Unveil[Q](ans));

0

 

And now also leaving `x` and `y` alone,

 

V(eqn, special=[x,y]);
simplify(eqn - LargeExpressions:-Unveil[Q](%));

8*(2*Q[1]^(1/2)+2*Q[10])^(1/2)*(a*c-(1/4)*b^2)*(x-Q[5])/(4*a*c-b^2)^2-2*(2*Q[1]^(1/2)-2*Q[10])^(1/2)*(y+Q[4])*Q[13]

0

 

And now with a few different expression length sizes, as cutoff.

Also, a different symbol for the replacement.

 

V(eqn, 80, P, special=[x,y]);
simplify(eqn - LargeExpressions:-Unveil[P](%));

8*(2*P[1]^(1/2)+2*P[4])^(1/2)*(a*c-(1/4)*b^2)*(x-((1/4)*b*e-(1/2)*c*d)/(a*c-(1/4)*b^2))/(4*a*c-b^2)^2-2*(2*P[1]^(1/2)-2*P[4])^(1/2)*(y-(-(1/2)*a*e+(1/4)*b*d)/(a*c-(1/4)*b^2))*P[3]

0

V(eqn, 120, special=[x,y]);
simplify(eqn - LargeExpressions:-Unveil[Q](%));

8*(2*((a^2-2*a*c+b^2+c^2)*(4*a*c*f-a*e^2-b^2*f+b*d*e-c*d^2)^2)^(1/2)+2*Q[10])^(1/2)*(a*c-(1/4)*b^2)*(x-((1/4)*b*e-(1/2)*c*d)/(a*c-(1/4)*b^2))/(4*a*c-b^2)^2-2*(2*((a^2-2*a*c+b^2+c^2)*(4*a*c*f-a*e^2-b^2*f+b*d*e-c*d^2)^2)^(1/2)-2*Q[10])^(1/2)*(y-(-(1/2)*a*e+(1/4)*b*d)/(a*c-(1/4)*b^2))*Q[13]

0

 

Download subs_recur_ac.mw

There are a few ways to finesse and improve it in terms of more involved functionality.

E.g. doing nested veiling using shortest first, and preserving "inner" results, instead of replacing longer-to-shorter.

Replacing instead by ascending length needs a careful cutoff, or else risks an unhelpful jumble of too many micro-substitutions, like from codegen:-optimize(eqn).

Does it help if you do it something like,

   barcaption = "Counts\n\n\n"

One thing that ODEsteps cares about is whether there is a derivative present.

 Student:-ODEs:-ODESteps(x+y(x), y(x));

Error, (in Student:-ODEs:-ODESteps) the ODE does not contain a derivative of the specified solving variable


It should be possible to construct a wrapper that splits the equation (factors, say) according to whether there is or is not a dependence upon a derivative (ie. an "ODE").

Purely as an example,

restart;

F:=proc(ee,unk)
  if indets(ee,specfunc({identical(unk,op(unk))},diff))<>{} then
    Student:-ODEs:-ODESteps(ee[1],output=solution);
  else
    solve(ee,unk)[];
  end if;
end proc:

Odes := [(x+y(x))*diff(y(x),x)=0,
         x*diff(y(x),x)=0,
         y(x)*diff(y(x),x)=0]:

K := proc(ode)
  print(ode,{dsolve(ode,y(x))}[]);
  map(F, remove~(u->(lhs-rhs)(u)=0,
                 [frontend(solve,[ode],
                         [{`^`,`+`,`*`,`=`},{}])]),
      y(x))[]; # I hard-coded y(x) here
end proc:

 

seq(print(K(oo)), oo=Odes);

(x+y(x))*(diff(y(x), x)) = 0, y(x) = c__1, y(x) = -x

y(x) = c__1, y(x) = -x

x*(diff(y(x), x)) = 0, y(x) = c__1

y(x) = c__1

y(x)*(diff(y(x), x)) = 0, y(x) = 0, y(x) = -c__1

y(x) = c__1, y(x) = 0

Download odesteps_hack2.mw

Please don't tell what it doesn't succeed at. This was a 5-minute piece of programming purely for illustration. That frontend'd solve call is blind to lots of forms, and selective freezing might well be much better. It's obviously neither complete nor robust. I even hard-coded it just for y(x).

I know that the OP already has his own ODE solver(s), so I wouldn't be surprised if he already had his own mechanisms to split in similar manners (ie. using ODE techniques for just the parts where derivatives came into it...).

During tracing "unknown" refers to an anonymous procedure.

Here, "anonymous" means that the procedure or operator is constructed without ever being assigned to any name. See subsection 6.9 of the Programming Guide.

That aspect displaying as "unknown" is described in its own subsection of the Description on the Help page of the trace command.

There are various ways to apply an anonymous procedure. For example, using printlevel as you have,

restart:

f := proc(ee,x);
  unapply(ee,x)(2),
  proc(u) u^3; end proc(x),
  (s->s^4)(x);
end proc:

trace(f):
printlevel:=10:
f(x^2+1, x);
printlevel:=1:

{--> enter f, args = x^2+1, x

{--> enter unapply, args = x^2+1, x

[]

x

proc (x) options operator, arrow; x^2+1 end proc

<-- exit unapply (now in f) = proc (x) options operator, arrow; x^2+1 end proc}

{--> enter unknown, args = 2

5

<-- exit unknown (now in f) = 5}

{--> enter unknown, args = x

x^3

<-- exit unknown (now in f) = x^3}

{--> enter unknown, args = x

x^4

<-- exit unknown (now in f) = x^4}

5, x^3, x^4

<-- exit f (now at top level) = 5, x^3, x^4}

5, x^3, x^4

Download unknown_unapply.mw

Another common example is something like the applications of the first argument to map below,

     map(t->t^5,[x]);

The following factored form is simpler than that obtained by
applying just evalf, or evalf and simplify, or expand and evalf, etc.

sol := dsolve({diff(f(x), x) = 0.768e-1*f(x)^(2/3)-0.102e-1*f(x), f(1) = 59}, f(x))

NULL

T := factor(subsindets(sol, specfunc(exp), proc (u) options operator, arrow; (exp(17/5000-(17/5000)*x))^simplify(op(u)/(17/5000-(17/5000)*x)) end proc)); new := evalf(simplify(evalf[20](T)))

f(x) = -48.08619869*(exp(0.34e-2-0.34e-2*x)-2.070558790)^3

NULL

Download worksheet_ac.mw

@Khair Muhammad Saraz 

Is this anything like the kind of static 3d plot you're after, for your followup example?

I can only guess, since you haven't explicitly described what you're actually after.

dq_code_1_acc.mw

Does it help to use an assumption on n?

Using Maple 2022.2, and guessing at your intention,

restart;

c:=1;

1

A := rsolve({a(0)=1/n,a(i)=((n-i+1)/(n-i)+1/(c*(n-i)))*a(i-1)},a)
  assuming n::posint;

(n+1)/((-n+i)*(-n+i-1))

total1 := simplify(combine(expand(sum(eval(A,i=k),k=0..n-1))),size)
  assuming n::posint;

n

evalf(eval(total1, n = 6));

6.

restart;

c:=2;

2

A := rsolve({a(0)=1/n,a(i)=((n-i+1)/(n-i)+1/(c*(n-i)))*a(i-1)},a)
  assuming n::posint;

-(-1)^(n+i)*GAMMA(3/2+n)*GAMMA(-n+i-1/2)*GAMMA(n-i)/(Pi*GAMMA(1+n))

total1 := simplify(combine(expand(sum(eval(A,i=k),k=0..n-1))),size)
  assuming n::posint;

-2+4*GAMMA(3/2+n)/(Pi^(1/2)*GAMMA(1+n))

evalf(eval(total1, n = 6));

3.865234375

restart;

A := rsolve({a(0)=1/n,a(i)=((n-i+1)/(n-i)+1/(c*(n-i)))*a(i-1)},a)
  assuming n::posint;

(-1)^i*GAMMA((c*i-c*n-1)/c)*GAMMA(n-i)/(GAMMA(n+1)*GAMMA(-(c*n+1)/c))

total1 := simplify(sum(eval(A,i=k),k=0..n-1))
  assuming n::posint;

-c+c*(-1)^n*GAMMA(-1/c)/(GAMMA(n+1)*GAMMA((-c*n-1)/c))

evalf(eval(limit(total1,c=1),n=6));

6.

evalf(eval(total1,[c=2,n=6]));

3.865234375

simplify(limit(total1,c=1)) assuming n::posint;

n

simplify(limit(total1,c=2)) assuming n::posint;

-2+4*GAMMA(3/2+n)/(Pi^(1/2)*GAMMA(n+1))

 

 

Download rsolve_ex_simp.mw

First 21 22 23 24 25 26 27 Last Page 23 of 336