Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

Hi again everybody,

Made some easy Maple code to find some special prime numbers.

Namely, positive prmie numbers p 
such that p, p+2, and p+6 are all prime numbers

see prime_triples_p_p_and_2__p_and_6.mw

prime_triples_p_p_and_2__p_and_6.pdf

for your viewing pleasure

Have a good day.

 

Matthew

With the new ribbon interface (and startup-page disabled) I need to open a new worksheet to make opening files by the recent document menu work.

Can someone reproduce this?

I write text in Trebuchet MS. When inserting footers I have noticed that the print preview displays page numbers not with the same font (most likely in Times New Roman).

How to change the font of page numbers and other items in headers and footers?

 

 

I am attempting to solve an optimization problem using the Karush–Kuhn–Tucker (KKT) conditions, where the objective function is to be maximized subject to a constraint that may or may not be binding. However, when solving the system, the KKT multiplier (μ1​) consistently evaluates to zero, even when the constraint appears to be active. I am unable to determine the optimal value of μ1​ and seek guidance on how to obtain the optimal values of Pn, Pr, and w, as well as the correct condition for μ1​.


 

``

restart

with(Optimization); with(plots); with(LinearAlgebra)

_local(Pi)

Pi

(1)

``

`π_m` := proc (Pn, Pr, w) options operator, arrow; (Pn-Cn)*(1-(Pn-Pr)/(1-delta))+(Pr-w-Crm)*alpha*(1/2+(1/2)*((Cr*Pn*i2-Cr*Pn*tau-Cr*Pr*i2+Cr*Pr*tau+Cr*delta*i2-Cr*delta*tau+2*delta*i2*tau-2*delta*tau^2+2*w*tau*delta-Cr*i2+Cr*tau-2*i2*tau+2*tau^2-2*w*tau)/(Cr*Pn-Cr*Pr+Cr*delta+4*tau*delta-Cr-4*tau)-i2)/tau)*(1-(Pn-Pr)/(1-delta))-Ce*rho0*(1-(Pn-Pr)/(1-delta)) end proc

proc (Pn, Pr, w) options operator, arrow; (Pn-Cn)*(1-(Pn-Pr)/(1-delta))+(Pr-w-Crm)*alpha*(1/2+(1/2)*((Cr*Pn*i2-Cr*Pn*tau-Cr*Pr*i2+Cr*Pr*tau+Cr*delta*i2-Cr*delta*tau+2*delta*i2*tau-2*delta*tau^2+2*w*tau*delta-Cr*i2+Cr*tau-2*i2*tau+2*tau^2-2*w*tau)/(Cr*Pn-Cr*Pr+Cr*delta+4*tau*delta-Cr-4*tau)-i2)/tau)*(1-(Pn-Pr)/(1-delta))-Ce*rho0*(1-(Pn-Pr)/(1-delta)) end proc

(2)

``

``

NULL

C1 := (((Cr+4*tau)*delta-4*tau+(Pn-Pr-1)*Cr)*rho0+(delta-1)*(i2-tau))/(delta-1) <= w

(((Cr+4*tau)*delta-4*tau+(Pn-Pr-1)*Cr)*rho0+(delta-1)*(i2-tau))/(delta-1) <= w

(3)

NULL

# No equality constraints
 
      f[1] := (Pn,Pr,w) -> (((Cr + 4*tau)*delta - 4*tau + (Pn - Pr - 1)*Cr)*rho0 + (delta - 1)*(i2 - tau))/(delta - 1)-w:

 

# Lagrangian (we want to maximize `&pi;_m` so to minimize -`&pi;_m`

L := -`&pi;_m`(Pn,Pr,w) + add(f[i](Pn,Pr,w)*mu[i], i=1):

dLdPn := collect(diff(L, Pn), [Pn]):
dLdPr := collect(diff(L, w), [Pr]):
dLdw := collect(diff(L, w), [w]):

KKT_conditions := [
                    seq(mu[i] >= 0, i=1),         # Dual feasibility conditions
                    dLdPn = 0,  
dLdPr = 0,
dLdw = 0,                     # Stationarity condition
                    seq(``(f[i](Pn,Pr,w)) <= 0, i=1),  # Primal feasibility conditions
                    add(mu[i]*f[i](Pn,Pr,w) = 0, i=1)  # Complementary slackness
                  ]:

 print~(KKT_conditions):

0 <= mu[1]

 

-1+(Pn-Pr)/(1-delta)+(Pn-Cn)/(1-delta)-(1/2)*(Pr-w-Crm)*alpha*((Cr*i2-Cr*tau)/(Cr*Pn-Cr*Pr+Cr*delta+4*delta*tau-Cr-4*tau)-(Cr*Pn*i2-Cr*Pn*tau-Cr*Pr*i2+Cr*Pr*tau+Cr*delta*i2-Cr*delta*tau+2*delta*i2*tau-2*delta*tau^2+2*delta*tau*w-Cr*i2+Cr*tau-2*i2*tau+2*tau^2-2*tau*w)*Cr/(Cr*Pn-Cr*Pr+Cr*delta+4*delta*tau-Cr-4*tau)^2)*(1-(Pn-Pr)/(1-delta))/tau+(Pr-w-Crm)*alpha*(1/2+(1/2)*((Cr*Pn*i2-Cr*Pn*tau-Cr*Pr*i2+Cr*Pr*tau+Cr*delta*i2-Cr*delta*tau+2*delta*i2*tau-2*delta*tau^2+2*delta*tau*w-Cr*i2+Cr*tau-2*i2*tau+2*tau^2-2*tau*w)/(Cr*Pn-Cr*Pr+Cr*delta+4*delta*tau-Cr-4*tau)-i2)/tau)/(1-delta)-Ce*rho0/(1-delta)+Cr*rho0*mu[1]/(delta-1) = 0

 

alpha*(1/2+(1/2)*((Cr*Pn*i2-Cr*Pn*tau-Cr*Pr*i2+Cr*Pr*tau+Cr*delta*i2-Cr*delta*tau+2*delta*i2*tau-2*delta*tau^2+2*delta*tau*w-Cr*i2+Cr*tau-2*i2*tau+2*tau^2-2*tau*w)/(Cr*Pn-Cr*Pr+Cr*delta+4*delta*tau-Cr-4*tau)-i2)/tau)*(1-(Pn-Pr)/(1-delta))-(1/2)*(Pr-w-Crm)*alpha*(2*delta*tau-2*tau)*(1-(Pn-Pr)/(1-delta))/((Cr*Pn-Cr*Pr+Cr*delta+4*delta*tau-Cr-4*tau)*tau)-mu[1] = 0

 

alpha*(2*delta*tau-2*tau)*(1-(Pn-Pr)/(1-delta))*w/((Cr*Pn-Cr*Pr+Cr*delta+4*delta*tau-Cr-4*tau)*tau)+alpha*(1/2+(1/2)*((Cr*Pn*i2-Cr*Pn*tau-Cr*Pr*i2+Cr*Pr*tau+Cr*delta*i2-Cr*delta*tau+2*delta*i2*tau-2*delta*tau^2-Cr*i2+Cr*tau-2*i2*tau+2*tau^2)/(Cr*Pn-Cr*Pr+Cr*delta+4*delta*tau-Cr-4*tau)-i2)/tau)*(1-(Pn-Pr)/(1-delta))-(1/2)*(Pr-Crm)*alpha*(2*delta*tau-2*tau)*(1-(Pn-Pr)/(1-delta))/((Cr*Pn-Cr*Pr+Cr*delta+4*delta*tau-Cr-4*tau)*tau)-mu[1] = 0

 

``((((Cr+4*tau)*delta-4*tau+(Pn-Pr-1)*Cr)*rho0+(delta-1)*(i2-tau))/(delta-1)-w) <= 0

 

((((Cr+4*tau)*delta-4*tau+(Pn-Pr-1)*Cr)*rho0+(delta-1)*(i2-tau))/(delta-1)-w)*mu[1] = 0

(4)

 

NULL


 

Download Solve_mu1.mw

Maple help does not have an example I could find showing the right way to call method, which is meant to be called only from the constructor the object, before the object is fully build.

Help page does not have such example.

This worksheet shows 3 possible ways to do this. All seem to work fine. I am sure one can come up with more variations.

The question is, which one of these calls is the "right" way?

The method called from the constructor in this example is called process_age().

If someone knows an official Maple documentation showing one example of calling  a proc from constructor that will also help.

Version 1

 

restart;

module person()
   option object;

   local _name::string;
   local _age::posint;

   export ModuleCopy::static := proc( _self, proto::person,
        name::string,age::posint,$)
        _name:=name;
        _age:=process_age(age);
   end proc;

   local process_age:=proc(age::posint,$)::posint;
         age+1;
   end proc;

   export get_age::static:=proc(_self,$)::posint;
          _age;
   end proc;
end module;

module person () local _name::string, _age::posint, process_age; option object; end module

o:=Object(person,"me",99);
o:-get_age()

module person () local _name::string, _age::posint, process_age; option object; end module

100

 

 

Version 2

 

restart;

module person()
   option object;

   local _name::string;
   local _age::posint;

   export ModuleCopy::static := proc( _self, proto::person,
        name::string,age::posint,$)
        _name:=name;
        _age:=process_age(age);
   end proc;

   local process_age::static:=proc(age::posint,$)::posint;
         age+1;
   end proc;

   export get_age::static:=proc(_self,$)::posint;
          _age;
   end proc;
end module;

module person () local _name::string, _age::posint; option object; end module

 

o:=Object(person,"me",99);
o:-get_age()

module person () local _name::string, _age::posint; option object; end module

100

 

 

Version 3

 

restart;

module person()
   option object;

   local _name::string;
   local _age::posint;

   export ModuleCopy::static := proc( _self, proto::person,
        name::string,age::posint,$)
        _name:=name;
        _age:=_self:-process_age(age);
   end proc;

   local process_age::static:=proc(_self,age::posint,$)::posint;
         age+1;
   end proc;

   export get_age::static:=proc(_self,$)::posint;
          _age;
   end proc;
end module;

module person () local _name::string, _age::posint; option object; end module

 

 

o:=Object(person,"me",99);
o:-get_age()

module person () local _name::string, _age::posint; option object; end module

100

 

 

Download correct_way_to_call_method_from_constructor_oct_17_2025.mw

I have a Pascal program. I want to use a Maple program inside the Pascal program when calling it each time. I dont know how to interact Maple with Pascal. For this, could you give me over a small program? Yours Sincerely

The pair of symbols that stand for "isomorphic" and "not isomorphic" - basically equality sign with a tilda on top - seem to be conspicuously absent from all the palettes that I've seen. Is it hidden somewhere I failed to find it or actually absent - and if latter, is there any reason for that ? It seems to be a rather basic symbol, especially compared to much more niche stuff in "Relational" palette. 

Another conspicuously absent symbol is "not a subset". We have good old subset, and a "notSquareSubset" but I couldn't locate the "not a subset" in any palette. 

Less critical but still noticeable is absence of various arrows indicating surjectivity, injectivity and bijectivity. 

Is there perhaps a workaround to typesetting all of the above ? Copying from another document works usually but it's not a very convenient way. And if they are actually absent, perhaps we could ask the good folks at Maple to add them for the next update if it's not too much trouble ?

Isomorphism symbol : ≅
"Not a [proper] subset" symbols :  ⊈ ⊄
Arrows : in LaTex, \rightarrowtail \twoheadrightarrow \twoheadrightarrowtail 
Arrows

How Maple 2023 displays new results with old results together

Help page for structured types shows examples where they add delayed quotes around things. For example

So I started writing  'specfunc(anything,y)' instead of just  specfunc(anything,y). Only to find this breaks things when used inside a proc.

Here is an example.

restart;

#here it worksheetdir
IC:=y(x)=0;
indets(IC,'specfunc(anything,y)');      

y(x) = 0

{y(x)}

#inside proc, same code fail
foo:=proc(func::function(name),IC::`=`)
    local y::symbol:=op(0,func);
    indets(IC,'specfunc(anything,y)');
end proc:
 

foo(y(x),y(x)=0)

{}

 

 

Removing the quotes, it now works

restart;

#here it worksheetdir
IC:=y(x)=0;
indets(IC,'specfunc(anything,y)');      

y(x) = 0

{y(x)}

#inside proc, same code fail
foo:=proc(func::function(name),IC::`=`)
    local y::symbol:=op(0,func);
    indets(IC,specfunc(anything,y));
end proc:
 

foo(y(x),y(x)=0)

{y(x)}

 

 

Download delayed_vs_not_v2.mw

Download delayed_vs_not.mw

It took me 2 hrs debugging to find this, as when I copied code which was working in my worksheet to my function, it stopped working and did not know why.

So for now, I will not use quotes around specfunc or any others like the help page shows in its examples.

Is there a rule of thumb to follow here? The help page is very inconsistent. It shows some examples with quotes around and some without. Makes it hard to know why and when to add the delayed quotes. It seems arbitrary.

When doing variable change for a differential equation, dchange works well for transformations like {s=r sin(theta),z=r cos(theta)}, but it does not seem to work if you include constant values like {s=(k-1)*r sin(theta)}, how can I let maple know that k is to be treated as a constant?

Good day.

Using the iterative map routine, the location of the bifurcation points of the logistic function can be determined using the plot (see attached).

I was wondering .. is it possible to estimate and output the locations of these points and the range of the function? I would like to explore the bifurcation behavior for the modified function so, this would be a great help. 

In this case, the location of the points are: (1.00,0.00), (3.00, 0.66), (3.45, 0.44), (3.45, 0.85) and the range is [0,4]. 

Thanks for reading!

MaplePrimes_Oct_16.mw

I gave up on this. I know how to find all normal derivatives such as diff(y(x),x) and diff(y(x),x$2) so on in expression. 

But now I want to find all those used for initial conditions, which do not have x in them. This makes it harder.

These have the form   D(y)(0) or (D@@2)(y)(1) and so on.

I tried indets and select and many other things, but can't figure how to tell Maple to find these in expression. Here is an example.

Given

expr:=y(3)+y(8)+5*(D@@2)(y)(4)+Pi+3*exp(2)+77*D(y)(0)+1/(D@@4)(y)(7);

I'd like to get list that has in it only the derivatives and nothing else, anywhere they show, which will be

{(D@@2)(y)(4) , D(y)(0) , (D@@4)(y)(7) }

some of the things I tried are

indets(expr,'satisfies'(s->op(0,s)=(D@@n)(y) and n::integer) );
indets(expr,'specfunc(anything, D)');
indets(expr,'specfunc(anything, (D@@anything)(y))');

And many more. I still struggle with structured types in Maple.

In the above, we can assume the dependent variable is always same which is the 'y' symbol.

I can do the above using patmatch. But I am trying to move away from that in Maple and use types.

For reference, this is what I do using another software. I am trying to do the same in Maple, but using structured types and not patmatch.

Iam sure there is a way to do this in Maple using structured types, but so far not able to figure the syntax needed.

Maple 2025.1

I use the tab key to control the formatting of lists. 

On my computer the tab key spacing under Maple 2025 is a little more than one inch which is too much. I have been through the Maple Help and cannot find how to change the tab key spacing.

Any help will be greatly appreciated.

My current account email is dead so I can only view answers here.

I want to solve differential equations using dsolve and plot the solution in the range plot(E(nu), nu=10^14…10^18) of the equation.

restart;

with(PDEtools, dchange):

N:=8*Pi*Tq^2*nu^2*E(nu)/(c^3*(exp(E(nu)/(k*T)) - 1));V:=Pi*rb^3;

8*Pi*Tq^2*nu^2*E(nu)/(c^3*(exp(E(nu)/(k*T))-1))

 

Pi*rb^3

(1)

Et:=dchange({nu=1/t},N*V,expand);#Change of var in t = period of a single oscilation;

8*Pi^2*Tq^2*E(t)*rb^3/(t^2*c^3*(exp(E(t)/(k*T))-1))

(2)

Sol_T:=subs(t=t,(Et)-subs(t=t+Tq,(Et)));#We do the calculus per one period Tq;

8*Pi^2*Tq^2*E(t)*rb^3/(t^2*c^3*(exp(E(t)/(k*T))-1))-8*Pi^2*Tq^2*E(t+Tq)*rb^3/((t+Tq)^2*c^3*(exp(E(t+Tq)/(k*T))-1))

(3)

Sol_nu:= dchange({t=1/nu},Sol_T,params=Tq,expand);# I like to go back to variable nu but is correct???;

8*Pi^2*Tq^2*nu^2*E(nu)*rb^3/(c^3*(exp(E(nu)/(k*T))-1))-8*Pi^2*Tq^2*E(nu)*rb^3/((1/nu+Tq)^2*c^3*(exp(E(nu)/(k*T))-1))

(4)

B:=int(diff(Sol_nu,nu),t=t..t+Tq);

16*Pi^2*Tq^3*nu*E(nu)*rb^3/(c^3*(exp(E(nu)/(k*T))-1))+8*Pi^2*Tq^3*nu^2*(diff(E(nu), nu))*rb^3/(c^3*(exp(E(nu)/(k*T))-1))-8*Pi^2*Tq^3*nu^2*E(nu)*rb^3*(diff(E(nu), nu))*exp(E(nu)/(k*T))/(c^3*(exp(E(nu)/(k*T))-1)^2*k*T)-16*Pi^2*Tq^3*E(nu)*rb^3/((1/nu+Tq)^3*c^3*(exp(E(nu)/(k*T))-1)*nu^2)-8*Pi^2*Tq^3*(diff(E(nu), nu))*rb^3/((1/nu+Tq)^2*c^3*(exp(E(nu)/(k*T))-1))+8*Pi^2*Tq^3*E(nu)*rb^3*(diff(E(nu), nu))*exp(E(nu)/(k*T))/((1/nu+Tq)^2*c^3*(exp(E(nu)/(k*T))-1)^2*k*T)

(5)

dsolve(Sol_nu=A*B,E(nu));#Where A = constant

-nu+3*A*Tq*ln(nu)-2*A*Tq*ln(Tq*nu+1)+A*Tq*ln(Tq*nu+2)-A*Tq*ln(exp(E(nu)/(k*T))-1)+A*Tq*ln(E(nu))+_C1 = 0

(6)

E(nu):=solve(E(nu)=-nu + A*Tq*ln(Tq*nu + 2) + 3*A*Tq*ln(nu) - 2*A*Tq*ln(Tq*nu + 1) - A*Tq*ln(exp(E(nu)/(k*T)) - 1) + A*Tq*ln(E(nu))+C1,E(nu));

ln(exp(RootOf(-A*Tq*ln(nu^3*(Tq*nu+2)*ln(exp(_Z)+1)*T*k/(Tq*nu+1)^2)+_Z*A*Tq+ln(exp(_Z)+1)*T*k-C1+nu))+1)*T*k

(7)

#E(nu)=???

k:= 1.3806490000*10^(-23);rb:=5.293*10^(-11);
ec:= 1.602176634*10^(-19);Tq:=1.765*10^(-19);
c:= 299792458;T:=297;A:=1;

0.1380649000e-22

 

0.5293000000e-10

 

0.1602176634e-18

 

0.1765000000e-18

 

299792458

 

297

 

1

(8)

plot(-nu - 2*A*Tq*ln(Tq*nu + 1) + 3*A*Tq*ln(nu) + A*Tq*ln(Tq*nu + 2),nu=10^14..10^18);#Approx neglecting => -A*Tq*ln(exp(E(nu)/(k*T)) - 1) + A*Tq*ln(E(nu))

 

plot(E(nu),nu=10^14..10^18);

Warning, expecting only range variable nu in expression ln(exp(RootOf(-A*Tq*ln(nu^3/(Tq*nu+1)^2*(Tq*nu+2)*ln(exp(_Z)+1)*T*k)+_Z*A*Tq+ln(exp(_Z)+1)*T*k-C1+nu))+1)*T*k to be plotted but found names [A, C1, T, Tq, k]

 

 
 

 

Download plm.mw

Given a list of n characters, for example [a,1,=,#,@,B,...]. Please help me use Maple command to randomly pick k elements, each element consists of q consecutive random characters, for example, randomly pick 4 elements, each element consists of 3 consecutive random characters a1=, aa&, BC!, 90%. Thank you very much for your help!

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