## 13728 Reputation

11 years, 147 days

## "By eye"...

@Wavish  Since you do not have a clear criterion for obtaining the wished line, then the solution "by eye" is likely to be the easiest and best solution to the problem.

## unapply...

An example of the creation of a specific matrix function:

F:=unapply(<t, t^2; sin(t), cos(t)>, t):
F(2);

## Formal symbolic result...

@vv  In fact, as a formal symbolic result, we get the same thing. But if we try to assign some numeric constants to the symbols, then of course we get an error:

```Ec := (Ems+I*Eml)*(1+((Ems+I*Eml)/Ef-1)*Zeta*phi/((Ems+I*Eml)/Ef+Zeta))/(1-((Ems+I*Eml)/Ef-1)*phi/((Ems+I*Eml)/Ef+Zeta)):
a:=simplify(Re(Ec)) assuming positive;
b:=simplify(Im(Ec)) assuming positive;
EC:=eval(Ec,Zeta=ZETA):
simplify(evalc([Re,Im](EC)));
eval(%, ZETA=Zeta);
is(a=%[1] and b=%[2]);
Zeta:=1;
```

## Screenshot and text...

@bsoudmand  This is the output of my code (in Maple 2018.2):

In the text form:

a:=(-Ems*Zeta*(Ef^2-2*Ef*Ems+Eml^2+Ems^2)*phi^2+((Zeta-1)*Ems^3+Ef*(Zeta-1)^2*Ems^2-(Zeta-1)*(Ef^2*Zeta-Eml^2)*Ems-Ef*Eml^2*(Zeta+1)^2)*phi+Ems*(Ef^2*Zeta^2+2*Ef*Ems*Zeta+Eml^2+Ems^2))/((Ef^2-2*Ef*Ems+Eml^2+Ems^2)*phi^2+(-2*Ems^2-2*Ef*(Zeta-1)*Ems+2*Ef^2*Zeta-2*Eml^2)*phi+Ef^2*Zeta^2+2*Ef*Ems*Zeta+Eml^2+Ems^2);

b:=-Eml*(Zeta*(Ef^2-2*Ef*Ems+Eml^2+Ems^2)*phi^2+(Ef*(Ef-2*Ems)*Zeta^2+(-Ef^2-Eml^2-Ems^2)*Zeta-2*Ef*Ems+Eml^2+Ems^2)*phi-Ef^2*Zeta^2-2*Ef*Ems*Zeta-Eml^2-Ems^2)/((Ef^2-2*Ef*Ems+Eml^2+Ems^2)*phi^2+(2*Ef*(-Ems+Ef)*Zeta+2*Ef*Ems-2*Eml^2-2*Ems^2)*phi+Ef^2*Zeta^2+2*Ef*Ems*Zeta+Eml^2+Ems^2);

## 3 examples...

SymFun(ln((x-1)/(x+1)), x);
plot(ln((x-1)/(x+1)), x=-4..4, -4..4);

SymFun(sqrt(x^2), x);
plot(sqrt(x^2), x=-2..2);

SymFun(abs(x)^(1/2), x);
plot(abs(x)^(1/2), x=-1..1);

## makeproc...

@emendes  You can use  makeproc  option. See help on  rsolve  command for this.

## Re...

@Lali_miani  If you enter in 2d math mode any of  i, j, I  from the Comman Symbols palette, it will work as the imaginary unit. But from the keyboard you have to enter the imaginary unit as  I . I almost never use palettes and only work from the keyboard in 1d math mode (Maple input).

## plots:-arrow, plots:-textplot...

@minhthien2016  You can make arrows at the ends of the axes of coordinates and labels in the same place if you use  plots:-arrow  and  plots:-textplot  commands.

Example:

```Arrow_x:=plots:-arrow([2.3,0],[0.15,0], width=0, head_width=0.12, head_length=0.15):
Labels:=plots:-textplot([[2.4,-0.2,"x"],[-0.2,4.4,"y"]], font=[times,16]):
P:=plot(x^2, x=-2..2, color=red, thickness=2, labels=["",""]):
plots:-display(Arrow_x,Arrow_y,P,Labels);

```

Output:

Edit.

convert(Q, exp);

## DirectSearch...

@EB1000 The  DirectSearch  package is not included in Maple and must be downloaded from the Maple Application Center from  here

## Nice...

@tomleslie  Thanks for this. In my opinion it is the best solution.

## Re...

@radaar  I did not understand the meaning of what you posted. But in general, I think that using loops is more efficient, but you need to increas  Digits  (for example take Digits:=15)  to compensate for the loss of accuracy.

## Double add vs double for-loop...

@radaar Note that double  add  requires more time and memory, but the calculation itself is more accurate. In order to achieve the same accuracy with double  for-loop  you have to increase  Digits , but then both time and memory will increase. You need to check it all out.

## Comparison...

@mmcdara  I do not think your solution is shorter. You have written a special procedure for this, which uses a number of commands from  Statistics  package. I simply use  Composition  procedure, written several years ago and not directly related to this problem. The solution itself takes 1 line of the code and is about 50 times faster (see below):

 > restart;
 > P := proc(NbOfDice)  local S, R:  uses Statistics:  S := add(RandomVariable(DiscreteUniform(1, 6)), k=1..NbOfDice):  R := [\$NbOfDice..6*NbOfDice]:  return  R =~ Probability~(S =~ R) end proc:
 > t:=time[real](); P(3); time[real]()-t;
 (1)
 > Composition := proc (n::nonnegint, k::posint, res::{range, nonnegint} := 0) local a, b, It, L0; if res::nonnegint then a := res; b := n-(k-1)*a  else a := lhs(res); b := rhs(res) fi; if b < a or b*k < n then return `No solutions` fi; It := proc (L) local m, j, P, R, i, N; m := nops(L[1]); j := k-m; N := 0; for i to nops(L) do R := n-`+`(op(L[i])); if R <= b*j and a*j <= R then N := N+1; P[N] := [seq([op(L[i]), s], s = max(a, R-b*(j-1)) .. min(R, b))] fi; od; [seq(op(P[s]), s = 1 .. N)]; end proc; L0 := [[]]; (It@@k)(L0); end proc:
 > t:=time[real](); n:=3: [seq([S,nops(Composition(S,n,1..6))/6^n], S=n..6*n)]; time[real]()-t;
 (2)
 >