acer

32333 Reputation

29 Badges

19 years, 318 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@FDS Previously you did not mention how you wanted to use the results, so I showed only the simplest way to access the parsed results (as Records whose fields can be access individually).

For comparing them, you could turn each into a Date object.

If you only want to use the Dates for other tasks, then you could sort the new Vector of Dates directly. If you'd also like to sort the earlier parsed results then you could construct the permutation key, which may then be used to reorder either Vector.

restartNULL

dates := Vector(3, {(1) = "9/7/2023", (2) = "12/8/2020", (3) = "10/10/2021"})

times := Vector(3, {(1) = "14:08", (2) = "09:12", (3) = "22:45"})

str := `~`[cat](dates, times)

Vector[column](%id = 36893628358824725308)

G := `~`[StringTools:-ParseTime]("%m/%d/%Y%H:%M", str)

Dts := map(proc (g) options operator, arrow; Date(g:-year, g:-month, g:-monthDay, g:-hour, g:-minute) end proc, G)

Vector[column](%id = 36893628358824709644)


The Date objects can be compared using `<`, so they can be sorted directly.

evalb(Dts[2] < Dts[1])

true


If we no longer need G, we could simply sort Dts
and use these dates from here on.

sort(Dts)

Vector[column](%id = 36893628358824698932)


The following permutation can be used to sort G or Dts.

K := sort(Dts, 'output' = ':-permutation')

[2, 3, 1]

Dts[K]

Vector[column](%id = 36893628358824696756)

G[K]

Vector[column](%id = 36893628358824690380)

NULL

Download StringToDateTime_ac2.mw


ps. The is also a Time command, though I did not need it above. There are Help pages for the Date and Time commands, as well as the Calendar package which has some additional commands for handling Date objects.

@lemelinm Thank you for your kind words.

Sorry, I don't understand your objection to the code from my previous reponse. Aren't the "principal" (major) tickmarks on the x-axis at 0,3,6, and 9?

You might have to upload your worksheet that uses it, and then write more clearly what aspect is wrong.

Isn't the result the same as the image shown in your original Question? Or, was that original actually somehow wrong too?

note. You appear to also want gridlines, and possibly also to zoom in/out? It's not always possible to control how the gridlines appear in the GUI, under zoom, etc. But maybe this is not on-topic. I don't yet understand your objections, and whether it's with the axis-ticks or the gridlines.

ps. If t represents time then wouldn't you also want the s to be Unit(s), so as to be rendered in upright Roman for consistency?

@lemelinm It's not clear what you want done with the x and 10^8, if the Unit(m) is inside brackets.

You can force any specific tickmarks you'd like. Eg,

plot(0, x = 0 .. 10, y = 0 .. 4, gridlines = true,
     axis[1] = [tickmarks=[0,3,6,9], gridlines=[subticks=1]],
     labels = [x*InertForm:-Display(10)^8*``(Unit(m)), `t `(s)])

Or you could specify a spacing between them (with anchoring at, say, zero), so that you get additional multiples shown if you zoom out.

plot(0, x = 0 .. 10, y = 0 .. 4, gridlines = true,
     axis[1] = [tickmarks=spacing(3,0), gridlines=[subticks=1]],
     labels = [x*InertForm:-Display(10)^8*``(Unit(m)), `t `(s)])

See the Help page ?plot,tickmarks

@FDS You now seem to be using the 24-hour convention, so the hour format is %H rather than %l. (See the Help-page for the ParseTime command.) I could not tell which you wanted from your original example.

You can apply the ParseTime command across the Vector using either elementwise syntax or the map command.

StringToDateTime_ac.mw

@Rana47 You yourself provided a formula for u[1], and indeed you assigned that formula to that very name. So that assigned u[1]=0 gives your first cited BC.

By evaluating that assigned name u[1] (which was assigned the formula) at sigma=-sigma and equating to 0, we can produce the formula for your other BC.

When you see something like A=A inside one of the solutions it means that A can take any arbitrary value. For example, in the following solution all the parameters except k and B can take any arbitrary value (except possibly sigma=0). Using this for k and B is all that's needed to satisfy the given BCs.

simplify(eval([u[1], eval(u[1], sigma = -sigma)],
         [B = -1/4*p^3*y^4 - 1/2*y^2*q - A*y, k=-1]));

      [0, 0]

I didn't use your own syntax, u[1](-sigma) = 0, u[1](sigma) = 0 since you assigned an expression rather than an operator to u[1]. Here's the same kind of thing, but with u[1] an operator instead of an expression.  help_c_solve_o.mw

ps. Why do you seem to think that your two BCs might allow all the other parameters to specify both some fixed A and B (with neither arbitrary)?

Note that you could also get something like this formula for A, with B arbitrary.

u[1] := -(-2*p^3*sigma^3*y^4+4*k*p^2*sigma^2*y^3+4*p^2*sigma^2*y^3-3*k^2*p*sigma*y^2-4*q*sigma^3*y^2-6*k*p*sigma*y^2+k^3*y-3*p*sigma*y^2+3*k^2*y+3*k*y+y)/(8*sigma^3)+A*y+B

simplify(solve({u[1] = 0, eval(u[1], sigma = -sigma) = 0}, [A, k], explicit, real, parametric))

[[y <> 0, sigma <> 0, A = (1/4)*(-p^3*y^4-2*q*y^2-4*B)/y, k = -1]]

Download help_c_solve_p.mw

@minhthien2016 Using your list L, you can get the same result using,

   sort~(map~(normal,L),order=plex(x))

as you can using,

   subs('y' = 1, collect(`*`~('y', L), x, normal))

 

You didn't previously provide examples which went from unsorted to sorted (wrt x), so I didn't know it was a requirement.

I have a question. The first entry in your list L appears to be,
     -3*(m - 10)*x^2 + (9*m - 6)*x + x^3
where the coefficient of x^2 is factored and the coefficient of x is not factored. The two methods above will each factor both coefficients. Does that matter to you?

@minhthien2016 Ok, so you already have the expressions in the list assigned to L.

Did you see my previous response,

   map~(normal, L)

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

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