emendes

375 Reputation

6 Badges

6 years, 210 days

MaplePrimes Activity


These are questions asked by emendes

Hello

I am trying to use Threads in my procedures as much as possible.  However, one of them returned different results when compared to map or Grid:-Map (I have checked if the used functions are threadsafe (perhaps I miss something)).  Here is the procedure (optimization of the code is most welcome).

searchMonomialsEqns:=proc(conds::set,Eqns::list,Vars::list,poolofeqns::list(list))
description "Find if a set of monomials in an equation can be found in a pool of monomials and returns the condition when it is true":
local A:=Array(1..0),
      C,
      i,
      res,
      n:=numelems(Eqns):
#  Find the monomials of Eqns
res:=subs(conds,Eqns):
for i from 1 to n do
    C:= coeffs(expand(lhs(res[i])-rhs(res[i])),Vars, 'M'):
    A,={M}:
end do:
ifelse(member([seq(A)],poolofeqns)=false,NULL,conds):
end proc:

1) Threads:-Map

ans1:=CodeTools:-Usage(Threads:-Map(w->searchMonomialsEqns(w,eqns[1..2],vars[2..3],validYZeqnMon),conds5)):nops(ans1);

returns

memory used=0.58GiB, alloc change=139.56MiB, cpu time=40.23s, real time=11.12s, gc time=1.01s

                              8613

 

2) map

ans2:=CodeTools:-Usage(map(w->searchMonomialsEqns(w,eqns[1..2],vars[2..3],validYZeqnMon),conds5)):nops(ans2);

returns

memory used=0.57GiB, alloc change=-4.00MiB, cpu time=22.48s, real time=21.55s, gc time=1.70s

                              8637

3) Grid:-Map

ans3:=CodeTools:-Usage(Grid:-Map(w->searchMonomialsEqns(w,eqns[1..2],vars[2..3],validYZeqnMon),conds5)):nops(ans3);

return

memory used=23.29MiB, alloc change=21.88MiB, cpu time=3.77s, real time=2.25s, gc time=3.14s

                              8637

Although the number of elements is the same, Grid:-Map returns the result with set function mentioned in my previous post. (I am aware that CodeTools:-Usage is pointless here).

4) Threads:-Seq

ans4:=CodeTools:-Usage([Threads:-Seq](searchMonomialsEqns(conds5[i],eqns[1..2],vars[2..3],validYZeqnMon),i=1..nops(conds5))):nops(ans4);

returns

memory used=0.58GiB, alloc change=0 bytes, cpu time=33.99s, real time=8.68s, gc time=644.74ms

                              8622

What am I missing?   

Many thanks

Ed

 

Hello

I have no choice but use Grid:-Map and Grid:-Seq in my calculations due to the size of them.  Here is a very small example that is puzzling me (Perhaps I did something really silly and did not realize). 

ansa:=CodeTools:-Usage(Grid:-Map(w->CondswithOnesolutionTest(w,eqns,vars,newvars,tlim),conds5s)):

with the following result:

ansa:=set([{alpha[1, 1] = 0, alpha[1, 2] = 0, alpha[1, 3] = 0, alpha[1, 4] = 0, alpha[1, 5] = 0, alpha[1, 6] = 0, alpha[1, 8] = 0, alpha[1, 9] = 0, alpha[2, 0] = 0, alpha[2, 1] = 0, alpha[2, 2] = 0, alpha[2, 4] = 0, alpha[2, 5] = 0, alpha[2, 7] = 0, alpha[2, 8] = 0, alpha[2, 9] = 0, alpha[3, 0] = 0, alpha[3, 1] = 0, alpha[3, 2] = 0, alpha[3, 3] = 0, alpha[3, 4] = 0, alpha[3, 6] = 0, alpha[3, 7] = 0, alpha[3, 8] = 0, alpha[3, 9] = 0}, {}, {}, {}, {}, {}], [{}, {}, {}, {}, {}, {alpha[1, 1] = 0, alpha[1, 2] = 0, alpha[1, 3] = 0, alpha[1, 4] = 0, alpha[1, 5] = 0, alpha[1, 6] = 0, alpha[1, 8] = 0, alpha[1, 9] = 0, alpha[2, 0] = 0, alpha[2, 1] = 0, alpha[2, 2] = 0, alpha[2, 4] = 0, alpha[2, 5] = 0, alpha[2, 7] = 0, alpha[2, 8] = 0, alpha[2, 9] = 0, alpha[3, 0] = 0, alpha[3, 1] = 0, alpha[3, 2] = 0, alpha[3, 3] = 0, alpha[3, 5] = 0, alpha[3, 6] = 0, alpha[3, 7] = 0, alpha[3, 8] = 0, alpha[3, 9] = 0}], [{alpha[1, 1] = 0, alpha[1, 2] = 0, alpha[1, 3] = 0, alpha[1, 4] = 0, alpha[1, 5] = 0, alpha[1, 6] = 0, alpha[1, 8] = 0, alpha[1, 9] = 0, alpha[2, 0] = 0, alpha[2, 1] = 0, alpha[2, 2] = 0, alpha[2, 4] = 0, alpha[2, 5] = 0, alpha[2, 7] = 0, alpha[2, 8] = 0, alpha[2, 9] = 0, alpha[3, 0] = 0, alpha[3, 1] = 0, alpha[3, 3] = 0, alpha[3, 4] = 0, alpha[3, 5] = 0, alpha[3, 6] = 0, alpha[3, 7] = 0, alpha[3, 8] = 0, alpha[3, 9] = 0}, {}, {}, {}, {}, {}], [{}, {}, {}, {}, {}, {alpha[1, 1] = 0, alpha[1, 2] = 0, alpha[1, 3] = 0, alpha[1, 4] = 0, alpha[1, 5] = 0, alpha[1, 6] = 0, alpha[1, 8] = 0, alpha[1, 9] = 0, alpha[2, 0] = 0, alpha[2, 1] = 0, alpha[2, 2] = 0, alpha[2, 4] = 0, alpha[2, 5] = 0, alpha[2, 7] = 0, alpha[2, 8] = 0, alpha[2, 9] = 0, alpha[3, 0] = 0, alpha[3, 2] = 0, alpha[3, 3] = 0, alpha[3, 4] = 0, alpha[3, 5] = 0, alpha[3, 6] = 0, alpha[3, 7] = 0, alpha[3, 8] = 0, alpha[3, 9] = 0}])

The same thing but now using only map

ansb:=CodeTools:-Usage(map(w->CondswithOnesolutionTest(w,eqns,vars,newvars,tlim),conds5s)):
ansb:={[{}, {}, {}, {}, {}, {alpha[1, 1] = 0, alpha[1, 2] = 0, alpha[1, 3] = 0, alpha[1, 4] = 0, alpha[1, 5] = 0, alpha[1, 6] = 0, alpha[1, 8] = 0, alpha[1, 9] = 0, alpha[2, 0] = 0, alpha[2, 1] = 0, alpha[2, 2] = 0, alpha[2, 4] = 0, alpha[2, 5] = 0, alpha[2, 7] = 0, alpha[2, 8] = 0, alpha[2, 9] = 0, alpha[3, 0] = 0, alpha[3, 1] = 0, alpha[3, 2] = 0, alpha[3, 3] = 0, alpha[3, 5] = 0, alpha[3, 6] = 0, alpha[3, 7] = 0, alpha[3, 8] = 0, alpha[3, 9] = 0}], [{}, {}, {}, {}, {}, {alpha[1, 1] = 0, alpha[1, 2] = 0, alpha[1, 3] = 0, alpha[1, 4] = 0, alpha[1, 5] = 0, alpha[1, 6] = 0, alpha[1, 8] = 0, alpha[1, 9] = 0, alpha[2, 0] = 0, alpha[2, 1] = 0, alpha[2, 2] = 0, alpha[2, 4] = 0, alpha[2, 5] = 0, alpha[2, 7] = 0, alpha[2, 8] = 0, alpha[2, 9] = 0, alpha[3, 0] = 0, alpha[3, 2] = 0, alpha[3, 3] = 0, alpha[3, 4] = 0, alpha[3, 5] = 0, alpha[3, 6] = 0, alpha[3, 7] = 0, alpha[3, 8] = 0, alpha[3, 9] = 0}], [{alpha[1, 1] = 0, alpha[1, 2] = 0, alpha[1, 3] = 0, alpha[1, 4] = 0, alpha[1, 5] = 0, alpha[1, 6] = 0, alpha[1, 8] = 0, alpha[1, 9] = 0, alpha[2, 0] = 0, alpha[2, 1] = 0, alpha[2, 2] = 0, alpha[2, 4] = 0, alpha[2, 5] = 0, alpha[2, 7] = 0, alpha[2, 8] = 0, alpha[2, 9] = 0, alpha[3, 0] = 0, alpha[3, 1] = 0, alpha[3, 2] = 0, alpha[3, 3] = 0, alpha[3, 4] = 0, alpha[3, 6] = 0, alpha[3, 7] = 0, alpha[3, 8] = 0, alpha[3, 9] = 0}, {}, {}, {}, {}, {}], [{alpha[1, 1] = 0, alpha[1, 2] = 0, alpha[1, 3] = 0, alpha[1, 4] = 0, alpha[1, 5] = 0, alpha[1, 6] = 0, alpha[1, 8] = 0, alpha[1, 9] = 0, alpha[2, 0] = 0, alpha[2, 1] = 0, alpha[2, 2] = 0, alpha[2, 4] = 0, alpha[2, 5] = 0, alpha[2, 7] = 0, alpha[2, 8] = 0, alpha[2, 9] = 0, alpha[3, 0] = 0, alpha[3, 1] = 0, alpha[3, 3] = 0, alpha[3, 4] = 0, alpha[3, 5] = 0, alpha[3, 6] = 0, alpha[3, 7] = 0, alpha[3, 8] = 0, alpha[3, 9] = 0}, {}, {}, {}, {}, {}]}

(This is what I expected as the result).

 

Why did Grid:-Map add set to the answer?  What am I missing?  

 

Many thanks

 

Hello

I need to detect if different expressions contain a radical. For example

aaa := X3*(alpha[2, 8]*(sqrt(X2/alpha[1, 7])*alpha[3, 8] + X1*alpha[3, 6])*X2 + X3*(alpha[2, 8] + alpha[3, 9]/2))/(X2*alpha[2, 8])

As can be noticed there is a square root in the expression.   

I have tried type(expr,sqrt) and has but to no avail. (I am not sure if I use them as they should though).   

Many thanks

 

Ed

 

Hello

Since this is my first attempt to use plots[animate], please forgive if my question is silly.  

I want to use plots[animate] with RootLocusPlot to show the effect of variable.   Here is my attempt.

num:=10*(s+alpha);den:=s*(s^2+4*s+8);
plots[animate](RootLocusPlot,[NewSystem(subs(alpha=a,num/den))],a=1..10);

Of course, when issuing the commands, an error comes out:  

Error, (in plots/animate) symbolic value(s) in model: a
 

  • Although I could define sys using NewSystem with a symbolic value, alpha, I have no idea how to assign a value for alpha.  subs(alpha=2,..) does not seem to work.
  • If I remove the square brackets in the second argument of plots[animate], a different msg comes out.  Why do I need (or not) them? 

Many thanks.

 

Hello

I am trying to reproduce a simple result from Linear Control Theory using Laplace Transform.  Here are the steps:

assume(omega>0);assume(zeta>0 and zeta<1);
tf:=omega^2/(s^2+2*zeta*omega*s+omega^2);
y:=tf*1/s;
yt:=inttrans:-invlaplace(y,s,t);
dyt:=diff(yt,t);

So far, so good.  Now I need to find the values of t (time) such that the dyt=0.  

 

solve(dyt=0,t);

but Maple returns only the trivial solution, that is, zero.   How can I find the next one (Tp - peak time = Pi/(omega*sqrt(1-zetaˆ2)))?  

 

Many thanks

 

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