Kitonum

21500 Reputation

26 Badges

17 years, 60 days

MaplePrimes Activity


These are answers submitted by Kitonum

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)];

 

A:={20,15,10,30,46,78}; 
S:=0:
for i from 1 to nops(A) do
S:=S+A[i];
if S>=50 then break fi;
od:
B:=A[1..i-1];

Maple automatically sorts the elements of a set in ascending order, so for Maple your set will be  A={10, 15, 20, 30, 46, 78}

Example:

DocumentTools:-Tabulate(Matrix(2, [seq(plot(x^k, x=-1..1, size=[300,300]),k=1..4)]), interior = none, exterior = none);

See help for details.

To see this matrix run the  interface(rtablesize=infinity):   command first.

If you do not have Maple on your work computer, then you cannot rotate your 3D plot with the mouse.

Two possible options:
1. You can simply save the plot in any graphic format and display it as a static image.
2. You can make a simple animation in Maple, for example, rotating your plot around a spatial axis, then save this animation as a GIF file. Such files can be played in many browsers and in Power Point.

The problem is easily solved by application of the formula inclusions and exclusions:

for n from 6 do
if sum(binomial(6,k)*(6^n-(6-k)^n)*(-1)^(k-1), k=1..6)/6^n>=1/2 then break fi;
od;
n;
                                       
          13

restart; 
b:=unapply(rsolve({b(n)+b(n-1)+b(n-2)=0, b(0)=1, b(1)=-1, b(2)=0}, b(n)), n);

seq(expand(b(n)), n=1..20);
                           
-1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0

 

You can do this as follows (in the example, 4 ellipses are plotted):

restart;
F1,F2:=[-1,0],[1,0]:
Eq:=sqrt((x-F1[1])^2+(y-F1[2])^2)+sqrt((x-F2[1])^2+(y-F2[2])^2) = C;
plots:-implicitplot([seq(eval(Eq,C=c),c=[2.2,3,4,5])], x=-4..4, y=-4..4, color=[red,yellow,blue,green], scaling=constrained, gridrefine=3);

 

You forgot to call the  plots  package. So replace  display  with  plots:-display . To create  filled circles, use  the  disk  command instead of  circle  command. 

First 93 94 95 96 97 98 99 Last Page 95 of 290