## dharr

Dr. David Harrington

## 5968 Reputation

19 years, 295 days
University of Victoria
Professor or university staff

## Social Networks and Content at Maplesoft.com

I am a professor of chemistry at the University of Victoria, BC, Canada, where my research areas are electrochemistry and surface science. I have been a user of Maple since about 1990.

## variation...

Here's a variation on @Ronan's answer.

 > restart;
 > for n to 4 do    A[n]:=Matrix(n,n,(i,j)->local m;                            ifelse(i+j

## bug reporting...

I agree with your analysis, and that it is a bug. To report it, you can (logged into Mapleprimes) choose the "more" tab, and then "submit software change request". I usually copy the mapleprimes link and paste that in the box where you are asked for any further information.

I don't know the specific answer to question 1. If you extend to Gamma negative you don't see a region. Anyway, as you say, it gives the correct number of solutions in the different regions shown. Other explanations below.

 > restart;

Here @acer's analysis

 > Eq := -8*(rho + 1)^4*Lambda^4 + 12*(rho + 1)^3*Gamma*(rho - 1)*Lambda^3 - 5*(rho + 1)^2*(-4/5 + Gamma^2*rho^2 + 2*(-2/5 - Gamma^2)*rho + Gamma^2)*Lambda^2 - 4*(rho + 1)*Gamma*(rho^2 - 1)*Lambda + Gamma^2*(rho + 1)*(rho - 1)^2;

 > with(RootFinding:-Parametric):
 > m := CellDecomposition([Eq=0, Lambda>0, Gamma>0, rho>-1, rho<1], [Lambda]):
 > CellPlot(m, samplepoints, view=[0..10,-2..2], size=[400,300]);

Number of solutions in regions 1..5

 > NumberOfSolutions(m)[1..5];

The chosen sample points within the region (as shown on the plot)

 > m:-SamplePoints;

Value of Lambda at sample point 2

 > SampleSolutions(m,2);

 > SampleSolutions(m,3);

The plot3d that I think you are worried about. For the region Lambda>0, there is everywhere a solution (the top sheet), in agreement with the analysis above that shows 1 real solution in regions 2and 3

 > plot3d([allvalues(RootOf(Eq,Lambda))],rho=-1..1,Gamma=0..5, grid = [20,20]);

 >

## No...

If you mean multiply by some function of the variables then the answer is no. The answer is somehow "closer" if you change the red k/2 to -k/2. What are the assumption on k? If one is allowed to multiply by matrices, then the answer might be different. (Matrices not showing correctly on Mapleprimes.

 >
 >
 >

 >

To get the off diagonals of L to be those of X, we need to multiply by

 >

 >

Diagonals have different sums, so cannot be the same.

 >

 >

## PolynomialSystem...

SolveTools:-PolynomialSystem with engine=triade can solve this. PolynomialSystems allows choice of different engines, one of which is groebner, so you can experiment if it gets stuck.

solve_test.mw

## ListTools:-Categorize...

To find the non-somorphic ones I use ListTools:-Categorize. I think IsIsomorphic already uses canonical labelling internally anyway, so is not required explicitly.

 > restart;
 > with(GraphTheory):
 > graph_list := [GraphTheory:-CompleteGraph(3), GraphTheory:-PathGraph(3),Graph({{a,b},{b,c},{c,a}})]:
 > classes:=[ListTools:-Categorize(IsIsomorphic,graph_list)];

Take first one from each class

 > nonisomorphic:=map2(op,1,classes);

If you would like them generically labelled (vertices 1,2,etc) then (or this could be done on the original list)

 > map(G->Graph(op(4,G)),nonisomorphic);

 >

## missing derivatives...

It's hard to know what form linjeelementer expects for an ODE, but if I assume it's the standard Maple form, then the error message is clear - you have given a differential equation without a derivative. Probably what you have given is the growth rate diff(y(t),t) so then you want

`ODE := diff(y(t), t) = -0.000032229*y(t)^2 + 0.065843*y(t) - 15.103`

## complete algorithm...

Here's a complete algorithm, assuming I've understood your objective correctly. Your C and C' can just be combined into a single combined C that I deal with - the counts for C={1}, C'={2,3,4} are the same as for C={1,2}, C'={3,4}, so I just count {1,2,3,4}.

Each row and column-choice combination is a pattern for which a count is recorded, so there are no unsuccessful searches.

Older version:

Edit: new much faster version takes advantage of the fact that there are many duplicate rows. Now L=10 can be done in about a second on my machine:

 > restart;
 > N := 10^5: L := 5: M := LinearAlgebra:-RandomMatrix(N, L, generator=0..1):

All subsets that can be C union C' with C, C' disjoint and nonempty

 > Lset:={\$1..L}: cs:=[map(convert,combinat:-powerset(L) minus {{},Lset,seq({i},i=1..L)},list)[]];

Procedure that counts the possibilities for the matrix M and the column choices in cs.

 > count := proc(M, cs);         local counts, C, n, N, P, row, MT, nrows;         N := upperbound(M)[1];         # prescan Matrix for duplicate rows and count them         MT := table('sparse'):         for n to N do                 row := [seq(M[n])];                 MT[row]++;         end do:         counts := table('sparse');         for row, nrows in eval(MT) do                 for C in cs do                         P := row[C];                         counts[P, C] += nrows;                 end do;         end do;         eval(counts); end proc:
 > counts := CodeTools:-Usage(count(M, cs)):

memory used=56.16MiB, alloc change=5.00MiB, cpu time=47.00ms, real time=145.00ms, gc time=15.62ms

How many times does the pattern [1,1,0] occur in columns [1, 2, 4]?

 > counts[[1,1,0], [1,2,4]];

Total counts in all cases

Try L=10;

 > N := 10^5: L := 10: M := LinearAlgebra:-RandomMatrix(N, L, generator=0..1):
 > Lset := {\$1..L}: cs := [map(convert,combinat:-powerset(L) minus {{},Lset,seq({i},i=1..L)},list)[]]: nops(cs);

 > counts := CodeTools:-Usage(count(M, cs)):

memory used=168.70MiB, alloc change=24.18MiB, cpu time=765.00ms, real time=1.10s, gc time=78.12ms

 > counts[[1,0,1,0,1], [1,4,5,6,9]];

 >

2015 compatible version:
mmcdara8a.mw

## analytical solution...

An accurate analytical solution for approximate (floating point) coefficients varying over many orders of magnitude is unlikely, so it would be better if you entered the system using rationals (from which the floating values presumably came). Maple begins by converting the floating point values to rationals, but an analytical solution can then be obtained using method = laplace.

## gfun...

Here is your sin(x^2) example, using guessgf directly when no odes are involved.

 > restart;
 > convert(series(sin(x^2),x,40),polynom); cofs:=[seq(coeff(%,x,i),i=0..39)];

 > gfun:-guessgf(cofs,x);

 >

 >
 >

 >

 >

## sequentially...

Yes, you need to do them sequentially - the help page warns it won't work doing them together in one alias command.

alias_in_alias.mw

## rho and rho__v...

I changed the rho's in the solution to rho__v's (as in the Eqs) and it worked.
solution_check.mw

## Solve for three variables....

I agree with Carl. Perhaps the following helps to illustrate the point.

 >
 >

 >

 >

We want to find when Q = N for any u. Since doubling the a's can be compensated for by halving the b's we can fix the scale by arbitrarily choosing a value for b[0], say 1. Or we can just write the solution for the other variables in terms of b[0]. Since we have 3 equations in 6 unknowns, we can extend this logic to another two variables aside from b[0], i.e., as @Carl Love noted we need to choose three variables to solve for in terms of the other three. For example, the following gives a[1], a[2] and b[2] in terms of the other 3. (Solve/identity is just a shortcut for the 3 equations equating the coefficients.

 >

Suppose we give a 4th variable to solve for - now we see the solution contains b[0] = b[0], meaning we can choose b[0] arbitrarily, the others are as above.

 >

In this case, Maple chose to make a[1] arbitrary; we get the same as if we had chosen a[2], b[1] and b[2] to solve for.

 >

 >

## from eqns to Matrix...

I made the opposite assumption to @acer (that you started with the equations), and kept implicitplot butdid them all in one, which is simple here despite the inefficiency.

 >

 >

Define the equations to solve and plot

 >

Convert to the corresponding Matrix of coefficients and Vector (because we shouldn't have to enter equivalent information twice, and less likely to make a mistake)

 >

 >

We can do all equations in one implicitplot. (I like the brighter colors, so I left the quotes off.)

 >

 >