## 18899 Reputation

14 years, 29 days

## has, select...

```restart;
F:=2*y*sin(beta*x)+6*z*cos(beta*x)+24*sin(beta*x)*cos(beta*x):
coeff(select(t->has(t,sin) and not has(t,cos),F), sin(beta*x));
```

## gamma is Euler's constant...

In Maple gamma is Euler's constant, not a symbol. When you write  gamma(t) , this is a constant function, which equals  gamma  for any t .

```restart;
simplify([3(t), gamma, gamma(t)]);
evalf(%);```

[3, gamma, gamma]
[3., 0.5772156649, 0.5772156649]

In the second example  gamma  is a symbol  (`&gamma;`)

## Procedure for this...

The procedure checks for a match in the rows of matrices  A  and  B  and returns a list of lists  L , in which the 1st element is the matching row, and the 2nd element is a list of two numbers (how many times this row occurs in each of the matrices).

 > restart; CheckRowsUniquie:=proc(A::Matrix,B::Matrix) local m1, m2, A1, B1, A11, B11, k, a, b, L; uses LinearAlgebra, ListTools; m1,m2:=ColumnDimension(A),ColumnDimension(B); if m1<>m2 then error "Should be ColumnDimension(A)=ColumnDimension(B)" fi; A1:=convert(A,listlist); B1:=convert(B,listlist); A11:=Collect(A1); B11:=Collect(B1); k:=0; for a in A11 do for b in B11 do if a[1]=b[1] then k:=k+1; L[k]:=[a[1],[a[2],b[2]]] fi; od; od; convert(L,list); end proc:
 > A:=<1,2; 3,4; 1,2; 5,6>; B:=<0,1; 1,2; 1,2; 3,4; 7,8>; CheckRowsUniquie(A,B);
 (1)
 >

## GraphTheory:-RelabelVertices...

Just use the  RelabelVertices  command as in the example below:

```restart;
with(GraphTheory):
G := Graph({{1, 2}, {1, 3}, {1, 4}});
V := Vertices(G);
V1 := subs([1, 2]=~[a, b], V);
H := RelabelVertices(G, V1);
DrawGraph(H);```

## Specify the ranges...

Just specify the ranges for the variables  x  and  y  and the error will disappear:

```restart;
plots:-implicitplot(x-y-Pi, x=-1..5, y=-4..1);```

## eval...

Or use the  eval  command:

```restart;
dgdx := (x,T)->diff(g(x, T), x);
g := (x,T)->T*x + x^2;
eval(dgdx(x,T), [x=1,T=2]);```

The reason for the error in OP's approach is that Maple first substitutes  x  and  y  with the numbers 1 and 2 and the result is differentiation not with respect to the variable  x , but with respect to the constant  1 .

## zip...

```restart;
A := <<true, false, true> | <true, false, true> | <false, false, false>>;
B := <<1, 2, 6> | <3, 4, 7> | <22, 33, 44>>;
zip((u,v)->`if`(u=true,v,`( )`), A,B);```

## plot3d, plots:-spacecurve...

I don't know why Student:-Calculus1:-VolumeOfRevolution command distorts the colors. You may get better results if you use the  plot3d  command to draw surfaces. I also selected the edges of the cylinder (2 circles) using the  plots:-spacecurve  command:

```restart;
A:=plot3d([x,4*cos(t),4*sin(t)], t=0..2*Pi, x=1..2, style=surface, color="Blue"):
B:=plot3d([[1,r*cos(t),r*sin(t)],[2,r*cos(t),r*sin(t)]], t=0..2*Pi, r=0..4, style=surface, color="Blue"):
C:=plots:-spacecurve([[1,4*cos(t),4*sin(t)],[2,4*cos(t),4*sin(t)]], t=0..2*Pi, color=black, thickness=2):
plots:-display(A,B,C, transparency=0.6, scaling=constrained, view = [0 .. 3, -5 .. 5, -5 .. 5], axes=normal, orientation = [-94,-18,11], labels = [x, y, z]);

```

## `if`...

See the following toy example:

```A:=<1,2; ``,3>;
map(t->`if`(t=``,``,f(t)), A);```

## Complex values...

Look at these 2 graphs. We see that on a part of the range  0..2*Pi , the function takes negative values. Therefore, the square root on these intervals will take on complex values.

```plot(c^2-a^2*cos(theta)^2, theta = 0 .. 2*Pi);
plot(b^2-(a*sin(theta)+sqrt(c^2-a^2*cos(theta)^2))^2, theta = 0 .. 2*Pi);```

## solve...

You must use the  solve  command for this:

```restart;
eq:=5*a^2 + 2*b - 7 = 0;
a:=1;
b=solve(eq, b);```

## Easier and more automatic...

This can be done more simply and more automatically as in the example:

```restart;
with(plots):
with(plottools):
p1:= cuboid( [0,0,0], [1,1,1], color="LightBlue", transparency=0.5): # The cube
p2:=plot3d(3/2-x-y, x=-1..2, y=-1..2, style=surface, color=red): # The plane
display([p1, p2], view=[(0..1)\$3]);
```

I considered a more interesting example in which the intersection will be a regular hexagon. For your example in the code replace 3/2 - x - y  with  1 - x .

## Solution...

The problem is surprisingly easy to solve. Leave the first column unchanged. For the remaining columns, sequentially in the cycle, we find the desired permutation:

```restart;
L1:=[blue\$3,brown\$2,yellow\$2,red,black]:
L2:=[blue\$3,purple\$2,pink\$2,red,black]:
L3:=[green\$3,brown\$2,pink\$2,red,black]:
L4:=[orange\$3,purple\$2,yellow\$2,red,black]:
L5:=[green\$3,brown\$2,yellow\$2,red,black]:
L6:=[orange\$3,purple\$2,pink\$2,red,black]:
L7:=[blue\$3,brown\$2,yellow\$2,red,black]:
assign(seq(P||i=combinat:-permute(L||i), i=2..7)):

OneStep:=proc(L,P)
local p;
for p in P do
if `and`(seq(not (p[i] in convert(L[i],set)), i=1..9)) then
return [seq([op(L[i]),p[i]],i=1..9)] fi;
od;
end proc:

L:=L1:
for n from 1 to 6 do
L:=OneStep(L,P||(n+1));
od:

for n from 1 to 9 do
R[n]:=plots:-pointplot([seq([i,10-n],i=1..7)], color=convert(L[n],list), symbol=solidcircle, symbolsize=40);
od:
plots:-display(seq(R[n], n=1..9), axes=none, size=[500,700], scaling=constrained);
```

## A way...

I don't know of a purely automatic way to solve the problem. The procedure below returns a set of self-intersection points. But it uses an optional parameter  n  (default is 50). The number  n  means the number of intervals for applying the  fsolve  command. We select the number   in such a way that only 1 self-intersection point can fall into one interval. I think that for most examples  n=50  will be enough (in the example below,  n=30  was enough). But probably there are complex examples where a larger number of   is required. Therefore, it is recommended to make a plot before applying the procedure in order to estimate the value of  .

```restart;
Self_Intersection_Points:=proc(L::list,R::range,n::posint:=50)
local x, y, a, b, h, k, m, Sol, S;
x:=unapply(L[1],t); y:=unapply(L[2],t);
a:=lhs(R); b:=rhs(R);
h:=(b-a)/n;
m:=0;
for k from 2 to n do
Sol:=fsolve({x(t)=x(s),y(t)=y(s)}, {s=a+h*(k-1)..a+h*k,t=a..a+h*(k-1)});
if type(Sol,set) then m:=m+1; S[m]:=eval(s,Sol) fi;
od;
convert(S,set);
end proc:
```

Example of use:

```x:=t->4*cos(t/2)+2*cos(2*t)+cos(4*t): y:=t->4*sin(t/2)+2*sin(2*t)+sin(4*t):
L:=Self_Intersection_Points([x(t),y(t)],0..4*Pi, 30);
A:=plot([x(t),y(t), t=0..4*Pi], color=blue):
B:=plot(map(t->[x(t),y(t)],L), style=point, symbol=solidcircle, color=red, symbolsize=10):
plots:-display(A,B, size=[500,500]);
```

## OK...

Your decision is correct. You can test each of the solutions using the  odetest  command:

```restart;
Dgl_1 := diff(y(x), x) = (1 + y(x)^2)/(x*y(x));
P := dsolve(Dgl_1, y(x));
odetest(P[1], Dgl_1);
odetest(P[2], Dgl_1);
```
 1 2 3 4 5 6 7 Last Page 1 of 270
﻿