mmcdara

7891 Reputation

22 Badges

9 years, 50 days

MaplePrimes Activity


These are answers submitted by mmcdara

Let us take this simple example

z := a+I*b
                            a + I b
Re(z), Im(z)
                    Re(a + I b), Im(a + I b)

This may be a surprising result but it is normal: as you did not say that a and b where real, for instance, you have no reason to say that Re(z) = a and Im(z) = b.

Now you want to take the real and imaginary parts of pde3 and the results are "unchanged" as you say: but how could they be if you don't say that theta, phi, c, x, t, Omega, k, ... are real or imaginary or complex?

If you just want to separate the sub-expressions which explicitely contain I , you can, do this:

ImPart, RePart := add~([ selectremove(has, [op(lhs(pde3))], I) ])[]:
print(RePart);
print(ImPart);




About your question:  Also how to convert 'D(phi)(-c*t + x) = phi_\xi' as in Eq. (1.5)?

phi_\xi is not a mathematical expression in Maple. What is this supposed to mean?
Be more clear please.




About your question: How to assume phi is an even function and theta is an odd function as in the image?
Example (phi is assumed even)

expr := phi(x-c*t)*phi(-x+c*t); 
                      phi(-c t + x) phi(c t - x)

op(1, expr) * eval(op(2, expr),  phi = (u -> phi(-u)));
                                      2
                         phi(-c t + x) 

eval(op(1, expr),  phi = (u -> phi(-u))) * op(2, expr)
                                     2
                         phi(c t - x) 

A more complex example:

expr    := phi(x-c*t)*phi(-x+c*t) + theta(x-c*t)*theta(-x+c*t);
expr_f  := indets(expr, function):
expr_fo := op~(expr_f):

# Select arbitrarily one of these two as the "reference"

ref := expr_fo[1]:

# Assuming phi is even and theta is odd
# Select amid Im_f the functions which DO NOT depend on ref: there will be the
# functions to rewrite:

ref_free := remove(has, expr_f, ref):

# Build the rewritting rules RR:

RR := NULL:
for f in ref_free do
print(f);
  if op(0, f) = phi then 
    RR := RR, phi(ref) = phi(-ref)
  elif op(0, f) = theta then 
    RR := RR, theta(ref) = -theta(-ref)
  end if
end do:

# Rewrite expr wrt RR

eval(expr, {RR});

  phi(-c t + x) phi(c t - x) + theta(-c t + x) theta(c t - x)
                            2                 2
                phi(c t - x)  - theta(c t - x) 


PD_OD_mmcdara.mw



 

restart

S := x^2+y^2-1

x^2+y^2-1

(1)

convert(S, polar)

polar(abs(x^2+y^2-1), argument(x^2+y^2-1))

(2)

S := x^2+y^2-1;
changecoords(x^2+y^2-1, [x,y], polar, [r,theta]);
solve(%, r)

x^2+y^2-1

 

r^2*cos(theta)^2+r^2*sin(theta)^2-1

 

1, -1

(3)

T := x^4+2*x^2*y^2+y^4+2*x^3+2*x*y^2-y^2;
changecoords(T, [x,y], polar, [r,theta]);
simplify(%);
solve(%, {r});

x^4+2*x^2*y^2+y^4+2*x^3+2*x*y^2-y^2

 

r^4*cos(theta)^4+2*r^4*cos(theta)^2*sin(theta)^2+r^4*sin(theta)^4+2*r^3*cos(theta)^3+2*r^3*cos(theta)*sin(theta)^2-r^2*sin(theta)^2

 

r^2*(cos(theta)^2+2*r*cos(theta)+r^2-1)

 

{r = 0}, {r = -cos(theta)+(cos(theta)^2+sin(theta)^2)^(1/2)}, {r = -cos(theta)-(cos(theta)^2+sin(theta)^2)^(1/2)}

(4)

infolevel[changecoords] := 4:
changecoords(T, [x,y], polar, [r,theta]);

r^4*cos(theta)^4+2*r^4*cos(theta)^2*sin(theta)^2+r^4*sin(theta)^4+2*r^3*cos(theta)^3+2*r^3*cos(theta)*sin(theta)^2-r^2*sin(theta)^2

(5)

R := -3*x^2+y^2-4*x-1;
changecoords(R, [x,y], polar, [r,theta]);
simplify(%);
solve(%, {r});

-3*x^2+y^2-4*x-1

 

-3*r^2*cos(theta)^2+r^2*sin(theta)^2-4*r*cos(theta)-1

 

-4*r^2*cos(theta)^2-4*r*cos(theta)+r^2-1

 

{r = -1/(2*cos(theta)-1)}, {r = -1/(2*cos(theta)+1)}

(6)

changecoords(x-2, [x,y], polar, [r,theta]);

r*cos(theta)-2

(7)

changecoords(x*y-4, [x,y], polar, [r,theta]);

r^2*cos(theta)*sin(theta)-4

(8)

changecoords(x^2-y^2-1, [x,y], polar, [r,theta]);

r^2*cos(theta)^2-r^2*sin(theta)^2-1

(9)

changecoords(y^2-3*x^2-4*x-1, [x,y], polar, [r,theta]);
simplify(%, trig);

# 4th equivalence in the book is false

simplify(% - (1+2*r*cos(theta)))

-3*r^2*cos(theta)^2+r^2*sin(theta)^2-4*r*cos(theta)-1

 

-4*r^2*cos(theta)^2-4*r*cos(theta)+r^2-1

 

-4*r^2*cos(theta)^2-6*r*cos(theta)+r^2-2

(10)

changecoords(x^4+y^4+2*x^2*y^2+2*x^ 3+2*x*y^2-y^2, [x,y], polar, [r,theta]);
simplify(%, trig);

# 5th equivalence in the book is false

simplify(% - (1-cos(theta)))

r^4*cos(theta)^4+2*r^4*cos(theta)^2*sin(theta)^2+r^4*sin(theta)^4+2*r^3*cos(theta)^3+2*r^3*cos(theta)*sin(theta)^2-r^2*sin(theta)^2

 

r^2*(cos(theta)^2+2*r*cos(theta)+r^2-1)

 

r^2*cos(theta)^2+2*cos(theta)*r^3+r^4-r^2+cos(theta)-1

(11)

# 4th book example reversed

book4 := 1+2*r*cos(theta);
algsubs(r*cos(theta) = x, book4);
changecoords(%, [x,y], polar, [r,theta]);

1+2*r*cos(theta)

 

2*x+1

 

1+2*r*cos(theta)

(12)

# 5th book example reversed

book5 := 1-cos(theta);
algsubs(cos(theta) = x/sqrt(x^2+ y^2), book5);
changecoords(%, [x,y], polar, [r,theta]);
simplify(%) assuming r::positive

1-cos(theta)

 

((x^2+y^2)^(1/2)-x)/(x^2+y^2)^(1/2)

 

-(r*cos(theta)-(r^2*cos(theta)^2+r^2*sin(theta)^2)^(1/2))/(r^2*cos(theta)^2+r^2*sin(theta)^2)^(1/2)

 

1-cos(theta)

(13)

 


 

Download polar_mmcdara.mw

Here are two examples

restart:

with(Grid):

F := proc(n, N, Folder)
  local data := LinearAlgebra:-RandomVector(N, generator=rand(0. .. 1.)):
  save data, cat(Folder, "/rand_", n, ".m");
end proc:

N      := 10:
folder := currentdir():

NN := 2:

Setup(numnodes=NN):
Set('F'):

for i from 0 to NN-1 do
  Run(i, F, [i, N, folder])
end do:
Wait():

 

G := proc(n, N, Folder)
  local file_name := cat(Folder, "/test_", n, ".txt"):
  FileTools:-Text:-WriteString(file_name, cat("processing at node =",n));
end proc:

NN := 2:

Setup(numnodes=NN):
Set('G'):

for i from 0 to NN-1 do
  Run(i, G, [i, N, folder])
end do:
Wait():

 

restart:
folder := currentdir():
read cat(folder, "/rand_", 0, ".m");
data;

Vector[column]([[.2342493224], [.1799302829], [.5137385362], [.2907448089], [.8953600369], [.2617341097], [.7780122500], [0.6587642124e-1], [.7235311453], [.3157837057]])

(1)

FileTools:-Text:-ReadLine(cat(folder, "/test_", 0, ".txt"));

"processing at node =0"

(2)
 

 

Download Grid_Files.mw



What is the polar angle?
What is the radius?
What are t and x?

You cannot use polarplot to plot a complex function depending of 5 parameters (x, t, alpha, beta, gamma) ; just read the help page for a few examples

What you could so is:

Firsly: give alpha, beta and gamma numeric values (your P?)

Secondly: choose the component (Re or Im) you want tp plot

Thirdly: choose a calue for x or t and use polarplot withthe remaining variable (t or x)...
... or use plot3d(..., coords=cylindrical) with t and x as variables.

Example:  How_to_use_xxx.mw

that the points you construct are not evenly spread within the unit disk?
(I'm sorry  @Rouben Rostamian , I missed your comment)

The way you proceed your points are concentrated round its center.
To be convinced do this

ScatterPlot(Sample(x1, 1000), Sample(y1, 1000))

The first question you have to ask yourself is "What distribution of points am I expected?", in other terms what does "taking two points at random within the unit disc" means to you?
Without this, independently of the capabilities of Maple to compute the corresponding PDF, you have several solutions.

Here is a similar problem Bertrand paradox

The attached file below explores three different "definitions" of randomness

restart

with(Statistics):


Your choice

N  := 10^4:
R1 := Sample(Uniform(0, 1), N):
R2 := Sample(Uniform(0, 1), N):
T1 := Sample(Uniform(0, 2*Pi), N):
T2 := Sample(Uniform(0, 2*Pi), N):

X1 := R1 *~ cos~(T1):
Y1 := R1 *~ sin~(T1):
X2 := R2 *~ cos~(T2):
Y2 := R2 *~ sin~(T2):

d := sqrt~((X1-X2)^~2 + (Y1-Y2)^~2):

ScatterPlot(X1, Y1, symbol=point);  # concentration round the center

 

Histogram(d)

 


Another choice

X1 := Sample(Uniform(-1, 1), N)^+:
X2 := Sample(Uniform(-1, 1), N)^+:

U1 := Sample(Uniform(-1, 1), N)^+:
U2 := Sample(Uniform(-1, 1), N)^+:

Y1 := U1 *~ sqrt~(1-~X1^~2):
Y2 := U2 *~ sqrt~(1-~X2^~2):

ScatterPlot(X1, Y1, symbol=point);  # concentration near the boundary
  

 

d := sqrt~((X1-X2)^~2 +(Y1-Y2)^~2):
Histogram(d)

 


Yet nother choice

Generaly considered as the correct one as it gives an homogenous distribution of points in the
following sense: the Voronoï diagramassociated to the (X1, Y1) points has N cells with almost
the same area.

R1 := Sample(Uniform(0, 1), N)^+:
R2 := Sample(Uniform(0, 1), N)^+:
T1 := Sample(Uniform(0, 2*Pi), N)^+:
T2 := Sample(Uniform(0, 2*Pi), N)^+:


X1 := sqrt~(R1) *~ cos~(T1):
Y1 := sqrt~(R1) *~ sin~(T1):
X2 := sqrt~(R2) *~ cos~(T2):
Y2 := sqrt~(R2) *~ sin~(T2):

ScatterPlot(X1, Y1, symbol=point);  # GOOD !

 

d := sqrt~((X1-X2)^~2 +(Y1-Y2)^~2):
Histogram(d)

 

 

 

Download Randomness_definitions.mw

_____________________________________________________________________________

I dont think it is possible to get an analytic expression of the PDF with Maple (I mean usingdirectly Statistics:-PDF).
Here is an excerpt from Lellouche & Souris which gives you the expression of this PDF

You can follow this paper step by step to try and get this result with Maple
_____________________________________________________________________________

A quite common approach in Statistics to build an analytic  approximation of a  PDF from raw data is to use tools like Edgeworth series, Burr distribution or, like I do in the attached file below, Pearson distribution.

PDF_analytic_approximation.mw

Here is the c omparison between the exact PDF (see excerpt above) and its Pearson approximation


You will see at the end that worksheet that Maple is not even capable to compute the expectation of the distance, which introduces a lot of doubt in its capability to find the PDF
_____________________________________________________________________________

@Rouben Rostamian:  I don't consider Maple's inability to compute the PDF as a bug, read the paper I cite above or watch the 1st and 4th videos I mention below to see how this PDF can be gotten almost by hand.
_____________________________________________________________________________

Here is a serie of 4 amazing videos which detail step by step (the last one being mesmerizing) how to prove the expectation of the distance of two random points in the unit disk (third randomness choice above) is 128/(45*Pi).

First point,
the correct syntax (Maple 2015) is

solve(identity(K1, xi), [A[0], A[1], A[2], B[1], B[2]])

(no braces around xi)

Second point,
K1 depends also on 4 more parameters: alpha, beta, c, mu.
So you expect [A[0], A[1], A[2], B[1], B[2]] to be function of them don't you?
It is highly likely that those functions, provided solve/identity has indeed a solution are very complex and it thus highly unlikely taht Maple will be capable to get them.

Workaround
I propose you a numeric workaround in which you first give alpha, beta, c, mu numeric values, then build N relations between A[0], A[1], A[2], B[1], B[2], each for a different value of xi (this mimics the identity(K1, xi) stuff), finally minimize them in the least squares sense.

Maybe this will not suit you? But I'm afraid it's this (maybe something close) or nothing else.

restart

with(PDEtools):

with(LinearAlgebra):

with(SolveTools):

undeclare(prime)

`There is no more prime differentiation variable; all derivatives will be displayed as indexed functions`

(1)

_local(gamma):

ode := beta*U(xi)^2*c^2+(-alpha*c^2+1)*U(xi)+mu^2*c^2*(diff(diff(U(xi), xi), xi)) = 0

beta*U(xi)^2*c^2+(-alpha*c^2+1)*U(xi)+mu^2*c^2*(diff(diff(U(xi), xi), xi)) = 0

(2)

n := 2

2

(3)

F := U(xi) = sum(tanh(xi)^(i-1)*(B[i]*sech(xi)+A[i]*tanh(xi)), i = 1 .. n)+A[0]

U(xi) = B[1]*sech(xi)+A[1]*tanh(xi)+tanh(xi)*(B[2]*sech(xi)+A[2]*tanh(xi))+A[0]

(4)

K1 := eval(ode, F)

beta*(B[1]*sech(xi)+A[1]*tanh(xi)+tanh(xi)*(B[2]*sech(xi)+A[2]*tanh(xi))+A[0])^2*c^2+(-alpha*c^2+1)*(B[1]*sech(xi)+A[1]*tanh(xi)+tanh(xi)*(B[2]*sech(xi)+A[2]*tanh(xi))+A[0])+mu^2*c^2*(B[1]*sech(xi)*tanh(xi)^2-B[1]*sech(xi)*(1-tanh(xi)^2)-2*A[1]*tanh(xi)*(1-tanh(xi)^2)-2*tanh(xi)*(1-tanh(xi)^2)*(B[2]*sech(xi)+A[2]*tanh(xi))+2*(1-tanh(xi)^2)*(-B[2]*sech(xi)*tanh(xi)+A[2]*(1-tanh(xi)^2))+tanh(xi)*(B[2]*sech(xi)*tanh(xi)^2-B[2]*sech(xi)*(1-tanh(xi)^2)-2*A[2]*tanh(xi)*(1-tanh(xi)^2))) = 0

(5)

solve(identity(K1, xi), [A[0], A[1], A[2], B[1], B[2]])

Warning,  computation interrupted

 

# Any analytic solution seems to be out of range.
#
# Here is a numeric workaround

randomize();
# randomize(173729404478144);  # A seed which give some IDsol values (see below)
# randomize(173729420578144);  # This one doesn't seem to give any (see below)

# Identify the "remaining" parameters

params := convert(indets(K1, name) minus {xi, A[0], A[1], A[2], B[1], B[2]}, list);
NP     := numelems(params):

# Define the function F(params)(xi) = lhs(K1)

F := unapply(unapply(lhs(K1), xi), params):

# Chose values for all parameters, for instance

X := [ seq(p = rand(0. .. 1.)(), p in params) ];

# Define the function Fp(xi) as the instance of F(params)(xi) forthose values

Fp := unapply(eval(F(params)(xi), X), xi):

# Randomly chose (for instance) N values of xi in some ad hoc range

N  := 100:
Xi := Statistics:-Sample(Uniform(0, 1), N):

# Compute the corresponding values of f(xi)

Y := Vector(N, n -> Fp(Xi[n])):

# Define the objective function to minize over A[0], ..., B[2]
# (ideally its minimum should ne 0, or somethong close)

Obj := Y^+ . Y:

# Minimize the objective function


interface(warnlevel = 0):

opt := Optimization:-NLPSolve(Obj);

# Plot the N residues agaist xi

plot(
  [ seq([Xi[n], eval(Y[n], opt[2])], n=1..N) ]
  , style=point
  , labels=[xi, "residue (should be 0)"]
  , labeldirections=[default, "vertical"]
  , title=typeset(evalf[4](X))
)

173729420578144

 

[alpha, beta, c, mu]

 

[alpha = .9364695393, beta = .1127828746, c = .8295135814, mu = .9551208268]

 

[0.164551129077846001e-2, [A[0] = HFloat(-0.2515499002096579), A[1] = HFloat(-1.331181289087155), A[2] = HFloat(0.010288244997440708), B[1] = HFloat(-0.2312944419813471), B[2] = HFloat(0.4525201303944428)]]

 

 

# Observing that Fp(xi) only depends on A[0], ..., B[2] on can try using solve/identity now:

IdSol := solve(identity(Fp(xi)=0, xi))

Warning,  computation interrupted

 

# Depending one the seed his would be a bad idea as shows the plot below

plot(eval(Fp(xi), IdSol[1]), xi=0..1)

 

# Evaluate Y for the first IdSol solution

plot(
  [ seq([Xi[n], eval(Y[n], IdSol[1])], n=1..N) ]
  , style=point
  , labels=[xi, "residue (should be 0)"]
  , labeldirections=[default, "vertical"]
  , title=typeset('Obj' = evalf[4](eval(Obj, IdSol[1])))
)

 

# My guess:
# There is no set of values for A[0], ..., B[2] which identically verifies K1
# for arbitrary values os alpha, beta, c, mu.


Download Find_params_mmcdara.mw

Find_params_mmcdara_larger_xi_range.mw  contains results obtained on a large xi range

The autocorrelation functionis "the" tool to detect periodicity or to extract the periodic component from a noisy signal.

Autocorrelation is acccessible from both SignalProcessing and Statistics packages, with little differences, but for sampled signals only. Meaning you don't copute the autocorrelation function itself but something which van be interpreted as its sampling (on a finite number of points).

The "continuous" correlation function of s signal S(t) doesn't seem to exist in my 2015 Maple version.
Generally it is computed by taking the inverse Fourier transform of the spectral power density of S(t) which is itself defined by
FS(xi) * conjugate(FS(xi)), where FS(xi)  is the Fourier transform of S(t).
inttrans package might help you to do this.
The issue is that a periodic signal as a discrete spectrum made of a finite set of Dirac distributions and so is its spectral power density function (it contains squares of Dirac(s))... a thing invfourier doesn't seem capable to handle.

So here is maybe a simple workaround that coukd answer your question: if inttrans:-fourier(S(t), t, xi)  is a linear combination of Dirac distribution, then S(t) is periodic.
This is already a first step.
The second step consists in identifyong the period: here is a notional example that could give you some hints:

restart

with(inttrans):

S := t -> cos(2*Pi*t/3)+cos(2*Pi*t/7)

proc (t) options operator, arrow; cos((2/3)*Pi*t)+cos((2/7)*Pi*t) end proc

(1)

# S(t) is periodic as it is a linear combination of Dirac distribution

F__S := unapply(fourier(S(t), t, xi), xi);  

proc (xi) options operator, arrow; Pi*(Dirac(xi+(2/3)*Pi)+Dirac(xi-(2/3)*Pi)+Dirac(xi-(2/7)*Pi)+Dirac(xi+(2/7)*Pi)) end proc

(2)

# Period

indets(F__S(xi), function);
op~(%);
denom~(eval(%, xi=0));

period := mul(%)/gcd(op(%))

{Dirac(xi-(2/3)*Pi), Dirac(xi-(2/7)*Pi), Dirac(xi+(2/3)*Pi), Dirac(xi+(2/7)*Pi)}

 

{xi-(2/3)*Pi, xi-(2/7)*Pi, xi+(2/3)*Pi, xi+(2/7)*Pi}

 

{3, 7}

 

21

(3)

plot(S(t), t=0..period)

 

pattern       := t -> piecewise(0 <= t and t <= period, S(t), 0):
periodization := unapply(pattern(t-floor(t/period)*period), t):

plot(periodization(t), t=0..period*3);

 

# The normalized autocorrelation function should be equal to 1 fot t=Z*period

# Autocorrelation with lag=0

A[0] := evalf(Int(periodization(t)*periodization(t), t=0..period)):

Normalized_A[lag=0] := A[0]/A[0];

# Autocorrelation with lag=period

Normalized_A[lag='period'] := evalf(Int(periodization(t)*periodization(t-period), t=0..period)) / A[0];

# Autocorrelation with lag=2*period

Normalized_A[lag=2*'period'] := evalf(Int(periodization(t)*periodization(t-2*period), t=0..period)) / A[0];

# Autocorrelation with lag=-period

Normalized_A[lag=-'period'] := evalf(Int(periodization(t)*periodization(t+period), t=0..period)) / A[0];

1.000000000

 

1.000000000

 

1.000000000

 

1.000000000

(4)
 

 

A more complete code with more cases (including the one above): Period_detection.mw

restart

kernelopts(version)

`Maple 2015.2, APPLE UNIVERSAL OSX, Dec 20 2015, Build ID 1097895`

(1)

sl10 :=  -1 <= (3-5*x)*(1/2) and (3-5*x)*(1/2) <= 9

0 <= 5/2-(5/2)*x and -(5/2)*x <= 15/2

(2)

sol_1 := solve(sl10)

RealRange(-3, 1)

(3)

convert(x in sol_1, relation)

And(-3 <= x, x <= 1)

(4)

sol_2 := solve({op(sl10)})

{-3 <= x, x <= 1}

(5)

simplify(And(op(sol_2)))

And(-3 <= x, x <= 1)

(6)

# Or use what I proposed you here


Download examples.mw

Technically f is a number and writing diff(f, something) is identically null.

Don't you mean "what is the variation delta(f) of f given a variation delta(q) of function q" ?

Look to this, maybe that will help you (or not)

variation.mw

The key code is 

# N = numelems(team):
# n = number of teammates per set
# T = list of sets lists

T := [seq(team[1+(i-1)*n..i*n], i=1..N/n)]:

restart

 

new_team := ["Michael K", "Andy C", "Michael G", "Mitch", "Jez", "Dean B", "Anthony B", "Rik B", "Ilya", "Fariborz", "Eugene", "Tania", "Bill", "Stevs", "Victor", "Jane", "Nash", "Ben"]:

 

MakeTeams := proc(team, n)
  local N, T, i, k, fmt;
  N := numelems(team):
  if irem(N, n) <> 0 then
    error cat("The number of players (", N, ") is not a multiple of the number (", n, ") of team members")
  end if:
  T := [seq(team[1+(i-1)*n..i*n], i=1..N/n)]:

  k   := numelems(convert(N/n, base, 10)):
  fmt := cat("set %", k, "d: %a\n"):
  for i from 1 to N/n do
    printf(fmt, i, T[i])
  end do:

  return T
end proc:

MakeTeams(new_team, 2):

set 1: ["Michael K", "Andy C"]
set 2: ["Michael G", "Mitch"]
set 3: ["Jez", "Dean B"]
set 4: ["Anthony B", "Rik B"]
set 5: ["Ilya", "Fariborz"]
set 6: ["Eugene", "Tania"]
set 7: ["Bill", "Stevs"]
set 8: ["Victor", "Jane"]
set 9: ["Nash", "Ben"]

 

 

newnew_team := ["Michael K", "Andy C", "Michael G", "Mitch", "Jez", "Dean B", "Anthony B", "Rik B", "Ilya", "Fariborz", "Eugene", "Tania", "Bill", "Stevs", "Victor", "Jane", "Nash", "Ben", "Malachi T", "R", "Sachin ", "Prakash Sn", "Graeme", "Nayu", "Martih", "Rickn", "Ahmed"]:

MakeTeams(newnew_team, 3):

set 1: ["Michael K", "Andy C", "Michael G"]

set 2: ["Mitch", "Jez", "Dean B"]
set 3: ["Anthony B", "Rik B", "Ilya"]
set 4: ["Fariborz", "Eugene", "Tania"]
set 5: ["Bill", "Stevs", "Victor"]
set 6: ["Jane", "Nash", "Ben"]
set 7: ["Malachi T", "R", "Sachin "]
set 8: ["Prakash Sn", "Graeme", "Nayu"]
set 9: ["Martih", "Rickn", "Ahmed"]

 


printf variant

MakeTeams_bis := proc(team, n)
  local N, T, i, k, fmt;
  N := numelems(team):
  if irem(N, n) <> 0 then
    error cat("The number of players (", N, ") is not a multiple of the number (", n, ") of team members")
  end if:
  T := [seq(team[1+(i-1)*n..i*n], i=1..N/n)]:

  k   := numelems(convert(N/n, base, 10)):
  fmt := cat("set %", k, "d: ", seq("%s, ", i=1..n-1), "%s\n");
  for i from 1 to N/n do
    printf(fmt, i, op(T[i]))
  end do:
  return T
end proc:

MakeTeams_bis(new_team, 2):
print():
MakeTeams_bis(newnew_team, 3):

set 1: Michael K, Andy C
set 2: Michael G, Mitch

set 3: Jez, Dean B
set 4: Anthony B, Rik B
set 5: Ilya, Fariborz
set 6: Eugene, Tania
set 7: Bill, Stevs
set 8: Victor, Jane
set 9: Nash, Ben

 

 

set 1: Michael K, Andy C, Michael G
set 2: Mitch, Jez, Dean B
set 3: Anthony B, Rik B, Ilya
set 4: Fariborz, Eugene, Tania
set 5: Bill, Stevs, Victor
set 6: Jane, Nash, Ben
set 7: Malachi T, R, Sachin
set 8: Prakash Sn, Graeme, Nayu
set 9: Martih, Rickn, Ahmed

 

`&rsquo;`

(1)


You can also build random teams this way

MakeRandomTeams := proc(TEAM, n)
  local team, N, T, i, k, fmt;
  team := combinat:-randperm(TEAM);
  N := numelems(team):
  if irem(N, n) <> 0 then
    error cat("The number of players (", N, ") is not a multiple of the number (", n, ") of team members")
  end if:
  T := [seq(team[1+(i-1)*n..i*n], i=1..N/n)]:

  k   := numelems(convert(N/n, base, 10)):
  fmt := cat("set %", k, "d: %a\n"):
  for i from 1 to N/n do
    printf(fmt, i, T[i])
  end do:
  return T
end proc:

MakeRandomTeams(new_team, 2):

set 1: ["Michael G", "Andy C"]
set 2: ["Nash", "Ilya"]
set 3: ["Anthony B", "Bill"]
set 4: ["Tania", "Stevs"]
set 5: ["Michael K", "Mitch"]
set 6: ["Rik B", "Victor"]
set 7: ["Dean B", "Jez"]
set 8: ["Ben", "Jane"]
set 9: ["Eugene", "Fariborz"]

 
 

 

Download teams_mmcdara.mw

x in RealRange(1, Open(4)):
convert(%, relation)
                    1 <= x < 4

If you realy want to get a single inequality when the interval contains +/- infinity you can use procedure rel below: 

rel := proc(RR)
  local r := convert(RR, relation);
  if has(r, infinity) then
    r := remove(has, [op(r)], infinity)[]
  end if:
  r
end proc:

RR := x in RealRange(1, Open(4));
rel(RR)

`in`(x, RealRange(1, Open(4)))

 

And(1 <= x, x < 4)

(1)

RR := x in RealRange(Open(2), Open(infinity));
rel(RR)

`in`(x, RealRange(Open(2), infinity))

 

2 < x

(2)

RR := x in RealRange(Open(-infinity), Open(-3));
rel(RR)

`in`(x, RealRange(-infinity, Open(-3)))

 

x < -3

(3)

RR := x in RealRange(2, 3);
rel(RR)

`in`(x, RealRange(2, 3))

 

And(2 <= x, x <= 3)

(4)
 

 

Download Enhanced_convert.mw

 

 

restart
f := X^2 + Y^2 - 1:
g := X - Y:
intersections := proc(P, Q, T)
  local ind, R, W, w:

  # check
  ind := indets({P, Q}):
  if not member(T, ind) then
    error cat(sprintf("%s%", T), " is not an indeterminate of {P, Q}")
  elif numelems(ind) = 1 then
    error cat("Only one indeterminate ", sprintf("%s%", op(ind)), " found, 2 needed")
  elif numelems(ind) > 2 then
    error "More than 2 indeterminates found: P and/or Q do not define plane curves"
  end if:

  R := resultant(P, Q, T);
  W := op(ind minus {T});
  
  w := solve(R, W);

  return W = {w}
end proc:
intersections(f, g, X)
                        /  1  (1/2)  1  (1/2)\ 
                  Y =  { - - 2     , - 2      }
                        \  2         2       / 

intersections(f, g, A)
Error, (in intersections) A is not an indeterminate of {P, Q}
intersections(f+A, g, X)
Error, (in intersections) More than 2 indeterminates found: P and/or Q do not define plane curves
intersections(X, X^2, X)
Error, (in intersections) Only one indeterminate X found, 2 needed


Note that
 

solve({f, g}):
allvalues(%);
 /    1  (1/2)      1  (1/2)\            /      1  (1/2)        1  (1/2)\ 
{ X = - 2     , Y = - 2      }    ,     { X = - - 2     , Y = - - 2      }
 \    2             2       /            \      2               2       / 

numelems([%])
                 2


Note: I don't know if you got this code from Mistral AI as you often does, but it's worth saying that a lot of Artificial Intelligences give stupid results specially when used blindly or not trained properly


@GFY @acer

@acer's answer is great, but here is another wayto answer your problem which seems to me more natural (IMO).

The idea is still to use events but in conjunction with option discrete_variables. (see the event help page for more details).
Basically one augment the differential system by two functions A(t) and B(t) (the "discrete variables", not defined from differential equations), each of them being aimed to represent one of the two envelopes.
Specific events are used to build A(t) and B(t).

odeplot can be used directly in the usual way to plot those functions, for instance:

odeplot(solu12, [t, A(t)], t=...)

saopinjifen1230_mmcdara.mw

It is worth mentioning that the computation time for dsolve (without range option) is 0.1 sec and that it takes only 2.5 sec to odeplot the result (40 times faster than @acer's solution).

Note that using the range option and the refine option in odeplot (which can be useful for a better representation of x(t) only) can dramatically increase these times.


Successive-zooms.pdf

As you see below (first figure)  A(t) and B(t), excepted for the early times, are stepwise functions.
This is different from what @acer gets (second figure)

 



Note that it would quite simple to transform "my" stepwise envelopes into piecewise linear ones

Let P a multidimensional parameter.
You have 

phis := {phin = Fn(G(xi), P) , n=1..7 }

and you want to solve the system 

{Fn(G(xi), P) = 0 , n=1..7 }

wrt to P.

To get P you use the command

unknowns := indets(rhs~(phis), name)

which indeed returns all the names P contains, but also the name (xi) of the independent variable G depends upon.
So the error you get:
Error, (in solve) cannot solve expressions with diff(G(xi), xi) for xi

To get rid of it write

unknowns := indets(rhs~(phis), name) minus {xi};   # this is the "true" P

Now you can compute COEFFS, which is a sequence of 16 solutions:

COEFFS := solve(rhs~(phis), unknowns)

whattype(COEFFS);
                            exprseq

 numelems([COEFFS]);
                               16

Some of them depend on G(xi), which might not (?) be suitable.
If you want to get rid of them execute

GfreeCOEFFS := remove(has, [COEFFS], xi):
numelems(%);
                               9

Remark:

phis contains 7 relations while the parameter vector P has dimension 16. Which mean that 9 parameters are likely to get arbitrary values.

Maybe a better way would be to solve the system  { Fn(G(xi), Q) = 0 n=1..7 } with Q being a subvector parameter of P with size  7.
Ideally you should chose the 7 parameters which are the most relevant to the use you have in mind.

and ifI understand corrrectly your problem, here is a solution (which is likely not optimal in terms of computation time nor memory use) .
It is fast for N=8 but I didn't checked it for much larger values of N.

Round_Robin_mmcdara.mw

Maple Worksheet - Error

Failed to load the worksheet /maplenet/convert/round_robin_mmcdara.mw .



 

4 5 6 7 8 9 10 Last Page 6 of 65