Kitonum

21550 Reputation

26 Badges

17 years, 124 days

MaplePrimes Activity


These are answers submitted by Kitonum

Just use the  convert(x, float)  command or  evalf  command  for the finish result.

Use  CodeTools:-Usage  command for this. For ease of comparison, I increased the size of the array:
 

restart; FF := proc (xx::Array, nn::integer) local gg, i, j; gg := 0; for i by 3 to nn do for j from i+3 by 3 to nn do gg := gg+evalf(1/((xx[i]-xx[j])^2+(xx[i+1]-xx[j+1])^2+(xx[i+2]-xx[j+2])^2)) end do end do; return gg end proc; CodeTools:-Usage(FF(Array(1 .. 9999, [seq(i^2, i = 1 .. 9999)]), 9999))

memory used=1.75GiB, alloc change=8.00MiB, cpu time=22.66s, real time=22.12s, gc time=1.72s

 

0.1661350362e-2

(1)

NULL

restart; FF := proc (xx::Array, nn::integer) local gg, i, j; gg := add(add(1/((xx[i]-xx[j])^2+(xx[i+1]-xx[j+1])^2+(xx[i+2]-xx[j+2])^2), j = i+3 .. nn, 3), i = 1 .. nn, 3); return gg end proc; XX := Array(1 .. 9999, [seq(i^2, i = 1 .. 9999)]); CodeTools:-Usage(evalf(FF(XX, 9999)))

memory used=58.28GiB, alloc change=59.49MiB, cpu time=2.65m, real time=2.43m, gc time=71.55s

 

0.1661398690e-2

(2)

``

``


 

Download procedure_new1.mw

I think the problem can be solved in different ways. Below is an example of visualization of coin tosses. CoinToss procedure returns the result of N coin tosses in the form of a list of coordinates of the vertices of the broken line. Each segment up means the fall of one side of a coin, down - the other one. As an example, a simulation of 20 tosses of 2 independent coins is given. Animation of this is also shown.


 

restart;
CoinToss:=proc(N::posint,h:=0)
local S, r, n, t;
S[0]:=[0,h];
r:=rand(0..1);
for n from 1 to N do
t:=r();
S[n]:=[n,S[n-1][2]+(-1)^t];
od;
convert(S, list);
end proc:

A:=CoinToss(20,0.1);
B:=CoinToss(20);

[[0, .1], [1, 1.1], [2, 2.1], [3, 3.1], [4, 2.1], [5, 3.1], [6, 2.1], [7, 1.1], [8, .1], [9, 1.1], [10, .1], [11, -.9], [12, -1.9], [13, -.9], [14, .1], [15, -.9], [16, .1], [17, -.9], [18, .1], [19, -.9], [20, .1]]

 

[[0, 0], [1, -1], [2, -2], [3, -3], [4, -4], [5, -3], [6, -2], [7, -1], [8, -2], [9, -1], [10, -2], [11, -1], [12, -2], [13, -3], [14, -2], [15, -1], [16, -2], [17, -3], [18, -4], [19, -5], [20, -4]]

(1)

F:=n->plot([A[1..n+1],B[1..n+1]],color=[red,blue], scaling=constrained, thickness=3, size=[1000,400], legend=["1st coin","2nd coin"]);
F(20);

proc (n) options operator, arrow; plot([A[1 .. n+1], B[1 .. n+1]], color = [red, blue], scaling = constrained, thickness = 3, size = [1000, 400], legend = ["1st coin", "2nd coin"]) end proc

 

 

plots:-animate(plots:-display,['F'(round(k))], k=0..20, frames=100, size=[1000,400], scaling=constrained);

 

 

 


 

Download CoinToss.mw

 

I think that it will be interesting for you to get the law of distribution of the number of points when throwing  n dices. In other words, it is necessary to find the probability that when throwing  n dice the sum of points will be equal to  S  for any possible S . For this we can use the procedure  Composition . Details on the use of this procedure can be found here.

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:


Example of use - find all the ways to get a total of 12 points when throwing 3 dice:

Composition(12, 3, 1..6);
nops(%);      

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

In the example below we obtain the law of distribution of the amount of points when rolling 4 dice :

n:=4:
# Probabilities
P:=[seq([S,nops(Composition(S,n,1..6))/6^n], S=n..6*n)];
# Check
add(P[k,2], k=1..nops(P));

     
            

Edit.

      

Your integral equation has the exact solution  u(x)=1+3/4*x . The solution using the trapezoid rule for  N=100  gives a pretty good approximation:


 

restart;
Eq:=u(x) = 1+int(x*t*u(t), t = 0 .. 1);
u:=x->1+3/4*x;
Eq;  # Check of exact solution

u(x) = 1+int(x*t*u(t), t = 0 .. 1)

 

proc (x) options operator, arrow; 1+(3/4)*x end proc

 

1+(3/4)*x = 1+(3/4)*x

(1)

restart;
N:=100:
u[0]:=1.:
X:=[seq(1/N*k, k=1..N)]:
x[0]:=0.:
assign(seq(x[i]=X[i], i=1..N)):
h:=1/N:
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)}:

Sol:=solve(Sys);

{u[1] = 1.007500188, u[2] = 1.015000375, u[3] = 1.022500563, u[4] = 1.030000750, u[5] = 1.037500938, u[6] = 1.045001125, u[7] = 1.052501313, u[8] = 1.060001500, u[9] = 1.067501688, u[10] = 1.075001875, u[11] = 1.082502063, u[12] = 1.090002250, u[13] = 1.097502438, u[14] = 1.105002625, u[15] = 1.112502813, u[16] = 1.120003000, u[17] = 1.127503188, u[18] = 1.135003375, u[19] = 1.142503563, u[20] = 1.150003750, u[21] = 1.157503938, u[22] = 1.165004125, u[23] = 1.172504313, u[24] = 1.180004500, u[25] = 1.187504688, u[26] = 1.195004875, u[27] = 1.202505063, u[28] = 1.210005250, u[29] = 1.217505438, u[30] = 1.225005625, u[31] = 1.232505813, u[32] = 1.240006000, u[33] = 1.247506188, u[34] = 1.255006375, u[35] = 1.262506563, u[36] = 1.270006750, u[37] = 1.277506938, u[38] = 1.285007125, u[39] = 1.292507313, u[40] = 1.300007500, u[41] = 1.307507688, u[42] = 1.315007875, u[43] = 1.322508063, u[44] = 1.330008250, u[45] = 1.337508438, u[46] = 1.345008625, u[47] = 1.352508813, u[48] = 1.360009000, u[49] = 1.367509188, u[50] = 1.375009375, u[51] = 1.382509563, u[52] = 1.390009750, u[53] = 1.397509938, u[54] = 1.405010125, u[55] = 1.412510313, u[56] = 1.420010500, u[57] = 1.427510688, u[58] = 1.435010875, u[59] = 1.442511063, u[60] = 1.450011250, u[61] = 1.457511438, u[62] = 1.465011625, u[63] = 1.472511813, u[64] = 1.480012000, u[65] = 1.487512188, u[66] = 1.495012375, u[67] = 1.502512563, u[68] = 1.510012750, u[69] = 1.517512938, u[70] = 1.525013125, u[71] = 1.532513313, u[72] = 1.540013500, u[73] = 1.547513688, u[74] = 1.555013875, u[75] = 1.562514063, u[76] = 1.570014250, u[77] = 1.577514438, u[78] = 1.585014625, u[79] = 1.592514813, u[80] = 1.600015000, u[81] = 1.607515188, u[82] = 1.615015375, u[83] = 1.622515563, u[84] = 1.630015750, u[85] = 1.637515938, u[86] = 1.645016125, u[87] = 1.652516313, u[88] = 1.660016500, u[89] = 1.667516688, u[90] = 1.675016875, u[91] = 1.682517063, u[92] = 1.690017250, u[93] = 1.697517438, u[94] = 1.705017625, u[95] = 1.712517813, u[96] = 1.720018000, u[97] = 1.727518188, u[98] = 1.735018375, u[99] = 1.742518563, u[100] = 1.750018750}

(2)

Y:=map(rhs, convert(Sol,list));

[1.007500188, 1.015000375, 1.022500563, 1.030000750, 1.037500938, 1.045001125, 1.052501313, 1.060001500, 1.067501688, 1.075001875, 1.082502063, 1.090002250, 1.097502438, 1.105002625, 1.112502813, 1.120003000, 1.127503188, 1.135003375, 1.142503563, 1.150003750, 1.157503938, 1.165004125, 1.172504313, 1.180004500, 1.187504688, 1.195004875, 1.202505063, 1.210005250, 1.217505438, 1.225005625, 1.232505813, 1.240006000, 1.247506188, 1.255006375, 1.262506563, 1.270006750, 1.277506938, 1.285007125, 1.292507313, 1.300007500, 1.307507688, 1.315007875, 1.322508063, 1.330008250, 1.337508438, 1.345008625, 1.352508813, 1.360009000, 1.367509188, 1.375009375, 1.382509563, 1.390009750, 1.397509938, 1.405010125, 1.412510313, 1.420010500, 1.427510688, 1.435010875, 1.442511063, 1.450011250, 1.457511438, 1.465011625, 1.472511813, 1.480012000, 1.487512188, 1.495012375, 1.502512563, 1.510012750, 1.517512938, 1.525013125, 1.532513313, 1.540013500, 1.547513688, 1.555013875, 1.562514063, 1.570014250, 1.577514438, 1.585014625, 1.592514813, 1.600015000, 1.607515188, 1.615015375, 1.622515563, 1.630015750, 1.637515938, 1.645016125, 1.652516313, 1.660016500, 1.667516688, 1.675016875, 1.682517063, 1.690017250, 1.697517438, 1.705017625, 1.712517813, 1.720018000, 1.727518188, 1.735018375, 1.742518563, 1.750018750]

(3)

plot([0,X[]],Y, view=[0..1,0..2], scaling=constrained);

 

 


 

Download IntEq.mw

I did not find a way to increase the size of this font inside Maple. As a workaround, you can use a Windows screen magnifier or just wear glasses. See the screenshot:

If you have specific points, you can use  geom3d  package.

Example:

restart;
with(geom3d):
point(P, 5, 6, 7);
point(A, 1, -2, 3);
point(B, 2, 4, 1);
line(AB, [A,B]);
projection(Q, P, AB);
detail(Q);
                               

 

 

A:=isolve(n+k=2*c);
is(A<>NULL and eval(n, A)::name);
                          
A := {c = _Z1, k = 2*_Z1-_Z2, n = _Z2}
                                                       true

Above  _Z1  and  _Z2  are any integers.

You can use  PolyhedralSets  package to get the vertices and edges of your polygon. This also works in the multidimensional case.

Your example (failed to load the contents of the file, so the image is shown, the link to the file below):


You can extract all vertices in one list with  Relations  command:
V:=Vertices(ps):
Relations~(V);
map(v->eval([x,y],v), %);
               
  [[y = -1, x = -1], [y = 1, x = -1], [y = -1, x = 1], [y = 1, x = 1]]
                                       [[-1, -1], [-1, 1], [1, -1], [1, 1]]

The same for edges.

 

Download PS.mw


 

 

Use  factors  command for this:

f:=x*(x+1)^4*(x^2+x+1)*(x^3+x^2+1)^5:
factors(f);
map(t->op(1,t), %[2]);
sort(%);
                         

 

I usually use  is  command for such checks:

is(2*cos(phi)^2-1=cos(2*phi));
                                                             
true


And more often I look  here , if I don’t know any rare identity.


Edit.

Maple 2018.2 returns the result in the form of finite sums and products (without hypergeometric functions):

restart;
int(sin(x)^n, x) assuming n::posint;
eval(%, n=10);
value(%);
int(sin(x)^10, x); # The direct calculation

      

restart;
Ke := Matrix(4, 4, {(1, 1) = (12*I)*E/l^3, (1, 2) = (6*I)*E/l^2, (1, 3) = -(12*I)*E/l^3, (1, 4) = (6*I)*E/l^2, (2, 1) = (6*I)*E/l^2, (2, 2) = (4*I)*E/l, (2, 3) = -(6*I)*E/l^2, (2, 4) = (2*I)*E/l, (3, 1) = -(12*I)*E/l^3, (3, 2) = -(6*I)*E/l^2, (3, 3) = (12*I)*E/l^3, (3, 4) = -(6*I)*E/l^2, (4, 1) = (6*I)*E/l^2, (4, 2) = (2*I)*E/l, (4, 3) = -(6*I)*E/l^2, (4, 4) = (4*I)*E/l}):
k:=E*I/l^3:
``(k).(Ke/k);

                        

 

You can take any initial value (also any range) for the parameter yourself.
Example:

restart;
plots:-animate(plot, [m*x, x=-10..10, -10..10], m=1..5, frames=100);

Here is a simple procedure for this and an example:

Code of the procedure

P:=proc(A::Matrix, B::Matrix)
local m1,n1,n2;
m1:=op([1,1],A);
n1:=op([1,2],A);
n2:=op([1,2],B);
Matrix(m1,n2, (i,j)->add(A[i,p].B[p,j], p=1..n1));
end proc:


Example

A:=Matrix(2,3,{seq(seq((i,j)=LinearAlgebra:-RandomVector(2,generator=-9..9), i=1..2),j=1..3)});
B:=Matrix(3,2,{seq(seq((i,j)=LinearAlgebra:-RandomVector(2,generator=-9..9), i=1..3),j=1..2)});

Matrix(2, 3, {(1, 1) = Vector(2, {(1) = 2, (2) = -9}), (1, 2) = Vector(2, {(1) = 3, (2) = 1}), (1, 3) = Vector(2, {(1) = -9, (2) = -7}), (2, 1) = Vector(2, {(1) = 3, (2) = 6}), (2, 2) = Vector(2, {(1) = -8, (2) = -8}), (2, 3) = Vector(2, {(1) = 0, (2) = -3})})

 

Matrix(%id = 18446746086682646398)

(1)

P(A,B);

Matrix(2, 2, {(1, 1) = 122, (1, 2) = 104, (2, 1) = -80, (2, 2) = -12})

(2)

 


Addition. Below is an example of another method (without a custom procedure):
 

A:=Matrix(2,3,(i,j)->LinearAlgebra:-RandomVector(2,generator=-9..9));
B:=Matrix(3,4,(i,j)->LinearAlgebra:-RandomVector(2,generator=-9..9));
subsindets(A.B, `*`,t->`.`(op(t)));

Download P.mw

First 97 98 99 100 101 102 103 Last Page 99 of 290