acer

32642 Reputation

29 Badges

20 years, 56 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Here is a Maple sheet that illustrates a pitfall, and a couple of alternatives.

Let us know if aspects are still unclear.
 

restart

eq3 := M[a] + M[8] = 2.109e7:

eq4 := M[a] = 1e7:

raw := solve([eq3,eq4],{M[8],M[a]})

{M[8] = 11090000., M[a] = 10000000.}

raw[1];

M[8] = 11090000.


This is analogous to what went wrong in your Maple Flow sheet.
You were attempting to assign to name M[8] an equation that
actually contains M[8]. That'd lead to an infinite recursion error.

 

M[8] := raw[1]

Error, recursive assignment

M[8] := M[8] = 1.1090000*10^7

Error, recursive assignment

 


Here is one way to pick off the value for M[8] in the solution
returned by solve. This could be used programatically. So,
one alternative is to not do any actual assignment to M[8].

(I usually prefer this approach, since I can evaluate any compound
formula using the solved values. But I can also still look at the equations
without the substitution.)

eval(M[8], raw)

11090000.


Now, on to doing the assignment:

As a first way, you could write out the assignment, as an explicit statement.

Note that this is much better than indexing raw[1] which is not robust.
Positional reference like that is weaker than picking off the value via eval,
because if your variable names were ever changed then the relative
positions might change too (breaking the fragile code).

M[8] := eval(M[8], raw)

11090000.

M[8]

11090000.

M[a]

M[a]


Or, as a second way, you could get both the equations in raw to be
used for assignment.

assign(eval(raw,1)[])


Now both variables have been assigned.

That second way would have worked even without the first, explicit, assignment statement

M[a]

10000000.

M[8]

11090000.


Download solve_asn_rec.mw

 

ps. At the risk of partly repeating myself...
    M[8] := eval(M[8], raw);        # OK
    M[8] := rhs(raw[1]));             # poor

[edit]
Maple guards against a recursive assignment, as shown above. If you trick/force it, and then evaluate, you can see a similar error message to what you had from Maple Flow. I mention this just to illustrate the similarity. Eg,

restart

assign(M[8], M[8] = 1.1090000*10^7);

M[8];

Error, too many levels of recursion

Is this the kind of thing you're after, for the,
   MinMachineNumber
   MaxMachineNumber

restart;

kernelopts(version);

`Maple 2024.2, X86 64 LINUX, Oct 29 2024, Build ID 1872373`

 

L:=[FLT_RADIX,DBL_MANT_DIG,DBL_DIG,DBL_EPSILON,DBL_MIN_EXP,DBL_MIN,
    DBL_MIN_10_EXP,DBL_MAX_EXP,DBL_MAX,DBL_MAX_10_EXP,LNMAXFLOAT]:

 

seq(lprint(nm=evalhf(nm)),nm=L);

FLT_RADIX = 2.
DBL_MANT_DIG = 53.
DBL_DIG = 15.
DBL_EPSILON = .222044604925031308e-15
DBL_MIN_EXP = -1021.
DBL_MIN = .100000010000000008e-306
DBL_MIN_10_EXP = -307.
DBL_MAX_EXP = 1024.
DBL_MAX = .99999999000000001e308
DBL_MAX_10_EXP = 308.
LNMAXFLOAT = 706.893000000000029

Download evalhf_const.mw

See the ?evalhf,constant Help page.

And for the "software" float case, you could look at the ?Maple_floats Help page. (But MAX_FLOAT divided by MIN_FLOAT would produce Float(infinity) in that context... as would DBL_MAX/DBL_MIN under evalhf.)

The union command merges sets.

In this example, you don't need union at all. You can just use {C4, C44} .

If C3 and C4 were themselves sets, then you could use {C4} union {C44} (and which would also work here).

restart

C1 := (Cr*Pr*d*rho0-Cr*d*delta*rho0+Ce*d*delta+Cr*d*rho0-c*d*delta+d*delta*w-delta*g*i2-Ce*d+2*Pr*rho0+a*delta+c*d-d*w-2*delta*rho0+g*i2-a+2*rho0)/(rho0*(Cr*d+2)) <= Pn; C11 := Pn <= (Cr*Pr*d*upsilon-Cr*d*delta*upsilon+Ce*d*delta+Cr*d*upsilon-c*d*delta+d*delta*w-delta*g*i2-Ce*d+2*Pr*upsilon+a*delta+c*d-d*w-2*delta*upsilon+g*i2-a+2*upsilon)/(upsilon*(Cr*d+2))

`&Pi;m` := (Pn-Cn)*(1-(Pn-Pr)/(1-delta))+(Pr-w-Crm)*alpha*((((-a+0.4e-1*g)*Cr-c-(-2*a*d*delta+0.6e-1*d^2+0.3e-1*Cr*alpha*d^2*rho0^2+Cn*Cr*d^2*rho0-Cr*Pr*d^2*rho0+Cr*d^2*delta*rho0+2*Crm*alpha*d*rho0^2-2*Pr*alpha*d*rho0^2-2*alpha*c*d*rho0^2+0.8e-1*d*delta*g+2*c*d^2*delta+2*d*delta*rho0+2*alpha*c*rho0^2-0.8e-1*alpha*g*rho0^2+2*Cn*d*rho0+0.6e-1*alpha*d*rho0^2+0.3e-1*Cr*d^2*rho0^2-2*Pr*d*rho0-Cr*d^2*rho0+Cr*Crm*alpha*d^2*rho0^2-Cr*Pr*alpha*d^2*rho0^2-Cr*alpha*c*d^2*rho0^2+Cr*alpha*c*d*rho0^2-0.4e-1*Cr*alpha*d*g*rho0^2+2*a*d-2*c*d^2-0.6e-1*d^2*delta+0.6e-1*d*rho0^2-0.8e-1*d*g-2*d*rho0)/(2*d*(Cr*alpha*d*rho0^2+2*alpha*rho0^2-d*delta+d))+0.3e-1)*d+0.4e-1*g-a)/(Cr*d+2)-0.4e-1*g+a)-(0.3e-1*(((-a+0.4e-1*g)*Cr-c-(-2*a*d*delta+0.6e-1*d^2+0.3e-1*Cr*alpha*d^2*rho0^2+Cn*Cr*d^2*rho0-Cr*Pr*d^2*rho0+Cr*d^2*delta*rho0+2*Crm*alpha*d*rho0^2-2*Pr*alpha*d*rho0^2-2*alpha*c*d*rho0^2+0.8e-1*d*delta*g+2*c*d^2*delta+2*d*delta*rho0+2*alpha*c*rho0^2-0.8e-1*alpha*g*rho0^2+2*Cn*d*rho0+0.6e-1*alpha*d*rho0^2+0.3e-1*Cr*d^2*rho0^2-2*Pr*d*rho0-Cr*d^2*rho0+Cr*Crm*alpha*d^2*rho0^2-Cr*Pr*alpha*d^2*rho0^2-Cr*alpha*c*d^2*rho0^2+Cr*alpha*c*d*rho0^2-0.4e-1*Cr*alpha*d*g*rho0^2+2*a*d-2*c*d^2-0.6e-1*d^2*delta+0.6e-1*d*rho0^2-0.8e-1*d*g-2*d*rho0)/(2*d*(Cr*alpha*d*rho0^2+2*alpha*rho0^2-d*delta+d))+0.3e-1)*d+0.4e-1*g-a))/(Cr*d+2)+0.12e-2*g-0.3e-1*a

DATA := [delta = .7, a = .2, d = .9, g = .3, c = 0.2e-1, sigma = .5, Cn = .35, Crm = .1, Cr = 0.1e-1, rho0 = .4, Pr = .6, alpha = .9, s = .21, upsilon = .95]

TRC := proc (Pn, w) options operator, arrow; eval(`&Pi;m`, DATA) end proc; C2 := subs(DATA, C1); C22 := subs(DATA, C11)

C3 := isolate(C2, w); C33 := isolate(C22, w)

t := {0.3e-1, 0.5e-1, 0.7e-1, 0.9e-1}; ts := {0.4e-1, 0.8e-1, .12}

M := Matrix(nops(t)*nops(ts), 3); rr := 0; for Ce in t do for i2 in ts do C4 := eval(C3, [Ce = t, i2 = ts]); C44 := eval(C33, [Ce = t, i2 = ts]); s := Optimization:-Maximize(TRC(Pn, w), {C4, C44}, Pn = 0 .. 1, w = 0 .. 1, assume = nonnegative); stemp := s[1]; Pntemp := s[2][1]; wtemp := s[2][2]; rr := rr+1; M[rr, 1 .. 3] := `<|>`(Ce, i2, stemp) end do end do

R := Array(ArrayTools:-Reshape(M,[3,4,3]),datatype=float[8]):

func := Interpolation:-SplineInterpolation([[0.04, 0.08, 0.12],[0.03, 0.05, 0.07, 0.09]],R[..,..,3]):

conts := [seq(min(R[..,..,3])..max(R[..,..,3]),(max(R[..,..,3])-min(R[..,..,3]))/8)]:

ContoursWithLabels:= proc(

ContoursWithLabels(func(x, y), x = 0.3e-1 .. .15, y = 0.2e-1 .. .1, contours = conts, decplaces = 4, Coloring = [colorstyle = HUE, colorscheme = ["Blue", "Gold"], style = surface], TextOptions = [font = [HELVETICA, BOLD, 9], color = black], GraphicOptions = [thickness = 0], ImplicitplotOptions = [gridrefine = 3], size = [700, 600], labels = [':-C__e', ':-i__2'], size = [350, 350])

 

 

Download Q_Constraint_error_ac.mw

Here are two ways of doing it, each showing both the difference and the ratio, in side-by-side plots.

restart; with(plots): setoptions(size=[500,200],style=pointline,labels=[x,""]);


First way, calling dsolve just once, and using a procedure to set the parameter value. Calling the dsolve-return at each x-value in the
target Vector.
 

de := diff(f(x),x,x) = -sin(a*x):

dsol:=dsolve({de,f(0)=1,D(f)(0)=1},numeric,parameters=[a],output=listprocedure):
Y := eval(f(x),dsol):

F := proc(aa::numeric) dsol(parameters=[aa]); Y~(A); end proc:

A := Array([seq(0..3,0.1)],datatype=float[8]):

display(Array([
  plot(A, F(7.1)-F(7.0), title=y[7.1](x)-y[7.0](x)),
  plot(A, F(7.1)/~F(7.0), title=y[7.1](x)/y[7.0](x), color="Navy") ]));

 

 

restart; with(plots): setoptions(size=[500,200],style=pointline,labels=[x,""]);


Second way, calling dsolve for each parameter value, and specifying the output option to the target Array of x-points.
 

de := diff(f(x),x,x) = -sin(a*x):

G := aa -> dsolve(eval({de,f(0)=1,D(f)(0)=1},':-a'=aa),numeric,output=A)[2,1][..,2]:

A := Array([seq(0..3,0.1)],datatype=float[8]):

display(Array([
  plot(A, G(7.1)-G(7.0), title=y[7.1](x)-y[7.0](x)),
  plot(A, G(7.1)/~G(7.0), title=y[7.1](x)/y[7.0](x), color="Navy") ]));

 

 

Download de_V.mw


There are even more ways of accomplishing this. I don't know whether you'd rather focus on simplicity, or flexibility, or performance.

If you omit the stated conditions that TM1,TM2,TM3 are all positive then the shaded regions extend to the boundaries of the Pn=0..1,w=0..1 square.

restart

with(plots)

TM1 := (Pn-.35)*(3.000000000-3.333333333*Pn)+.1115859938-.2510684861*w

TM2 := (Pn-.348)*(2.996666666-3.333333333*Pn)+.1017286174-.2299240474*w

TM3 := (Pn-.348)*(2.996666666-3.333333333*Pn)+.1018208882-.2301325952*w

allpos:=TM1>0,TM2>0,TM3>0:
extra:=optionsimplicit=[gridrefine=4]:
rngs:=Pn=0..1,w=0..1:
display(
  inequal([ allpos, TM1>=TM2, TM1>=TM3 ],rngs,nolines,extra),
  inequal([ allpos, TM2>=TM1, TM2>=TM3 ],rngs,color=red,nolines,extra),
  inequal([ allpos, TM3>=TM1, TM3>=TM2 ],rngs,color=green,nolines,extra)
);


Download Plot_3D_to_2D_ac.mw

One of the important differences is that, while both a[1] and a__1 get printed/rendered with a subscript in 2D Output, the double-underscore a__1 name is wholly distinct and independent from a the base-name of a[1] the indexed name.

Yet there is a programmatic dependence of the name a[1] on the base name a.  In consequence, it is problematic to use both a[1] and bare a in a set of equations used with commands like solve, dsolve, etc.

It doesn't make much sense to form an equation or system of equations in which both a[1] and a are both present. Worse still, doing so can confuse the solvers and lead to wrong results.

But people often like having both the base name and some subscripted form appear in some 2D Math examples. For example, it's popular to use y(x) , diff(y(x),x), etc, as well as y__0 (with a subscripted rendering) as placeholder for the initial condition y(0). That's not sensible to do with y[0] instead of y__0.

nb. In Maple terminology, the name a__1 gets printed with a subscripted 2D Output form, but it is not an indexed name. The name a[1] is an indexed name. Both names get printed with a subscripted form.

Try executing the Document using !!! and, when the popup appears, add some expression (say, just x) and press OK so that the plot gets inserted.

And make "Markers" visible. By that I mean the left, thin, side-bar.

That execution may remedy the Markers which were previously muddled together.

Then you may see that the Marker for the problematic block has two parts, ie. the red line doesn't extend to its very top. On the upper, smaller part (without the red line, ie. just above the red line) you can try toggling the box from the right-click action,
   Document Block -> Show Command

Those steps revealed the inserted command, for me.

I think that using a procedure for handling M and Br values is more flexible than preforming a Matrix with a fixed spead of values for those variables.

The following is just one example of what you could do. Note that dsolve computation is only ever done once for any M,Br pair of values. Mere plot-data-transformations are all that's then needed once that computation is done.

There are several other ways to do it, including even faster approaches, or ones with the colors being  "blocked" instead of in a density-style of spread. I don't know what balance of simple vs flexible vs fast you'll want later.

restart;

with(plots):
with(plottools):

paramSet := [x = 0, H = 0.55, We = 0.05, Gr = 0.1, N[r] = 0.3, Nr = 0.2, Rr = 0.3,Nb = 0.1, Nt = 0.2, Qt = 0.2, Le = 0.1, delta = 0.3, E = 0.2,M = 0.2, Pe = 0.2, delta0 = 0.3, Da = 0.1, n = 1]:

sys := {
    diff(psi(y), y$4)*(1 - We*(diff(psi(y), y$2))^2)
    + diff(psi(y), y$3)*(-2*We*diff(psi(y), y$2)*diff(psi(y), y$3))
    - M^2*diff(psi(y), y$2) + Gr*(diff(theta(y), y) - N[r]*diff(phi(y), y) - Rr*diff(chi(y), y)) = 0,
    (1 + 4/(3*Nr))*diff(theta(y), y$2) + Br*(1 - We*(diff(psi(y), y$2))^2)*diff(psi(y), y$3)
    + Nb*diff(theta(y), y)*diff(phi(y), y)+ Nt*(diff(theta(y), y))^2 + Qt*theta(y) = 0,
    diff(phi(y), y$2) + (Nt/Nb)*diff(theta(y), y$2)- Le*Da*phi(y)*(1 + delta*theta(y))^n*exp(-E/(1 + delta*theta(y))) = 0,
    diff(chi(y), y$2) + Pe*(diff(chi(y), y)*diff(phi(y), y) + (chi(y) + delta0)*diff(phi(y), y$2)) = 0,
    # --- Boundary Conditions ---
    D(psi)(-1 - x^2/2) = 1, D(psi)(1 + x^2/2) = -k,
    psi(-1 - x^2/2) = 0, psi(1 + x^2/2) = 2*H,
    theta(-1 - x^2/2) = 0, theta(1 + x^2/2) = 1,
    phi(-1 - x^2/2) = 0, phi(1 + x^2/2) = 1,
    chi(-1 - x^2/2) = 0, chi(1 + x^2/2) = 1
}:

fixed_k := 0.1:

G := proc(mval,brval) local pars,dsol;
  pars := [M = mval, Br = brval, k = fixed_k, op(paramSet)];
  dsol := dsolve(eval(sys, pars), numeric, method = bvp[midrich],
                 maxmesh = 256, initmesh = 64, abserr = 1e-4);
  eval(-diff(theta(y), y), dsol(1));
end proc:

CP3D:=contourplot3d(G, 0.1..0.9, 0.1..0.9, filled,
                 contours=15, grid=[9,9],colorscheme = "turbo", colorbar):

SP3D:=display(CP3D,overrideoptions,style=surface):

CP3Dblack:=display(CP3D,overrideoptions,color=black,thickness=2):

P3Dboth:=display(SP3D,CP3Dblack):

display(P3Dboth, transform((x,y,z)->[x,y,-0.53])(P3Dboth),
        labels = ["M", "Br", "Nu"],
        labelfont = [TIMES, BOLDITALIC, 16],
        title = typeset("Nusselt Number vs M and Br (k = ", fixed_k, ")"),
        titlefont = [TIMES, BOLD, 18], projection = 0.8,
        orientation=[10,75,0], lightmodel = light4);

 

 

Download 3D_shadow_at_the_base_Help_ac.mw

I think that it it helpful to have more direct visual cues as to which vertical axis pertains to each curve.

I like to do that with color, so, below, the curves are in various shades of the two vertical axes' base colors. (Another way is to use various symbols, with point style, and colors that match the axes.)

The result is that, mentally, one only has to associate rendered curve's color with the nearby axis colors. But in your original scheme one has to mentally go from the curve color to the legend, then know/recall that the legend name's subscript relates to one of the two vertical axis labels, and then find which is that label by reading. Relatively, IMO, that was considerably more effort.

Also, this lets us make a visual association between matching superscripts (ie, W,S, or D), since each pair of curves that share a superscript can also be made to share a common brightness (or point symbol). The two brightest curves are the "W" expressions, and the darkest are the "S" expressions.

I've used Maple 2019, as the OP does.

restart

`&Pi;_12` := (0.1455251030e-2*Ce+.5352049476)*(0.369876310e-1-0.3638127575e-2*Ce)+(.8*(-.1671790360+1.121361872*Ce))*(0.1849381518e-1-0.1819063782e-2*Ce)-Ce*(0.1849381518e-1-0.1819063782e-2*Ce)

`&Pi;_22` := (0.1455251030e-2*Ce+.5356096675)*(0.355258312e-1-0.3638127575e-2*Ce)+(.8*(-.1184158360+1.121361872*Ce))*(0.1776291535e-1-0.1819063782e-2*Ce)-Ce*(0.1776291535e-1-0.1819063782e-2*Ce)

`&Pi;_32` := (0.1455251030e-2*Ce+.5356038465)*(0.355403838e-1-0.3638127575e-2*Ce)+(.8*(-.1179012835+1.121361872*Ce))*(0.1777019161e-1-0.1819063782e-2*Ce)-Ce*(0.1777019161e-1-0.1819063782e-2*Ce)

G1 := plot([`&Pi;_12`, `&Pi;_22`, `&Pi;_32`], Ce = 0 .. 0.9e-1, color = ["#FF0000", "#C00000", "#700000"], labels = [typeset(Typesetting:-mo("Ce", mathvariant = "bold"), "\n"), typeset(Typesetting:-mo("Manufacturer Profit", mathvariant = "bold", mathcolor = "black"), "\n")], labeldirections = ["horizontal", "vertical"], legend = [`#msubsup(mi("Pi"),mi("m"),mn("W"));`, `#msubsup(mi("Pi"),mi("m"),mn("D"));`, `#msubsup(mi("Pi"),mi("m"),mn("S"));`], axis[2] = [color = "#600000"])

`&Pi;_1` := (-0.60726413e-1*Ce+.6173851967)*(0.1849381518e-1-0.1819063782e-2*Ce)-0.2500000000e-1*(0.1849381518e-1-0.1819063782e-2*Ce)^2

`&Pi;_2` := (-0.60726413e-1*Ce+.5929853242)*(0.1776291535e-1-0.1819063782e-2*Ce)-0.2500000000e-1*(0.1776291535e-1-0.1819063782e-2*Ce)^2

`&Pi;_3` := (-0.60726413e-1*Ce+.5932282299)*(0.1777019161e-1-0.1819063782e-2*Ce)-0.2500000000e-1*(0.1777019161e-1-0.1819063782e-2*Ce)^2

G2 := plot([`&Pi;_1`, `&Pi;_2`, `&Pi;_3`], Ce = 0 .. 0.9e-1, color = ["#00FF00", "#00BC00", "#008000"], labels = [typeset(Typesetting:-mo("Ce", mathvariant = "bold"), "\n"), typeset("\n", Typesetting:-mo("Retailer profit", mathvariant = "bold", mathcolor = "black"))], labeldirections = ["horizontal", "vertical"], legend = [`#msubsup(mi("Pi"),mi("r"),mn("W"));`, `#msubsup(mi("Pi"),mi("r"),mn("D"));`, `#msubsup(mi("Pi"),mi("r"),mn("S"));`], axis[2] = [color = "#006000"])

plots:-dualaxisplot(G1, G2, size = [700, 500])

 

 

Download All_plots_Combined_ac.mw

Student:-Calculus1:-InversePlot is an appliable module.

That means that when you call it with arguments (as a function call) Maple actually invokes the following procedure,

   Student:-Calculus1:-InversePlot:-ModuleApply

You can get the nicely printed rendering of that entry-point with,

restart;
kernelopts(opaquemodules=false):
eval(Student:-Calculus1:-InversePlot:-ModuleApply);

Or you can get the line-numbered display with,

showstat(Student:-Calculus1:-InversePlot);

Note that in 2D Input mode (only) the input that looks like,

     mX(m, isumSD_TOT) := isumSD_REG;

may get parsed as code to construct an operator (procedure) of two parameters.

But you obviously want to do Matrix indexing, instead. And you have chosen to use the round brackets for Matrix indexing.

I can't tell which version of Maple you're using (because you didn't mark this Question with a specific version, and you haven't provided your actual worksheet). But you appear to have encountered a 2D Input syntax clash, and are not getting the interpretation that you want.

I was able to reproduce it a few times in Maple 2022.2. Not every time, but enough to confirm it can happen there.

So you could either use 1D plaintext Maple notation for the problematic input line, or you could use the square bracket notation for Matrix indexing, ie.,

   mX[m, isumSD_TOT] := isumSD_REG;

The documentation of the Help page with topic overload explains that the mechanism attempts the procedures in order, and that it proceeds to the next only if an error exception prefixed by "invalid input" were raised by the attempt.

Note also that such an exception is raised for a procedure only if the "missing" argument corresponds to a parameter that is actually referenced in the procedure. Note the following distinction:

restart;

 

f1 := proc(a, b);
  return "finished";
end proc:

 

f1( s );

"finished"

f2 := proc(a, b);
  b; # the second parameter is referenced
  return "finished";
end proc:

 

f2( s );

Error, invalid input: f2 uses a 2nd argument, b, which is missing


Download proc_ref.mw

The above distinction is clearly documented (by explanation in first bullet point, and also by the examples) in the "Required Positional Parameters" section of the Help page with topic parameter_classes.

And now we can see that, if such a error exception were raised in your first example pair, then the overload mechanism would proceed to the next proc.

restart;

set_name :=overload(
        [     
            proc(first_name::string,last_name::string,$) option overload;
                last_name; # reference the second parameter
                print("in proc which takes two arguments");
            end,
       
            proc(the_name::string,$) option overload;
                 print("in proc which takes one argument");
            end          
        ]
    ):

set_name("me");

"in proc which takes one argument"

set_name("me","joe");

"in proc which takes two arguments"


Download nm_overload_ex_ref.mw

Was the file already there? If it wasn't, then you've likely got the wrong location. It's the existing user GUI-preferences file that you're editing, and it should contain a lot of other GUI options stuff.

Also, is it named, say,
    "//Users/$USER/Library/Preferences/Maple/2025/Maple preferences"
with a number like 2025?

(It wouldn't hurt to also put your userid in, rather than $USER, though it ought to resolve in a shell. You might also do it with, ~/Library/Preferences/ ...)

Of course, if you already found right the existing file (with its contents) then the location aspect is not the issue. The edited line ought to start like the other lines, eg. no tab at left.

Also, did you fully quit all Maple GUI instances before both editing that file as well as relaunching?

It is correct.

That squared term comes from the expanding of,
    cos(2*k*x)
to,
    2*cos(k*x)^2 - 1


Note that Maple's expand command by default will expand as much as it can here. That includes not only expanding the form cos(A+B) but also resulting terms like cos(2*C) and sin(2*C).

Let's go through the whole thing, in a few separate steps.

restart;

expand( cos(u*x-2*k*x) );

2*cos(u*x)*cos(k*x)^2-cos(u*x)+2*sin(u*x)*sin(k*x)*cos(k*x)


Let's expand only the difference, like the form cos(A+B).

There are several ways to do just that.

frontend( expand, [cos(u*x - 2*k*x)],
          [{specfunc(cos),`+`},{}] );

cos(2*k*x)*cos(-u*x)-sin(2*k*x)*sin(-u*x)

subs( [A=u*x,B=-2*k*x], expand( cos(A + B) ) );

cos(u*x)*cos(-2*k*x)-sin(u*x)*sin(-2*k*x)

trigsubs(cos(u*x - 2*k*x), trigidentity="Sum Expansion")[];

cos(2*k*x)*cos(-u*x)-sin(2*k*x)*sin(-u*x)


Evaluation (prevented in each of those three ways) alters
the negative signs inside those sin&cos terms.

temp := eval(%);

cos(2*k*x)*cos(u*x)+sin(2*k*x)*sin(u*x)

And now the sin(2*k*x) and cos(2*k*x) terms can
also be expanded.

Let's review the formula that Maple uses for those:

expand( cos(2*k*x) )

2*cos(k*x)^2-1

expand( sin(2*k*x) );

2*sin(k*x)*cos(k*x)


Substituting those into the earlier result  -- of just the single-step
expansion of the A+B form -- leads to the final result.

eval( temp, [cos(2*k*x)=expand(cos(2*k*x)),
             sin(2*k*x)=expand(sin(2*k*x))] );

(2*cos(k*x)^2-1)*cos(u*x)+2*sin(u*x)*sin(k*x)*cos(k*x)

normal(%);

2*cos(u*x)*cos(k*x)^2-cos(u*x)+2*sin(u*x)*sin(k*x)*cos(k*x)

Download trig_exp_ex.mw

It occurs to me that you might not have considered that replacement of cos(2*k*x) as a kind of expansion. (And apologies if you were already fully aware of this aspect.) You can take 2*k*x as being equivalent to k*x + k*x, and so consider it like expanding cos(k*x + k*x).

expand( cos( F + G ) );

cos(F)*cos(G)-sin(F)*sin(G)

eval( %, [F=k*x, G=k*x] );

cos(k*x)^2-sin(k*x)^2

eval( %, sin(k*x)^2 = 1 - cos(k*x)^2 );

2*cos(k*x)^2-1

Yes, see number 2 example compared to number 1; A reportable weakness.

restart;

kernelopts(version);

`Maple 2024.2, X86 64 LINUX, Oct 29 2024, Build ID 1872373`

expr := sqrt((-alpha^2*x^2 + R^2 + x^2)/(-alpha^2*x^2 + R^2))/sqrt(R^4/((-alpha^2*x^2 + R^2 + x^2)^2*(-alpha^2*x^2 + R^2)));

((-alpha^2*x^2+R^2+x^2)/(-alpha^2*x^2+R^2))^(1/2)/(R^4/((-alpha^2*x^2+R^2+x^2)^2*(-alpha^2*x^2+R^2)))^(1/2)

simplify(expr) assuming real, R^2+(1-alpha^2)*x^2>0;

(-alpha^2*x^2+R^2+x^2)^(3/2)/R^2

simplify(expr) assuming R^2>-(1-alpha^2)*x^2; # number 1

(-alpha^2*x^2+R^2+x^2)^(3/2)/abs(R)^2

simplify(expr) assuming R^2+(1-alpha^2)*x^2>0; # number 2

(-alpha^2*x^2+R^2+x^2)^(3/2)*(1/(-alpha^2*x^2+R^2))^(1/2)/(R^4/(-alpha^2*x^2+R^2))^(1/2)

Download simplify_real_ex0.mw

ps. I don't like the approach of placing assumptions on all indets of type `+`; it's rather ad hoc, presuming that those are all real without stating them explicitly, etc. It's not stronger than this (weak, IMO) approach:

simplify(expr, symbolic);

(-alpha^2*x^2+R^2+x^2)^(3/2)/R^2

Download simplify_real_ex1.mw

Note the following, which does not need x>=0 to be a given assumption. Looking at the expression, it seems reasonable to me:

simplify(expr) assuming R^2+(1-alpha^2)*x^2>0, R::real

(-alpha^2*x^2+R^2+x^2)^(3/2)/R^2

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