acer

32557 Reputation

29 Badges

20 years, 24 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@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?

@Jacobegerup Your attachment doesn't contain input exactly like your image. It's not clear which output(s) in it are presenting you with a similar issue. You should explain where the problem is, explicitly.

@Jacobegerup Could you upload and attach your Document (.mw file), using the green up-arrow in the Mapleprimes response editor's toolbar?

I don't know what version of Maple you're using.

But what happens if you use the name mass instead of m, for the assignment of 142g ?

@salim-barzani Sure you could do that in several different ways. For example,

plots:-display(seq(plot(last[2], l = -1 .. 1,
                        legend = typeset(`#mn("a");`=a)),
                   a = 0.3 .. 1, 0.1),
               legendstyle = [location = right]);

or just,

plot([seq(last[2], a = [0.3, 0.5, 1.0])], l = -1 .. 1);

etc. You can, of course, change those to other values of a. Or you could use other colors.

If you'd like those curves as contours on the 3D surface then that's possible in several ways. You haven't specifically asked about that, though.

If those aren't exactly what you're after then you're out of luck with me since you've now posted five times in this Question thread without properly and exactly explaining what you're after.

1 2 3 4 5 6 7 Last Page 3 of 595