Kitonum

21435 Reputation

26 Badges

17 years, 26 days

MaplePrimes Activity


These are answers submitted by Kitonum

I think Maple simply cannot cope with the symbolic (that is, exact) calculation of your integral. Therefore, I advise you to calculate it numerically, replacing infinity for example with the number 10. For comparison, I replaced infinity with the number 20. The results are identical. The reason is that the integrand very quickly converges to 0 (see its plot):

restart;

g(x,y):=min(3+(x-y)^2/10+abs(x+y)/sqrt(2),-abs(x-y)+7/sqrt(2));

q:=0; 
h(x,y):=Heaviside(g(x,y)-q);

p := Int(Int(h(x, y)*exp((-x^2-y^2)*(1/2))/(2*Pi), y = -10 .. 10), x = -10 .. 10);
evalf(%);

plot3d(h(x, y)*exp((-x^2-y^2)*(1/2))/(2*Pi), x=-5..5,y=-5..5);

p1 := Int(Int(h(x, y)*exp((-x^2-y^2)*(1/2))/(2*Pi), y = -20 .. 20), x = -20 .. 20);
evalf(%);


 

The number of subintervals is determined by the  partition  option. By default it is [5, 5] , that is, the interval for each variable is divided into 5 parts. Here are 2 examples with different values:


 

restart;

with(Student[MultivariateCalculus]):

ApproximateInt(x^2+y^2, x = 0 .. 2, y = 0 .. 3, partition=[2,3], output=plot);
ApproximateInt(x^2+y^2, x = 0 .. 2, y = 0 .. 3, partition=[4,6], output=plot);

 

 

 


 

Download int.mw

When there is no idea how to symbolically represent a numeric expression, the following trick is useful:

identify(evalf((1/2)!));

                                              

 

 

You can easily do this using just 2 commands (in the title):

A:=DETools:-DEplot(diff(y(t),t)=(3-y(t))*(y(t)+1), y(t), t=0..5, y=-2..4, color=yellow, linecolor=white, [y(0)=4]):
B:=Student:-NumericalAnalysis:-Euler(diff(y(t),t)=(3-y(t))*(y(t)+1), y(0) = 4, t = 5, plotoptions=[color=red, symbolsize=12], output=plot):
plots:-display(A,B,scaling=constrained, size=[400,500]);

        

The nodal points in the Euler method are highlighted with small red circles (Maple does this automatically).

I can not confirm this. Everything works properly. Take a look:

restart;
F := x^2+y^2 = 1;
G := lhs(F) <= rhs(F);
is(eval(G, [x=0.5,y=0.6]));

                                       F := x^2+y^2 = 1
                                      G := x^2+y^2 <= 1
                                              true


Please submit the full text of the code in which you encountered this error "Error, cannot determine if this expression is true or false: x^2+y^2 <= 1"

     

Two syntax errors:

1. Should be  Pi  not  pi (it's just a symbol).

2. Should be  e(1)  instead of  e(T=1) .


 

restart;
k:=T->2/cosh(2/T)/coth(2/T);
delta:=T->sqrt(1-k(T)^2*sin(theta)^2);
e:=T->-2*tanh(2/T)+D(T->k(T)/2/Pi*Int(sin(theta)^2/delta(T)/(1+delta(T)), theta=0..Pi))(T);

proc (T) options operator, arrow; 2/(cosh(2/T)*coth(2/T)) end proc

 

proc (T) options operator, arrow; sqrt(1-k(T)^2*sin(theta)^2) end proc

 

proc (T) options operator, arrow; -2*tanh(2/T)+(D(proc (T) options operator, arrow; (1/2)*k(T)*(Int(sin(theta)^2/(delta(T)*(1+delta(T))), theta = 0 .. Pi))/Pi end proc))(T) end proc

(1)

evalf(e(1));

-1.742031581

(2)

 


 

Download 11.mw

Here is a simple procedure that implements your task. The default upper limit for the number of units to be checked is 5,000. You can easily change it in the procedure code if you wish.

Wrapped_prime:=proc(p::prime, N::posint:=5000)
local n, k, m0, m;
n:=length(p);
for k from 1 to N do
m0:=add(10^i, i=0..k-1);
m:=m0+10^k*p+10^(k+n)*m0;
if isprime(m) then return k fi;
od;
end proc:


Examples of use:

Wrapped_prime(59);
                                                  42

Wrapped_prime(7);
                                                   
3

Wrapped_prime(2);
                                                 
NULL

Wrapped_prime(71);
                                                   
73

Wrapped_prime(167);
                                                 
192
 

Here is another significantly more efficient way to generate primitive Pythagorean triples. This method is based on building a tree of such triples. At each step, the number of triples tripled. The simplest triple  <3, 4 ,5>  is the root of this tree. See this article  https://en.wikipedia.org/wiki/Tree_of_primitive_Pythagorean_triples  for details.

Below the code the procedure  PPT  (Primitive Pythagorean Triples)  and examples of use:


 

restart;

PPT:=proc(n::nonnegint)
local A, B, C, T, k;
A:=<1,-2,2; 2,-1,2; 2,-2,3>;
B:=<1,2,2; 2,1,2; 2,2,3>;
C:=<-1,2,2; -2,1,2; -2,2,3>;
T[0]:=[<3,4,5>];
for k from 1 to n do
T[k]:=map(t->op([A.t,B.t,C.t]), T[k-1]);
od;
[seq(op(T[i]), i=0..n)];
end proc:  

PPT(4);

[Vector(3, {(1) = 3, (2) = 4, (3) = 5}), Vector(3, {(1) = 5, (2) = 12, (3) = 13}), Vector(3, {(1) = 21, (2) = 20, (3) = 29}), Vector(3, {(1) = 15, (2) = 8, (3) = 17}), Vector(3, {(1) = 7, (2) = 24, (3) = 25}), Vector(3, {(1) = 55, (2) = 48, (3) = 73}), Vector(3, {(1) = 45, (2) = 28, (3) = 53}), Vector(3, {(1) = 39, (2) = 80, (3) = 89}), Vector(3, {(1) = 119, (2) = 120, (3) = 169}), Vector(3, {(1) = 77, (2) = 36, (3) = 85}), Vector(3, {(1) = 33, (2) = 56, (3) = 65}), Vector(3, {(1) = 65, (2) = 72, (3) = 97}), Vector(3, {(1) = 35, (2) = 12, (3) = 37}), Vector(3, {(1) = 9, (2) = 40, (3) = 41}), Vector(3, {(1) = 105, (2) = 88, (3) = 137}), Vector(3, {(1) = 91, (2) = 60, (3) = 109}), Vector(3, {(1) = 105, (2) = 208, (3) = 233}), Vector(3, {(1) = 297, (2) = 304, (3) = 425}), Vector(3, {(1) = 187, (2) = 84, (3) = 205}), Vector(3, {(1) = 95, (2) = 168, (3) = 193}), Vector(3, {(1) = 207, (2) = 224, (3) = 305}), Vector(3, {(1) = 117, (2) = 44, (3) = 125}), Vector(3, {(1) = 57, (2) = 176, (3) = 185}), Vector(3, {(1) = 377, (2) = 336, (3) = 505}), Vector(3, {(1) = 299, (2) = 180, (3) = 349}), Vector(3, {(1) = 217, (2) = 456, (3) = 505}), Vector(3, {(1) = 697, (2) = 696, (3) = 985}), Vector(3, {(1) = 459, (2) = 220, (3) = 509}), Vector(3, {(1) = 175, (2) = 288, (3) = 337}), Vector(3, {(1) = 319, (2) = 360, (3) = 481}), Vector(3, {(1) = 165, (2) = 52, (3) = 173}), Vector(3, {(1) = 51, (2) = 140, (3) = 149}), Vector(3, {(1) = 275, (2) = 252, (3) = 373}), Vector(3, {(1) = 209, (2) = 120, (3) = 241}), Vector(3, {(1) = 115, (2) = 252, (3) = 277}), Vector(3, {(1) = 403, (2) = 396, (3) = 565}), Vector(3, {(1) = 273, (2) = 136, (3) = 305}), Vector(3, {(1) = 85, (2) = 132, (3) = 157}), Vector(3, {(1) = 133, (2) = 156, (3) = 205}), Vector(3, {(1) = 63, (2) = 16, (3) = 65}), Vector(3, {(1) = 11, (2) = 60, (3) = 61}), Vector(3, {(1) = 171, (2) = 140, (3) = 221}), Vector(3, {(1) = 153, (2) = 104, (3) = 185}), Vector(3, {(1) = 203, (2) = 396, (3) = 445}), Vector(3, {(1) = 555, (2) = 572, (3) = 797}), Vector(3, {(1) = 345, (2) = 152, (3) = 377}), Vector(3, {(1) = 189, (2) = 340, (3) = 389}), Vector(3, {(1) = 429, (2) = 460, (3) = 629}), Vector(3, {(1) = 247, (2) = 96, (3) = 265}), Vector(3, {(1) = 155, (2) = 468, (3) = 493}), Vector(3, {(1) = 987, (2) = 884, (3) = 1325}), Vector(3, {(1) = 777, (2) = 464, (3) = 905}), Vector(3, {(1) = 539, (2) = 1140, (3) = 1261}), Vector(3, {(1) = 1755, (2) = 1748, (3) = 2477}), Vector(3, {(1) = 1161, (2) = 560, (3) = 1289}), Vector(3, {(1) = 429, (2) = 700, (3) = 821}), Vector(3, {(1) = 765, (2) = 868, (3) = 1157}), Vector(3, {(1) = 391, (2) = 120, (3) = 409}), Vector(3, {(1) = 145, (2) = 408, (3) = 433}), Vector(3, {(1) = 817, (2) = 744, (3) = 1105}), Vector(3, {(1) = 627, (2) = 364, (3) = 725}), Vector(3, {(1) = 369, (2) = 800, (3) = 881}), Vector(3, {(1) = 1265, (2) = 1248, (3) = 1777}), Vector(3, {(1) = 851, (2) = 420, (3) = 949}), Vector(3, {(1) = 279, (2) = 440, (3) = 521}), Vector(3, {(1) = 455, (2) = 528, (3) = 697}), Vector(3, {(1) = 221, (2) = 60, (3) = 229}), Vector(3, {(1) = 75, (2) = 308, (3) = 317}), Vector(3, {(1) = 779, (2) = 660, (3) = 1021}), Vector(3, {(1) = 665, (2) = 432, (3) = 793}), Vector(3, {(1) = 715, (2) = 1428, (3) = 1597}), Vector(3, {(1) = 2059, (2) = 2100, (3) = 2941}), Vector(3, {(1) = 1305, (2) = 592, (3) = 1433}), Vector(3, {(1) = 637, (2) = 1116, (3) = 1285}), Vector(3, {(1) = 1357, (2) = 1476, (3) = 2005}), Vector(3, {(1) = 759, (2) = 280, (3) = 809}), Vector(3, {(1) = 315, (2) = 988, (3) = 1037}), Vector(3, {(1) = 2139, (2) = 1900, (3) = 2861}), Vector(3, {(1) = 1705, (2) = 1032, (3) = 1993}), Vector(3, {(1) = 1275, (2) = 2668, (3) = 2957}), Vector(3, {(1) = 4059, (2) = 4060, (3) = 5741}), Vector(3, {(1) = 2665, (2) = 1272, (3) = 2953}), Vector(3, {(1) = 1037, (2) = 1716, (3) = 2005}), Vector(3, {(1) = 1917, (2) = 2156, (3) = 2885}), Vector(3, {(1) = 999, (2) = 320, (3) = 1049}), Vector(3, {(1) = 273, (2) = 736, (3) = 785}), Vector(3, {(1) = 1425, (2) = 1312, (3) = 1937}), Vector(3, {(1) = 1075, (2) = 612, (3) = 1237}), Vector(3, {(1) = 561, (2) = 1240, (3) = 1361}), Vector(3, {(1) = 2001, (2) = 1960, (3) = 2801}), Vector(3, {(1) = 1363, (2) = 684, (3) = 1525}), Vector(3, {(1) = 407, (2) = 624, (3) = 745}), Vector(3, {(1) = 615, (2) = 728, (3) = 953}), Vector(3, {(1) = 285, (2) = 68, (3) = 293}), Vector(3, {(1) = 69, (2) = 260, (3) = 269}), Vector(3, {(1) = 629, (2) = 540, (3) = 829}), Vector(3, {(1) = 527, (2) = 336, (3) = 625}), Vector(3, {(1) = 517, (2) = 1044, (3) = 1165}), Vector(3, {(1) = 1525, (2) = 1548, (3) = 2173}), Vector(3, {(1) = 975, (2) = 448, (3) = 1073}), Vector(3, {(1) = 451, (2) = 780, (3) = 901}), Vector(3, {(1) = 931, (2) = 1020, (3) = 1381}), Vector(3, {(1) = 513, (2) = 184, (3) = 545}), Vector(3, {(1) = 165, (2) = 532, (3) = 557}), Vector(3, {(1) = 1173, (2) = 1036, (3) = 1565}), Vector(3, {(1) = 943, (2) = 576, (3) = 1105}), Vector(3, {(1) = 741, (2) = 1540, (3) = 1709}), Vector(3, {(1) = 2325, (2) = 2332, (3) = 3293}), Vector(3, {(1) = 1519, (2) = 720, (3) = 1681}), Vector(3, {(1) = 611, (2) = 1020, (3) = 1189}), Vector(3, {(1) = 1155, (2) = 1292, (3) = 1733}), Vector(3, {(1) = 609, (2) = 200, (3) = 641}), Vector(3, {(1) = 135, (2) = 352, (3) = 377}), Vector(3, {(1) = 663, (2) = 616, (3) = 905}), Vector(3, {(1) = 493, (2) = 276, (3) = 565}), Vector(3, {(1) = 231, (2) = 520, (3) = 569}), Vector(3, {(1) = 855, (2) = 832, (3) = 1193}), Vector(3, {(1) = 589, (2) = 300, (3) = 661}), Vector(3, {(1) = 161, (2) = 240, (3) = 289}), Vector(3, {(1) = 225, (2) = 272, (3) = 353}), Vector(3, {(1) = 99, (2) = 20, (3) = 101})]

(1)

S:=PPT(10):
nops(S);
# The first 10 and the last 10 triples of the list S
S[1..10][], S[-10..-1][];

88573

 

Vector[column](%id = 18446745482564281518), Vector[column](%id = 18446745482564281638), Vector[column](%id = 18446745482564281758), Vector[column](%id = 18446745482564281878), Vector[column](%id = 18446745482564281998), Vector[column](%id = 18446745482564282118), Vector[column](%id = 18446745482564282238), Vector[column](%id = 18446745482564282358), Vector[column](%id = 18446745482564282478), Vector[column](%id = 18446745482564282598), Vector[column](%id = 18446745482565857638), Vector[column](%id = 18446745482565857758), Vector[column](%id = 18446745482565857878), Vector[column](%id = 18446745482565857998), Vector[column](%id = 18446745482565858118), Vector[column](%id = 18446745482565858238), Vector[column](%id = 18446745482565858358), Vector[column](%id = 18446745482565858478), Vector[column](%id = 18446745482565858598), Vector[column](%id = 18446745482565858718)

(2)

 


 

Download PPT.mw

 

Here is the simplest sorting algorithm called bubble sorting. See wiki for details.

restart;
BubbleSort:=proc(L::list(numeric))
local n, L1, k, m;
n:=nops(L);
L1:=L;
for k from 0 to n-2 do
for m from 1 to n-k-1 do
if L1[m]>L1[m+1] then L1:=subsop(m=L1[m+1],m+1=L1[m],L1) fi;
od; od;
L1;
end proc:


Example of use:

r:=rand(1..100):
L:=[seq(r(), i=1..20)];
BubbleSort(L);     

             L := [35, 15, 26, 100, 24, 8, 63, 78, 23, 73, 22, 32, 98, 9, 53, 3, 98, 69, 3, 73]
                   [3, 3, 8, 9, 15, 22, 23, 24, 26, 32, 35, 53, 63, 69, 73, 73, 78, 98, 98, 100]
 

 


 

NULL

restart

FS := proc (xi, m0, `&xi;wp`, `&mu;v`) options operator, arrow; `if`(abs(xi) <= 1, m0*xi*(1-abs(xi))^2+xi*abs(xi)*(3-2*abs(xi)), signum(xi)*((`&xi;wp`-1)^2+`&mu;v`*(abs(xi)-1)^2)/((`&xi;wp`-1)^2+(abs(xi)-1)^2)) end proc

plot(FS(xi, 1.5, 2, .8), xi = 0 .. 1.5)

 

NULL


 

Download plottest_new.mw

You can plot lines and points separately, and then all together using  plots:-display  command.

Example:

A:=plot(sin(x), x=0..2*Pi, color="DeepPink"):
B:=plot(cos(x), x=0..2*Pi, linestyle=3, color=blue):
A1:=plot([seq([x,sin(x)], x=0..6.29,evalf(Pi/2))], style=point, color="DeepPink", symbol=solidcircle, symbolsize=20):
B1:=plot([seq([x,cos(x)], x=0..6.29,evalf(Pi/3))], style=point, color=blue, symbol=solidbox, symbolsize=20):
plots:-display(A,B,A1,B1, size=[800,300], scaling=constrained);

       

To plot this contour, you do not need to solve any equation. You can simply substitute the value of this variable  Delta=-12.71  in the equation  f :

restart:
with(plots):

Omega:=0:lambda:=1:
gamma1:=8*Pi:
gamma2:=0.002*Pi:
x1:=100*Pi:
omega2:=200*Pi:
gamma0:=0.2*Pi:
G:=20*Pi:

lambda1:=(1/(2*Pi))*(G*Omega*gamma0/(2*(0.25*gamma0^2+Delta^2))):
lambda2:=(1/(2*Pi))*(-G*Omega*Delta/((0.25*gamma0^2+Delta^2))):
lambda3:=(1/(2*Pi))*gamma1+lambda1:
lambda4:=(1/(2*Pi))*(lambda*Delta-G^2*Delta/(0.25*gamma0^2+Delta^2)):
lambda5:=(1/(2*Pi))*(2*x1^2*omega2/((omega2^2+gamma2^2))):
f:=epsilon=(lambda1+sqrt(-lambda2^2+Y^2*(lambda3^2+(lambda4-lambda5*Y^2)^2)));

implicitplot3d(f, epsilon=0..20,Y = 0 .. 1,Delta=-40*Pi..40*Pi, labels=[epsilon,X,Delta],tickmarks=[3,3,3],style=surface);

implicitplot(eval(f,Delta=-12.71), epsilon=-20..20,Y = 0 .. 1, labels=[epsilon,Y], gridrefine=5);

 

L:=[.358700275060090779, [p[0] = .192413186080606, p[1] = 0.906594292940704e-1, p[2] = 0.677108912885780e-1, p[3] = 0.609551830556988e-1, p[4] = 0.589744573790909e-1, p[5] = 0.585737058072817e-1, p[6] = 0.589744573787748e-1, p[7] = 0.609551830550955e-1, p[8] = 0.677108912877626e-1, p[9] = 0.906594292931833e-1, p[10] = .192413186079858]]:
Data:=map(rhs, L[2]);
Statistics:-LineChart(Data);

 

It is better to solve your problems by writing mu and sigma down as procedures:

mu:=proc()
local k;
add(args[k],k=1..nargs)/nargs;
end proc:

sigma:=proc()
local k;
sqrt(add((args[k]-mu(args))^2, k=1..nargs)/(nargs-1));
end proc:


Examples of use:

mu($1..20);
sigma($1..20);


Codes of these procedures can be written more compactly if we use arrow notation and element-wise operator ~ :

mu:=()->`+`(args)/nargs:

sigma:=()->sqrt(add(([args]-~mu(args))^~2)/(nargs-1)):


Edit.

I think for a beginner the following code will be clearer. It does the same thing as  CartProd1  (of course for 3 lists only):

A:= [1,5,7]:
B:= [23,56,12]:
C:= [1,3]:
[seq(seq(seq([a,b,c],a=A),b=B),c=C)];

 

First 92 93 94 95 96 97 98 Last Page 94 of 289