acer

32627 Reputation

29 Badges

20 years, 45 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@Geoff For that alternate input,

restart

n, k := 4, 2

4, 2

sys := {Tree = Union(Z, Prod(`$`(Tree, k)))}

all := combstruct:-allstructs([Tree, sys], size = n)

lists := eval(all, Prod = (proc () options operator, arrow; [args] end proc))

Groupings := proc(LI::{list,posint}, k::posint)
local L, Tree, Leaf, sys, n, lists, LTS;
if k = 1 then error "k must be greater than 1" end if;
if LI::posint then L:=$LI; n:=LI;
else L:=LI; n:=nops(L); end if;
LTS := proc(LL)
   local count := 0, F := proc() count:=count+1; L[count]; end proc;
   eval(subs(Leaf='F'(),LL));
end proc:
sys := {Tree = 'Union'(Leaf, 'Prod'(Tree $ k)), Leaf = 'Atom'};
lists := eval(combstruct['allstructs']([Tree, sys], 'size' = n), 'Prod' = (()->[args]));
map(LTS, lists);
end proc:

 

Groupings([a, b, c, d], 2);

[[a, [b, [c, d]]], [a, [[b, c], d]], [[a, b], [c, d]], [[a, [b, c]], d], [[[a, b], c], d]]

Groupings([1, 2, 3, 4], 2)

[[1, [2, [3, 4]]], [1, [[2, 3], 4]], [[1, 2], [3, 4]], [[1, [2, 3]], 4], [[[1, 2], 3], 4]]

Groupings(4, 2)

[[1, [2, [3, 4]]], [1, [[2, 3], 4]], [[1, 2], [3, 4]], [[1, [2, 3]], 4], [[[1, 2], 3], 4]]

Download Groupings_ac4.mw

@Geoff Change the type specification of the L parameter (in the definition of procedure Groupings) to L::list instead, so it'll look like,

   Groupings := proc(L::list, k::posint)
      ...
   end proc:

@Motocycle Mayor A reasonable first step would be to attach an Excel data file that could be used with your Import command and which creates a representative example that reproduces the problem.

Uploading and attaching an Excel file and .mw Maple worksheet that can be used together to reproduce the problem is often a very good first step here.

In the absence of an actual worksheet it is more difficult for me to determine the cause, eg. whether Data is actually a DataFrame, etc.

Mentioning your Maple version (or marking it in the field at the top of your Question) might also be useful. Are you still using Maple 2019?

Could you please attach an Excel data file and the Import command which creates a representative example that illustrates the problem? You can use the green up-arrow in the Reply editor, to upload and insert links to files.

Are you sure that the entries of the column are all strings already? Have you tried,

   SubsDatatype(Data, "UN Region", string, conversion=String );

@dharr I suppose this is simpler still, having F insert indexed references to L.

restart

n, k := 4, 2

4, 2

Define trees with k branches from each node. Z here is a leaf on the tree.

sys := {Tree = Union(Z, Prod(`$`(Tree, k)))}

Find all possibilities

all := combstruct:-allstructs([Tree, sys], size = n)

Convert the Prod(...) to [...]

lists := eval(all, Prod = (proc () options operator, arrow; [args] end proc))

Groupings:=proc(L::list(symbol),k::posint)
local Tree,Leaf,sys,n:=nops(L),lists,LTS;
if k=1 then error "k must be greater than 1" end if;
LTS:=proc(LL)
   local count:=0,F:=proc() count:=count+1;L[count];end proc;
   eval(subs(Leaf='F'(),LL));
end proc:
sys:={Tree='Union'(Leaf,'Prod'(Tree $ k)),Leaf='Atom'};
lists:=eval(combstruct['allstructs']([Tree,sys],'size'=n),'Prod'=(()->[args]));
map(LTS,lists);
end proc:

Groupings([a, b, c, d], 2)

[[a, [b, [c, d]]], [a, [[b, c], d]], [[a, b], [c, d]], [[a, [b, c]], d], [[[a, b], c], d]]

Download Groupings_accc.mw

@janhardo That's nice. It perhaps shares the theme of my 6) using eliminate, or 1).

You could even do it as the shorter,

   simplify(F2, {eq}, [p1])

@dharr For fun,

restart

n, k := 4, 2

4, 2

Define trees with k branches from each node. Z here is a leaf on the tree.

sys := {Tree = Union(Z, Prod(`$`(Tree, k)))}

Find all possibilities

all := combstruct:-allstructs([Tree, sys], size = n)

Convert the Prod(...) to [...]

lists := eval(all, Prod = (proc () options operator, arrow; [args] end proc))

Groupings := proc(L::list(symbol), k::posint)
local Tree, Leaf, sys, n:=nops(L), lists, LTS, G:=Equate([$n],L);
if k = 1 then error "k must be greater than 1" end if;
LTS := proc(LL)
   local count := 0, F := proc() count:=count+1; end proc;
   eval(eval(subs(Leaf='F'(),LL)),G);
end proc:
sys := {Tree = 'Union'(Leaf, 'Prod'(Tree $ k)), Leaf = 'Atom'};
lists := eval(combstruct['allstructs']([Tree, sys], 'size' = n), 'Prod' = (()->[args]));
map(LTS, lists);
end proc:

Groupings([a, b, c, d], 2)

[[a, [b, [c, d]]], [a, [[b, c], d]], [[a, b], [c, d]], [[a, [b, c]], d], [[[a, b], c], d]]

Download Groupings_ac.mw

If you'd rather not substitute bare [1,2,3,4]=[a,b,c,d] then you could instead do it with [X[1],X[2],X[3],X[4]]=[a,b,c,d] where X is another local. Groupings_acc.mw

@janhardo If you assign to name B12 then it's awkward to get a result that is expressed in just the name B12.

That's why I used InertForm above (as one of several ways to get around the fact that you'd assigned to that name...).

If instead you start with an equation involving B12 then there are a few ways, eg.,

restart;

eq := B12 = -6*(p1 + p2)/(p1 - p2)^2;

B12 = -6*(p1+p2)/(p1-p2)^2

F2 := (theta1*theta2*p1^2 + (-2*p2*theta1*theta2 - 6)*p1
      + theta1*theta2*p2^2 - 6*p2)/(p1 - p2)^2:

 

1)
evala(eval(F2,isolate(eq,p1)));

theta1*theta2+B12

 

alteq1 := isolate(eq,denom(eval(B12,eq)));

(p1-p2)^2 = -(6*p1+6*p2)/B12

2)
simplify(algsubs(alteq1, numer(F2))/subs(alteq1, denom(F2)));

theta1*theta2+B12

alteq2 := map[2](`/`,1,isolate(eq,denom(eval(B12,eq))));

1/(p1-p2)^2 = -B12/(6*p1+6*p2)

3)
simplify(subs(alteq2,algsubs(alteq1, F2)));

theta1*theta2+B12

4)
eval(collect(F2,[theta1],normal), (rhs=lhs)(eq));

theta1*theta2+B12

5)
eval(Ans,solve({Ans=F2,eq},{Ans,p1,p2}));

theta1*theta2+B12

6)
eval(Ans,eliminate({Ans=F2,eq},{Ans,p1})[1]);

theta1*theta2+B12

Download janh_03.mw

@michele Here are two ways to overlay them, with black&white, using either the float or 1..255 values.

Mat_bg_bw2.mw

which gives, for the plotted way,

or,

If I install the Maple 2024 Physics package update then the original attachment seems to work ok.

That is, in a separate Worksheet I issued the command,

   PackageTools:-Install("5137472255164416", version = 1852, overwrite);

and then I reopened the original worksheet, and ran it:

derivativve_ac.mw

@michele Sorry, I don't understand what you mean by "compare".

@janhardo It's now very unclear what your actual question is.

State clearly what input you do already have in your situation, and what you want to achieve with it.

Perhaps you are trying to ask whether you can somehow substitute for B12 in F2?

Or maybe even something(?) like this,

restart;

 

B12 := -6*(p1 + p2)/(p1 - p2)^2:

F2 := (theta1*theta2*p1^2 + (-2*p2*theta1*theta2 - 6)*p1
      + theta1*theta2*p2^2 - 6*p2)/(p1 - p2)^2:

 

simplify( F2 - B12 );

theta1*theta2

You can always both add and subtract something...

simplify( F2 - B12 ) + InertForm:-Display('B12');

theta1*theta2+Typesetting:-mi("B12")

Download janh_02.mw

If (as now it might seem) you'd be content with a plot then another choice for getting it in black and white is:

restart;

with(LinearAlgebra):

M:=1/255*RandomMatrix(8,generator=0..255):

 

plot(background=Array(M,datatype=float[8]),
     size=[400,400],axes=none);

 

Download Mat_bg_bw.mw

@Alfred_F The odeplot command can handle compound expressions involving the dependent functions.

See the second bullet point in the Description section of the Help page of the odeplot command.

restart

eq1 := diff(r(t), t)+1+cos(`ϕ`(t)) = 0

eq2 := diff(`ϕ`(t), t)+1-sin(`ϕ`(t))/r(t) = 0

ics := r(0) = 2.0, `ϕ`(0) = Pi/(1.5)

soln := dsolve({eq1, eq2, ics}, {r(t), `ϕ`(t)}, numeric)

"x(t):=r(t)*cos(`ϕ`(t)+t)+sin(t):"

"y(t):=r(t)*sin(`ϕ`(t)+t)-cos(t):"

plots:-odeplot(soln, [x(t), y(t)], t = 0 .. 20, labels = [x, y])

plots:-odeplot(soln, [x(t), y(t)], t = 0 .. 20, labels = [Typesetting:-Typeset(x(t)), Typesetting:-Typeset(y(t))])

Download test_12_ac.mw

note: The names r and phi are not assigned, just because they are part of a returned dsolve,numeric solution. So the calls r(t) and phi(t) don't mean anything to other commands like plot, etc. They mean something to odeplot because the assigned result was assigned to name soln and gets passed in as its first argument. (It is possible to extract operators individually from a certain flavour of dsolve,numeric call. And such could be used subsequently. But plotting such is often less efficient, eg. due to duplicated re-computation for later t-values. The odeplot command knows how to do it efficiently.)

Your code's primary mistake is in testing against NULL for the case that fsolve doesn't succeed.

More often fsolve will return unevaluated in such a failing case, and a better test would be to check either that the result were a list/set of type name=numeric quantities, or that the result were an unevaluated fsolve call. If you do the latter (as member sand15/mmcdara does in his Answer) it'd be faster if you prevented full evaluation of the result, eg. testing against eval(result,1) if done at the top-level.

But it's not clear what are your requirements. If parameters M, q, and tau can all vary then you should tell use exactly what range they are allowed to take. (You mentioned M varying, but didn't give use a range for that.) Also, how small a positive x value would you accept? And so on.

Also, you might need to guard against the situation that the lhs of either equation becomes complex-valued, say when the value inside a sqrt becomes negative. You might need to deal whether x<=M^2/2, say.

And it's not yet clear whether your two expressions (lhs of your eq1 and eq2) ever become positive, or could get arbitrarily close to zero (ie. whether a true root exists) within your full set of ranges. If not, then how small a residual are you willing to accept as representing a solution? And in such a scenario, setting this up as an optimization problem could be more productive.

Could you supply all these details?

2 3 4 5 6 7 8 Last Page 4 of 597