Kitonum

21530 Reputation

26 Badges

17 years, 91 days

MaplePrimes Activity


These are replies submitted by Kitonum

@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;

1452.203

 

[3 = 1/216, 4 = 1/72, 5 = 1/36, 6 = 5/108, 7 = 5/72, 8 = 7/72, 9 = 25/216, 10 = 1/8, 11 = 1/8, 12 = 25/216, 13 = 7/72, 14 = 5/72, 15 = 5/108, 16 = 1/36, 17 = 1/72, 18 = 1/216]

 

2.156

(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;

1458.044

 

[[3, 1/216], [4, 1/72], [5, 1/36], [6, 5/108], [7, 5/72], [8, 7/72], [9, 25/216], [10, 1/8], [11, 1/8], [12, 25/216], [13, 7/72], [14, 5/72], [15, 5/108], [16, 1/36], [17, 1/72], [18, 1/216]]

 

0.41e-1

(2)

 


 

Download SumOfDice_new.mw

@torabi  You have already been offered to use  DirectSearch  package. It is not part of Maple and must be downloaded from Maple Application Center from  here

@mehran rajabi 
Replace the line

Sys:={seq(u[k]=1+add((x[k]*x[i-1]*u[i-1]+x[k]*x[i]*u[i])/2*h, i=1..N), k=1..N)}:

with the lines

f:=i->x[k]*x[i]*u[i]:
Sys1:={seq(u[k]=1+h/3*(f(0)+4*add(f(2*i-1), i=1..N/2)+2*add(f(2*i-2),i=2..N/2)+f(N)), k=1..N)}:

 

 

Thank you all for the answers. Apparently there is no simple solution and it is easier to simply record this expansion handly.

@ecterrab  But this is not an automatic solution. In fact, you manually wrote an expansion, which I hoped to get from Maple.

@nm  Unfortunately, I was not able to verify by differentiating the result in my answer above for an arbitrary  n  and get  sin(x)^n . However, the correctness of this result is beyond doubt. Here is a simple check for 100 values of  n :

restart;
R:=int(sin(x)^n, x) assuming n::posint;
seq(is(value(eval(R, n=k))=int(sin(x)^k, x)), k=1..100);

    

@minhthien2016  
simplify((1/2)*ln(1+tan(x)^2))  assuming cos(x)>0;
                             
  -ln(cos(x))

@minhthien2016 

restart; 
int(sin(x)^n, x) assuming n::posint:
eval(%, n = 7); 
expand(simplify(value(%)));
algsubs(cos(x)^2=1-sin(x)^2, %);
factor(%);

 

@student_md 
Tm2 is present in your new code, but it is not defined. From your previous version it seems that  Tm2  is the same as Tm. Correct this.

The first error in your code occurs in the following line:

coz:=fsolve(sys);
indets(sys, name);

Error, (in fsolve) number of equations, 16, does not match number of variables, 21
{P_nn3, c[1, 1], c[1, 2], c[1, 3], c[1, 4], c[2, 1], c[2, 2],  c[2, 3], c[2, 4], c[3, 1], c[3, 2], c[3, 3], c[3, 4], [4, 1],  c[4, 2], c[4, 3], c[4, 4], t[1], t[2], t[3], t[4]}
 

 

@Jalale  See the corrected file:

QuestionSimulation_new1.mw 

@gaurav_rs  Maple often does not take into account restrictions on variables imposed by  assume  command.

An example:

assume(x>Pi/2, x<Pi):
solve(sin(x)=1/2);
           
 Warning, solve may be ignoring assumptions on the input variables.
                              1   
                              - Pi
                              6   
 

@Magma  See help on  ?remember . There everything is explained in detail with examples.

@vv   ``( ... )  construction prevents the automatic opening of the parentheses.

@mehdi jafari   Probably no.

@digerdiga 

f:=ln((1-x)^2*(x+1)^2/((-I*x-I+sqrt(-x^2+1))^2*(I*x+I+sqrt(-x^2+1))^2))*ln((1-x)^2*(x+1)^2/((-I*x-I+sqrt(-x^2+1))^2*(I*x+I+sqrt(-x^2+1))^2))*ln((1-x)^2*(x+1)^2/((-I*x-I+sqrt(-x^2+1))^2*(I*x+I+sqrt(-x^2+1))^2))*ln((1-x)^2*(x+1)^2/((-I*x-I+sqrt(-x^2+1))^2*(I*x+I+sqrt(-x^2+1))^2)) + ln((1-x)^2*(x+1)^2/((-I*x-I+sqrt(-x^2+1))^2*(I*x+I+sqrt(-x^2+1))^2))*ln((1-x)^2*(x+1)^2/((-I*x-I+sqrt(-x^2+1))^2*(I*x+I+sqrt(-x^2+1))^2)) + ln((1-x)^2*(x+1)^2/((-I*x-I+sqrt(-x^2+1))^2*(I*x+I+sqrt(-x^2+1))^2)) + ln((1-x)^2*(x+1)^2/((-I*x-I+sqrt(-x^2+1))^2*(I*x+I+sqrt(-x^2+1))^2))*ln((1-x)^2*(x+1)^2/((-I*x-I+sqrt(-x^2+1))^2*(I*x+I+sqrt(-x^2+1))^2));
subsindets(f, `function`, p->applyop(t->numer(t)/expand(denom(t)),1, p));
simplify(%);
expand(%);

First 36 37 38 39 40 41 42 Last Page 38 of 133