acer

32313 Reputation

29 Badges

19 years, 312 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@minhthien2016 What do you mean when you say, "I have 100 expressions"?

Where are they? How are they stored?

You haven't said how/where they are, or how they get created, or how it is that you "have" them.

So, in the absence of that important detail, how would we be able to best tell you how to form a list from them?

@minhthien2016 Yes. And handling such a list was shown before, except I didn't actually assign the list to name L.

exp1 :=  x^3 - (-3*m + 1)*x^2 + (-4*m - 3)*x:

exp2 := x^3 - (-m - 1)*x^2 - (-4*m - 3)*x:

L := [exp1, exp2];

[x^3-(-3*m+1)*x^2+(-4*m-3)*x, x^3-(-m-1)*x^2-(-4*m-3)*x]

map~(normal, L);

[x^3+(3*m-1)*x^2-(4*m+3)*x, x^3+(m+1)*x^2+(4*m+3)*x]

Download sgn_ex4.mw

I didn't see it before, but all these given examples (including the list of such expressions) can be handled with this same terse approach:

exp1 :=  x^3 - (-3*m + 1)*x^2 + (-4*m - 3)*x;

x^3-(-3*m+1)*x^2+(-4*m-3)*x

exp2 := x^3 - (-m - 1)*x^2 - (-4*m - 3)*x;

x^3-(-m-1)*x^2-(-4*m-3)*x

map(normal, exp1);

x^3+(3*m-1)*x^2-(4*m+3)*x

map(normal, exp2);

x^3+(m+1)*x^2+(4*m+3)*x

 

And now the list,

 

map~(normal, [exp1, exp2]);

[x^3+(3*m-1)*x^2-(4*m+3)*x, x^3+(m+1)*x^2+(4*m+3)*x]

 

Another example, for fun,

 

exp3 := x^3 - (-3*m + 1)*x^2 + (-4*m - 3)*(-y - 1)*(1 - w)*x;

x^3-(-3*m+1)*x^2+(-4*m-3)*(-y-1)*(1-w)*x

map(normal, exp3);

x^3+(3*m-1)*x^2-(4*m+3)*(y+1)*(-1+w)*x

 

And the map~ syntax could even be used for the singleton
expressions, if you'd prefer the coding consistency. Eg,

 

map~(normal, exp1);

x^3+(3*m-1)*x^2-(4*m+3)*x

Download sgn_ex3.mw

@minhthien2016 The technique I showed above can be used with a list of such expressions by simply utilizing map~ the elementwise operator form of the map command.

exp1 :=  x^3 - (-3*m + 1)*x^2 + (-4*m - 3)*x;

x^3-(-3*m+1)*x^2+(-4*m-3)*x

exp2 := x^3 - (-m - 1)*x^2 - (-4*m - 3)*x;

x^3-(-m-1)*x^2-(-4*m-3)*x

map~(s->sign(s)*normal(s*sign(s)), [exp1, exp2]);

[x^3+(3*m-1)*x^2-(4*m+3)*x, x^3+(m+1)*x^2+(4*m+3)*x]

Download sgn_exL.mw


Alternatively, here it is as a reusable procedure, which may then be applied easily either individually or across a list of such expressions.

restart;

 

P := ee -> map(s->sign(s)*normal(s*sign(s)), ee):

 

exp1 :=  x^3 - (-3*m + 1)*x^2 + (-4*m - 3)*x;

x^3-(-3*m+1)*x^2+(-4*m-3)*x

exp2 := x^3 - (-m - 1)*x^2 - (-4*m - 3)*x;

x^3-(-m-1)*x^2-(-4*m-3)*x

P(exp1);

x^3+(3*m-1)*x^2-(4*m+3)*x

P(exp2);

x^3+(m+1)*x^2+(4*m+3)*x

P~([exp1, exp2]);

[x^3+(3*m-1)*x^2-(4*m+3)*x, x^3+(m+1)*x^2+(4*m+3)*x]

 

exp3 := x^3 - (-3*m + 1)*x^2 + (-4*m - 3)*(-y - 1)*(1 - w)*x;

x^3-(-3*m+1)*x^2+(-4*m-3)*(-y-1)*(1-w)*x

P(exp3);

x^3+(3*m-1)*x^2-(4*m+3)*(y+1)*(-1+w)*x

Download sgn_ex2.mw

@Susana30 You're not explaining how you want to use the result.

The file I gave did show 2D Ouput, in a factored form you originally mentioned. My worksheet also showed some explanation -- not critical to the output part.

Why don't you explain precisely how you want to display or use a result with a factored form showing?

ps. Did you also read the link I'd given? It showed two additional ways.

@Carl Love Yes, the variant you've just given using ``(...) is exactly one of the ways given in that old Reply of mine to which I had supplied a link.

Indeed, that's precisely part of why I gave the link to that old Reply.

For some reason I made a weird mental flub, mentioning italics when I was *thinking* of the extra bracketing that can happen in some examples (though not this one) involving ``(...). Sorry if it appeared as if I were conflating left-tick usage -- I wasn't.

The typography is only only a minor part of why I don't prefer the ``(...) approach, over using InertForm.

I've edited my Answer here, to make my reference more explicit. The command,
   content( A ) * ``( primpart(A) )
and corresponding use of expand appear, literally, in that old Reply. Originally I'd figured that people interested would just follow the link.

@sursumCorda It cannot be turned off, though by using inert forms it can be side-stepped.

Here is a variant that also leverages the symmetry about theta=0 (eg. replacing theta by -theta will negate BB, yet retain AA and CC.)

Now the time for an effective grid of 32-by-129 takes approximately 5sec on my machine, as opposed to the unparallelized case without using symmetry taking about 34sec (or twice that, at about 65sec if not using memoization).

WZ_p4_symm_theta.mw

It copies the original and the flipped data into a double-sized Array for the final MESH (instead of using plots:-display of original along with a flipped plot), in order to avoid a seam along the join.

The previous version has the splitting values for theta getting exactly reused at both the top & bottom of adjacent portions. This is slightly inferior, and also might be the cause of a slight visible seam.

[edit] Here is a revision which does better: WZ_p4.mw
This produce the following in about 10sec, without the visible seam.

Here is a non-fancy parallelization, using Grid:-Seq followed by stitching the resulting MESH's Arrays together.

For a total grid of 33-by-128, this takes 9.5sec on my machine, compared with 33.5sec for the unparallelized version.

restart;

nsplit := kernelopts(numcpus);

4

plots:-setoptions(size=[350,350]);

g := evalf((Beta(1/4, 1/4)/2)^4):

WZ := proc(a,b,c) option remember;
  if not [a,b,c]::list(complexcons) then return 'procname'(args);
  else evalf(WeierstrassZeta(a,b,c)); end if;
end proc:

WPP := proc(a,b,c) option remember;
  if not [a,b,c]::list(complexcons) then return 'procname'(args);
  else evalf(WeierstrassPPrime(a,b,c)); end if;
end proc:

Grid:-Set(WZ): Grid:-Set(WPP):

AA := Pi*r*cos(theta) - Re(WZ(r*exp(theta*I), g, 0) + Pi*WPP(r*exp(theta*I), g, 0)/g);
BB := Pi*r*sin(theta) + Im(WZ(r*exp(theta*I), g, 0) - Pi*WPP(r*exp(theta*I), g, 0)/g);
C := sqrt(6*Pi/g)*Re(WeierstrassP(r*exp(theta*I), g, 0));

Pi*r*cos(theta)-Re(WZ(r*exp(I*theta), 189.0727201, 0)+0.1661579022e-1*WPP(r*exp(I*theta), 189.0727201, 0))

Pi*r*sin(theta)-Im(-WZ(r*exp(I*theta), 189.0727201, 0)+0.1661579022e-1*WPP(r*exp(I*theta), 189.0727201, 0))

.3157447408*Re(WeierstrassP(r*exp(I*theta), 189.0727201, 0))

P := proc(a,b,c,tbegin,tend,BEGIN,END,m,n)
  local res, t_low, t_high;
  (t_low,t_high) :=  tbegin+(BEGIN-1)/n*(tend-tbegin), tbegin+END/n*(tend-tbegin);
  #lprint(tbegin,tend,BEGIN,END,m,n,t_low,t_high);
  res := plot3d([a,b,c], r = 1/5 .. 4/5, theta = t_low .. t_high,
                        view = [-8 .. 8, -8 .. 8, -8 .. 8], shading = zhue,
                        style = surface, grid = [m, END-BEGIN+1]);
  op([1,1],res);
end proc:

(M,N) := 33, 128;

33, 128

str:=time[real]():
temp:=[Grid:-Seq['tasksize'=1](P(AA,BB,C,-Pi,Pi,
                                 1+floor((i-1)*N/nsplit),floor(i*N/nsplit),
                                 M,N), i=1..nsplit)]:
GG:=Array(1..M,1..N,1..3,datatype=float[8]):
for i from 1 to nsplit do
  #print(floor((i-1)*N/nsplit)+1 .. floor(i*N/nsplit));
  GG[..,floor((i-1)*N/nsplit)+1 .. floor(i*N/nsplit), ..] := temp[i];
end do:
ans2 := subsop([1,1]=GG,plot3d([AA, BB, C], r = 1/5 .. 4/5, theta = -Pi .. Pi,
                               view = [-8 .. 8, -8 .. 8, -8 .. 8], shading = zhue,
                               style = surface, grid = [2, 2]));
(time[real]()-str)*':-seconds';

9.508*seconds

# clear remember tables, and recompute it all, unparallelized
WZ:=subsop(4=NULL,eval(WZ)): WPP:=subsop(4=NULL,eval(WPP)):
str:=time[real]():
K:=P(AA,BB,C,-Pi,Pi,1,N,M,N):
ans1 := subsop([1,1]=K,plot3d([AA, BB, C], r = 1/5 .. 4/5, theta = -Pi .. Pi,
                        view = [-8 .. 8, -8 .. 8, -8 .. 8], shading = zhue,
                        style = surface, grid = [2, 2])):
(time[real]()-str)*':-seconds';

33.649*seconds

Download WZ_p2.mw

ps. I used a 128 which is a multiple of 4 (my numcpus value) for the N to total of the second grid values. I didn't try very hard to see whether the bookkeeping stands up robustly when N is not a multiple of 4. You could try N=127, etc.

@Aung Your solution_1 is already an equation with P(t) alone on the left hand-side only.

And it's not a differential equation. What do you intend to accomplish by passing it to dsolve?

It's unclear what you're trying to accomplish in this followup. What do you mean by, "i want to solve for t= 0 to 600 s" ?  What are you trying to "solve" for?

ps. You also have lowercase pi, which means nothing special in Maple. You likely intend Pi.

I've been on vacation, and am now catching up. I'll try to get to this as soon as I can.

I appreciate having more examples, and will look at them carefully when I get a chance. Thank you.

ps. Originally this was just a toy experiment with objects. One lesson learned/confirmed is a suspicion that having such objects act as so-called 1st class algebraic expressions involves a tricky balance between either: teaching almost eveything how to deal with them, and/or having everything (floats, units, etc) that touches them arithmetically get absorbed into the object, or having the object-ness be so ephemeral that many operations just drop the object-ness. I'm more doubtful that most people can be satisfied here most of the time.

This Question was given the "mathml" tag. Does that mean that presentation MathML would be of use?

@RezaZanjirani Your last Reply has no attachment.

@RezaZanjirani In my code I made it take the first solution from solve.

Your situation might be better handled as an optimization problem, ie. maximize this new (as yet unstated) objective function, with the original equalities/inequalities as constraints. And, for speed, it might be formulated as a floating-point numeric problem.

Prior to this, you've created several separate Question threads on this (or very close) topic. Please don't spawn any more wholly separate new Question threads on this. Duplicate Question threads get flagged as such and may be deleted.

You could add your followup queries and details to this or an earlier relevant Question. I suggest providing as complete and detailed a description as you can of your eventual goal and motivating example as you can, even if you don't yet have prototype Maple code to solve it. That'd be much more useful than, say, slowly approaching your actual goal by a set of partial reveals of details & code attempts.

First 63 64 65 66 67 68 69 Last Page 65 of 591