Kitonum

21435 Reputation

26 Badges

17 years, 22 days

MaplePrimes Activity


These are answers submitted by Kitonum

L:=[ ]:

for t from 10 by 2 to 100 do

h := solve({x*y*z = 6*t^3, x-y-z = 0, x+y+z = 6*t}, {x, y, z}):

L:= [op(L), rhs(h[1][2])]:

end do:

A:=matrix([L]);

It works much faster.

NumberOfTriangles1:=proc(G)

local L, M, N, i, j;

uses GraphTheory;

L:=Edges(G);

M:=Vertices(G);

N:=0;

for i in L do

for j in M do

if evalb({i[1],j} in L) and evalb({i[2],j} in L) then N:=N+1; fi;

od; od;

N/3;

end proc:

 

An example:

G:=GraphTheory[RandomGraphs][RandomGraph](200, 1000):

st := time(): NumberOfTriangles1(G); time()-st;

                                    171

                                   1.045

It's quite simple. For clarity, the procedure draws a graph G . If it is not necessary, you just remove the line  print(DrawGraph(G));  from the text of the procedure.

NumberOfTriangles:=proc(n, m)

local G, N, i, j, k, G1;

uses GraphTheory;

G:=RandomGraphs[RandomGraph](n, m);

N:=0:

for i to n-2 do

for j from i+1 to n-1 do

for k from j+1 to n do

G1:=InducedSubgraph(G,[i,j,k]);

if NumberOfEdges(G1)=3 then N:=N+1; fi;

od; od; od;

print(DrawGraph(G));

N;

end proc;

 

Example:

NumberOfTriangles(8,14);

combine(r^2 * Sum(A(j)*r^(n+j), j));

In the code try to swap   c = 0 .. 4  and  xT = .8 .. 1 .

assume(a+b>c,  a+c>b,  b+c>a):

p:=(a+b+c)/2:

S:=sqrt(p*(p-a)*(p-b)*(p-c)):

`cos(A)`:=(b^2+c^2-a^2)/2/b/c:

`cos(B)`:=(a^2+c^2-b^2)/2/a/c:

`cos(C)`:=(b^2+a^2-c^2)/2/b/a:

`tan(A/2)`:=sqrt((1-`cos(A)`)/(1+`cos(A)`)):

`tan(B/2)`:=sqrt((1-`cos(B)`)/(1+`cos(B)`)):

`tan(C/2)`:=sqrt((1-`cos(C)`)/(1+`cos(C)`)):

r:=S/p:  R:=a*b*c/4/S:

is(p*(`tan(A/2)`+`tan(B/2)`+`tan(C/2)`)=r+4*R);

                           true

If you use Bonnet's recursion formula from wiki, the program can be obtained very simple:

LegPol:=proc(n)

local P, i, f;

P[0]:=1: P[1]:=x:

if n>=2 then for i to n-1 do

P[i+1]:=((2*i+1)*x*P[i]-i*P[i-1])/(i+1);

od; fi;

f:=expand(P[n]);

f/lcoeff(f);

end proc;

 

Example:

for k from 0 to 9 do

LegPol(k);

od;

You get the same polynomials as above.

Your problem can be solved in one line. However, my previous comment fully applies and to this decision:

extrema(sqrt((X-x)^2+(Y-y)^2+(Z-z)^2),{x^2 + y^2 + z^2-2*x+4*y+2*z-3=0, 2*X-Y+2*Z-14=0},{X,Y,Z,x,y,z},'s'),  s;

Your solution is correct, if the sphere does not intersect with the plane. Otherwise, the smallest distance is equal to 0. Therefore, the code should include verification of this fact!

In the Maple there is no need to write code to calculate the Legendre polynomials. This is done automatically in the package orthopoly. They are different from yours only leading coefficients.

Example of calculation of the first 10 polynomials:

with(orthopoly):

for k from 0 to 9 do

sort(P(k,x)/lcoeff(P(k,x)));

od;

Different variant is to use surd command.

Compare:

surd(-8,3);  simplify((-8)^(1/3));

-2

1+sqrt(3)*I

 

solve(surd(x+24,3)+sqrt(12-x) = 6);

-88, -24, 3

simplify(algsubs(1-sin(x)^2=cos(x)^2,cos(x)^2+cos(4*x) + cos(x)^4 + sin(x)^4 + cos(x)^6 + sin(x)^6), {expand(cos(2*x))=t});

This example , of course, can be easily solved by hand, but if you deal with Maple, you can write:

simplify(expand(cos(x)^2+cos(4*x)), {expand(cos(2*x))=cos(2*x)});

The region must be defined in terms of Cartesian coordinates, where x=Re(z) , y=Im(z) .

An example of building the region  {|z|>=1, |z|<=2, Pi/4<=Arg(z)<=5*Pi/4} :

 

plots[implicitplot]((x^2+y^2-4)*(x^2+y^2-1)<=0, x = -3..3, y = x..3, coloring=[blue, white], filledregions = true,numpoints = 10000);

You have two basic elements g and g1. All the rest are obtained from them by  translate command.

g := plottools[curve]([seq([cos(2*Pi*i*(1/3)), sin(2*Pi*i*(1/3))], i = 0 .. 3)], color = brown, thickness = 5):

g1 := plottools[rotate](g, (1/3)*Pi, [cos(2*Pi*(1/3)), sin(2*Pi*(1/3))]):

plots[display](g, g1, scaling = constrained);

 

Different variant:

g := plottools[curve]([seq([cos(Pi/2+2*Pi*i*(1/3)), sin(Pi/2+2*Pi*i*(1/3))], i = 0 .. 3)], color = brown, thickness = 5):

g1 := plottools[rotate](g, (1/3)*Pi, [0, 1]):

plots[display](g, g1, scaling = constrained);

First 282 283 284 285 286 287 288 Page 284 of 289