acer

30757 Reputation

29 Badges

19 years, 4 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

It is more generally straightforward to programmatically access the results from the ifactors command, rather than from the ifactor command.

x := ifactors(6);

[1, [[2, 1], [3, 1]]]

x[2];

[[2, 1], [3, 1]]

x[2,1,1]

2

x[2,2,1]

3


Download ifactors_ex.mw

One aspect that makes it more sensible is that the methodology can be consistent whether the factors have multiplicity 1 or greater than 1. Eg, whether the original is say 6, or 72. But with ifactor the deconstruction would need a separate case for whether the power was 1 (in which case not actually present) or greater than 1.

a := "x^2";

"x^2"

StringTools:-RegSplit("\\^",a);

"x", "2"


Download regsplit_ex.mw

The codegen:-cost command does this computation (with addition and subtraction having the same "cost").

The individual numbers can be extracted in a usual manner, using coeff.

A := (g*m*s*y-g*m*t*x-g*n*r*y+g*n*t*w+g*o*r*x-g*o*s*w-h*l*s*y+h*l*t*x+h*n*q*y-h*n*t*v-h*o*q*x+h*o*s*v+h2*l*r*y-h2*l*t*w-h2*m*q*y+h2*m*t*v+h2*o*q*w-h2*o*r*v-j*l*r*x+j*l*s*w+j*m*q*x-j*m*s*v-j*n*q*w+j*n*r*v)/(c*h2*o*p*v+d*f*m*q*y-b*h*o*s*u-b*h2*k*r*y+b*h2*k*t*w+d*f*l*t*w-d*f*l*r*y+d*h*k*t*v+d2*f*l*r*x-d*j*m*q*u+d2*g*k*s*w-d2*g*k*r*x+b*h*o*p*x+b*h*n*t*u-b*h*n*p*y+c*f*o*q*x-d*h*k*q*y-d*g*o*r*u+d*g*o*p*w+d*g*m*t*u+c*j*n*q*u-c*j*n*p*v-c*j*l*s*u+c*j*l*p*x-c*g*k*s*y-c*f*o*s*v-d2*h2*k*q*w+d2*h2*k*r*v-c*f*n*q*y-c*f*l*t*x+c*f*l*s*y-b*j*n*r*u-b*f*o*r*x+c*g*n*p*y+c*g*k*t*x+a*h2*l*r*y-a*h2*l*t*w+c*h2*k*q*y+c*g*o*s*u-c*g*o*p*x-c*g*n*t*u-d*j*l*p*w-a*h*o*q*x+a*h*o*s*v+a*h*l*t*x+a*h*n*q*y-a*h*n*t*v+a*g*o*r*x-a*g*o*s*w-a*h*l*s*y+a*g*m*s*y-a*g*m*t*x-a*g*n*r*y+a*g*n*t*w+d*j*m*p*v+b*j*n*p*w+b*j*m*s*u-b*j*m*p*x+d*j*l*r*u+d*h*o*q*u+d*j*k*q*w-d*j*k*r*v-d2*h*l*p*x-d2*f*l*s*w-d2*f*m*q*x+d2*f*m*s*v+d2*f*n*q*w+d2*h2*l*p*w-d2*h2*l*r*u-d2*h2*m*p*v-a*j*l*r*x+a*j*l*s*w+a*j*m*q*x-a*j*m*s*v-a*j*n*q*w+a*j*n*r*v-b*f*m*s*y+b*f*m*t*x+b*f*n*r*y-b*f*n*t*w+b*f*o*s*w-d2*h*k*s*v+c*f*n*t*v-a*h2*m*q*y+a*h2*m*t*v+a*h2*o*q*w-a*h2*o*r*v-d2*f*n*r*v-d2*h*n*q*u+d2*h*k*q*x+d2*g*n*r*u-d2*g*n*p*w+b*h*k*s*y-d2*g*m*s*u+d2*h*n*p*v+c*h2*l*t*u-c*h2*l*p*y-b*h*k*t*x-b*j*k*s*w+b*j*k*r*x-c*h2*o*q*u-c*j*k*q*x+c*j*k*s*v+b*h2*o*r*u-b*h2*o*p*w+d2*g*m*p*x-c*h2*k*t*v-b*h2*m*t*u+b*h2*m*p*y-d*g*m*p*y-d*g*k*t*w+d*g*k*r*y+d*f*o*r*v-d*h*o*p*v+d2*h2*m*q*u-d*h*l*t*u+d2*h*l*s*u+d*h*l*p*y-d*f*o*q*w-d*f*m*t*v)

raw := codegen:-cost(A)

142*additions+552*multiplications+divisions

lprint(raw)

142*additions+552*multiplications+divisions

`~`[coeff](raw, [additions, multiplications, divisions])

[142, 552, 1]


Download Count_the_number_of_operations_in_A_ac.mw

note: If you do it by way of conversion to string then be wary of any special names that might contain the characters of the relevant operators. (That doesn't affect your example, of course.)

You might also be interested in some means of reducting of these numbers.

restart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q+(a*v-b*u)*t+p*(b*y-d2*v))*n+((a*x-d*u)*q+(-a*v+b*u)*s-p*(b*x-d*v))*o-k*((-d*y+d2*x)*q+(b*y-d2*v)*s-t*(b*x-d*v)))*h+(((a*x-d*u)*r+(-a*w+c*u)*s+p*(-c*x+d*w))*l+((-a*x+d*u)*q+(a*v-b*u)*s+p*(b*x-d*v))*m+((a*w-c*u)*q+(-a*v+b*u)*r-p*(b*w-c*v))*n-k*((-c*x+d*w)*q+(b*x-d*v)*r-s*(b*w-c*v)))*j-f*(((-d*y+d2*x)*r+(c*y-d2*w)*s+t*(-c*x+d*w))*l+((d*y-d2*x)*q+(-b*y+d2*v)*s+t*(b*x-d*v))*m+((-c*y+d2*w)*q+(b*y-d2*v)*r-t*(b*w-c*v))*n-((-c*x+d*w)*q+(b*x-d*v)*r-s*(b*w-c*v))*o))

codegen:-cost(new1)

142*additions+245*multiplications+divisions

vars := indets(A, And(name, Not(constant))); new2 := (codegen:-optimize(unapply(A, vars[]), tryhard))(vars[])

(g*((s*y-t*x)*m-(r*y-t*w)*n+o*(r*x-s*w))-h*((s*y-t*x)*l-(q*y-t*v)*n+o*(q*x-s*v))+h2*((r*y-t*w)*l-(q*y-t*v)*m+o*(q*w-r*v))-j*((r*x-s*w)*l-(q*x-s*v)*m+n*(q*w-r*v)))/((f*((r*x-s*w)*l-(q*x-s*v)*m+n*(q*w-r*v))-g*((r*x-s*w)*k-(p*x-s*u)*m+(p*w-r*u)*n)+h*((q*x-s*v)*k-(p*x-s*u)*l+(p*v-q*u)*n)-h2*((q*w-r*v)*k-(p*w-r*u)*l+(p*v-q*u)*m))*d2+(-f*((r*y-t*w)*l-(q*y-t*v)*m+o*(q*w-r*v))+g*((r*y-t*w)*k-(p*y-t*u)*m+(p*w-r*u)*o)-h*((q*y-t*v)*k-(p*y-t*u)*l+(p*v-q*u)*o)+j*((q*w-r*v)*k-(p*w-r*u)*l+(p*v-q*u)*m))*d+(f*((s*y-t*x)*l-(q*y-t*v)*n+o*(q*x-s*v))-g*((s*y-t*x)*k-(p*y-t*u)*n+(p*x-s*u)*o)+h2*((q*y-t*v)*k-(p*y-t*u)*l+(p*v-q*u)*o)-j*((q*x-s*v)*k-(p*x-s*u)*l+(p*v-q*u)*n))*c+(-f*((s*y-t*x)*m-(r*y-t*w)*n+o*(r*x-s*w))+h*((s*y-t*x)*k-(p*y-t*u)*n+(p*x-s*u)*o)-h2*((r*y-t*w)*k-(p*y-t*u)*m+(p*w-r*u)*o)+j*((r*x-s*w)*k-(p*x-s*u)*m+(p*w-r*u)*n))*b+(g*((s*y-t*x)*m-(r*y-t*w)*n+o*(r*x-s*w))-h*((s*y-t*x)*l-(q*y-t*v)*n+o*(q*x-s*v))+h2*((r*y-t*w)*l-(q*y-t*v)*m+o*(q*w-r*v))-j*((r*x-s*w)*l-(q*x-s*v)*m+n*(q*w-r*v)))*a)

codegen:-cost(new2)

142*additions+245*multiplications+divisions

LC := MmaTranslator:-Mma:-LeafCount

`~`[LC]([A, new1, new2])

[917, 829, 848]

Download Count_the_number_of_operations_in_A_acc.mw

Sometimes one can beat simplify(...,size) for this kind of thing through special use of collect.

The applyrule command is not receiving what you think, due to usual evaluation rules for procedure calls.

You could do this, instead,

e1 := sin(2*sqrt(a*b)*(t+mu));

sin(2*(a*b)^(1/2)*(t+mu))

applyrule( sin(x::anything) = cos('expand'(x)), e1 );

cos(2*(a*b)^(1/2)*t+2*(a*b)^(1/2)*mu)


Download applyrule_defer.mw

You can use trace to see what applyrule was actually receiving, for your example.

e1 := sin(2*sqrt(a*b)*(t+mu)):
trace(applyrule):

applyrule( sin(x::anything) = cos(expand(x)), e1 );

{--> enter applyrule, args = sin(x::anything) = cos(x), sin(2*(a*b)^(1/2)*(t+mu))
...

The above trace details show that applyrule was actually receiving the first of these next two results as its first argument. But you want it to receive something like the second.

sin(x::anything) = cos(expand(x))
                   sin(x::anything) = cos(x)

sin(x::anything) = cos('expand'(x))
               sin(x::anything) = cos(expand(x))

Here I'm using the same formula in each of your cases.

restart;

styles:=[symbol=solidcircle,symbolsize=20]:

C:=[red,green,blue,magenta]:

nC := nops(C);

4

L:=[[1,2],[3,4],[-5,6],[-3,-2]];

[[1, 2], [3, 4], [-5, 6], [-3, -2]]

plots:-display(plottools:-point( L, styles[],
                                 color=[seq(C[],i=1..iquo(nops(L),nC)),
                                        C[..irem(nops(L),nC)][]] ))

#too few point for the colours;
L1:=[[1,2],[3,4],[-5,6]];

[[1, 2], [3, 4], [-5, 6]]

plots:-display(plottools:-point( L1, styles[],
                                 color=[seq(C[],i=1..iquo(nops(L1),nC)),
                                        C[..irem(nops(L1),nC)][]] ))

#too many point for the colours;
f:=rand(-5.0..5.0):
L2 := [seq([f(),f()],i=1..rand(25..35)())]: nops(L2);

31

plots:-display(plottools:-point( L2, styles[],
                                 color=[seq(C[],i=1..iquo(nops(L2),nC)),
                                        C[..irem(nops(L2),nC)][]] ))

 

Download 2024-09-06_Q_Extend_or_Truncate_List_of_Colours_ac.mw

Since it's the same formula (except for the name of the data list) making a re-usable procedure for it is very easy. Here's that revision:
List_of_Colours_ac2.mw


ps. I suppose a fun alternative might be to split the data list L into min(nops(C),nop(L)) separate lists (using say indexed position in L, modulo nops(C)) and then construct plots for each using the appropriate single color.

restart


I use the right-click menu to convert the following to an "atomic variable", ie, a special name which the GUI prints nicely but is in fact just a Maple name underneath.

   2-D Math -> Convert To -> Atomic Variable

`#mover(mi("x"),mo("¯"))`

`#mover(mi("x"),mo("¯"))`

lprint(%)

`#mover(mi("x"),mo("¯"))`

v := %

`#mover(mi("x"),mo("¯"))`

diff(v^2, v)

2*`#mover(mi("x"),mo("¯"))`

 


I can copy&paste from the output that I converted above, if I want to re-use it in additional 2D Input.

diff(sin(`#mover(mi("x"),mo("¯"))`^2), v)

2*`#mover(mi("x"),mo("¯"))`*cos(`#mover(mi("x"),mo("¯"))`^2)

`#mover(mi("x"),mo("¯"))`

`#mover(mi("x"),mo("¯"))`

``

Download How_do_I_make_an_accented_symbol_inert_ac.mw

More programmatic alternatives include temporary substitution (freeze & thaw, say) or (sometimes) using frontend.

I'll address your error message: [Length of output exceeds limit of 1000000]

If you are going to assign the odeplot result to a name then the GUI can get confused when trying to inline print/display the output. (...in the case that the plot structure is very large.)

You can get around that by doing it in two steps:

# Note that this next statement is terminated with a full colon.
phaseplot := odeplot(sol, [x(t), y(t)], 0 .. 20000, numpoints = 20000,
                     color = red, thickness = 2,
                     axes = boxed, gridlines,
                     title = "Phase-space Diagram"):

# Now, terminating with a semicolon, to show it.
phaseplot;

extra_steps_ac.mw

 

e := Int(1/(3*u^4 + u + 3), u):

IntegrationTools:-Change(e, u=y*x^(1/3), y);

    Int(x/(3*x^2*y^4+x*y+3*x^(2/3)),y)

One way is the following change of variables, after which the integration succeeds.

Then, the actions after the call to value are just to massage the form. You can adjust or fiddle with them to get variants.

But simplify of the difference between this form and your particular target form produces zero.

restart;

kernelopts(version);

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

foo := Int(sqrt(x^2+sqrt(x^4+1))/(x+1)/sqrt(x^4+1),x=0..infinity);

Int((x^2+(x^4+1)^(1/2))^(1/2)/((x+1)*(x^4+1)^(1/2)), x = 0 .. infinity)

bar := IntegrationTools:-Change(foo,u=x^2 + sqrt(x^4 + 1)):

combine(evala(convert(simplify(value(bar)),ln)));

(1/8)*(2+2*2^(1/2))^(1/2)*ln(113+80*2^(1/2)+72*(1+2^(1/2))^(1/2)+52*(2+2*2^(1/2))^(1/2))


Download Int_CW.mw

It's not clear to me what might be your precise problem or actual goal.

But here is a modified example.

Test_ac.zip

Are you trying to get something like the following?

restart;

y := (1 + diff(u(r), r))*diff(u(r), r, r)
     + (1 + vs*u(r)/r + (1 - vs)/2*diff(u(r), r))*diff(u(r), r)/r
     - (1 + (1 + vs)/(2*r)*u(r))*u(r)/r^2;

(1+diff(u(r), r))*(diff(diff(u(r), r), r))+(1+vs*u(r)/r+(1/2)*(1-vs)*(diff(u(r), r)))*(diff(u(r), r))/r-(1+(1/2)*(1+vs)*u(r)/r)*u(r)/r^2

PDEtools:-dchange({r=R*rs, u(r)=h*U(R*rs)}, y, [rs, U]);

(1+h*(D(U))(R*rs))*h*((D@@2)(U))(R*rs)+(1+vs*h*U(R*rs)/(R*rs)+(1/2)*(1-vs)*h*(D(U))(R*rs))*h*(D(U))(R*rs)/(R*rs)-(1+(1/2)*(1+vs)*h*U(R*rs)/(R*rs))*h*U(R*rs)/(R^2*rs^2)


Download dchange_ex.mw

It works if one specifies the function, eg. as y(x).

(That error message is attempting to describe an ambiguity, otherwise)

ode:=diff(y(x),x$2)+diff(y(x),x)+y(x)=0;

diff(diff(y(x), x), x)+diff(y(x), x)+y(x) = 0

dsolve([ode,D(y)(a)=b], y(x));

y(x) = (3^(1/2)*c__2*sin((1/2)*3^(1/2)*a)+2*b*exp((1/2)*a)+c__2*cos((1/2)*3^(1/2)*a))*exp(-(1/2)*x)*sin((1/2)*3^(1/2)*x)/(3^(1/2)*cos((1/2)*3^(1/2)*a)-sin((1/2)*3^(1/2)*a))+c__2*exp(-(1/2)*x)*cos((1/2)*3^(1/2)*x)

dsolve_exx.mw

The following takes about 1sec on my machine,

map(u->fsolve(unapply('evalf[15]'(u),T)),
    subsindets((rhs-lhs)~(eval(eqList,t=T)),
               specfunc(Int),
               uu->Int(op(uu),method=_d01ajc,digits=15)));

  [-4.000000000, -3.139954398, -2.113700371, -1.528831968, 
   -1.048408886, -0.7066382663, -0.4795776807, -0.3151696062, 
   -0.1824325597, -0.06254879140, 0.08914597087, 0.3686891818, 
   1.504692983, 2.115525214, 2.461195982, 2.720883279, 
   2.962135688, 3.213074710, 3.598125622, 5.163493045, 
   6.560014160, 6.814134444, 6.668244819, 6.405779566, 
   6.193526060, 6.022014505, 5.954332725, 6.067614012,
   6.326776518]

The term "student portal" is quite often used to refer to the following documentation, which is available both online as well as (offline) in the Maple GUI's own Help system:  Maple Portal
(nb. In the actual Maple GUI you can issue ?portal or search for the term portal in the Help browser.)

A slightly higher link is this Student Help Center link.

There is also the Teacher Resource link, and the online Training link.

And all of those can be accessed from Maplesoft's main webpage, under the Support and Resources tab at the top.

You can do,

    rtable_eval(M)

That command was invented for dealing with this kind of situation.

The behavior you showed relates to a full eval not making a copy of an rtable, which relates to the (good) design of not having the mutable rtable structures (Matrix,Vector,Array) get passed as copies when they're arguments in procedure calls. (This allows for in-place sematics for rtables, in procedure calls.)

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