acer

32333 Reputation

29 Badges

19 years, 326 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@emersondiaz Before I was simply fixing up the Maple code that you provided in your .mw attachment, w.r.t. how you could use NLPSolve's results to get numeric values. I wasn't even looking at the Matlab code in the .pdf file.

Here is a different translation of that Matlab code in your .pdf file, and a plot that obtains:

4.6_acccc.mw

By the way, in your .pdf file the Matlab code uses an integrand like,

    sqrt(x)/(exp((x - y)/t) + 1)

But in your Maple code in this Question you appear to have used something like a polylog form with for integrand more like,

     sqrt(x)/(exp(x - y)/t + 1)

Those two expressions are not the same; the bracketing in the denominators are importantly different. That is why the earlier plot wasn't correct.

@zenterix For unassigned names i and x there's no important difference here between,

   plot(x, x=1..5)

and,

   plot(i, i=1..5)

There's no implicit type aspect where the name `i` is integer valued and `x` is continuously valued. They're both just names.

@romanrieme I had already mentioned that I'd intended [F2(t), F3(t)] instead of display(F1(t), F3(t)) inside the `if`.

Your F1,F2,F3 procedures are nicely behaved and return unevaluated when passed just the symbolic name t, so that premature evaluation problems can be avoided in these examples. You can program p1 similarly.

As I mentioned earlier you could nest `if` calls, for handling more that two cases, but you could also use piecewise which becomes simpler as you load on more conditions. (You could also write a master procedure, accepting parameter t/tau, returning unevaluted for symbolic t/tau, and assembling any single frame using a single if..then..else according to the your various conditions. I won't bother.)

The following attachment shows both the nested `if` as well as the piecewise approaches I just mentioned.

Download transition_include_plot_ac.mw

note: This is not advanced programming. Several of the followup solutions involve simple logical extensions from the previous coding examples in the thread.

@zenterix You haven't explained in any way what you expected your second attempt to mean. 

@romanrieme Sorry, I was rushing out the door earlier, and my fingers didn't type what was in my mind.

What I meant was that you could use [F2(t),F3(t)] in the `if`, instead of say just F2(t).

Eg,

    animate(display, [`if`(t < 0, F1(t), [F2(t), F3(t)]), scaling = constrained],
                  t = -1 .. 1, frames = 141)

how_transition_ac3.mw

note: In your followup comment you wrote, "F1(t) from -1 to 0", but in your worksheet your F2 appears in the subsection captioned, "t from -1 to 0". In any case I feel sure you can work out which you want where.

note: I am not so keen on the following, since two back-to-back frames are displayed each with t=0.
   display([animate(F2, [t], t = -1 .. 0), animate([F1, F3], [t], t = 0 .. 1)], insequence)

note: My earlier suggestion display(F2(t),F3(t)) was a mental slip. It should be obvious why it would not work: t is just a name and F2(t) returns unevaluated which is useful elsewhere but not good for the display call. Read my correction here.

@romanrieme Just display(F2(t),F3(t)) in the `if`.

Please put your close followup queries here, instead of in a wholly separate and new Question thread. (At the very least, you could Branch off from this Question...)

@zenterix What will be the next changes in the task, after this?

I'd prefer to save time and accomodate a few of the coming requirement changes in one shot.

Tom's toy example saves and reads back in reasonably quickly.

This is simply save, and read.

Below I call save on the result of display of all the frames together (with `insequence`). But you could just as easily save/read a mere list of the sequence of frames, in case say you want eventually to display together frames saved from different Grid processes.

It's easier than exporting just the numeric data (which will involve lots more work if it's supposed to also store receive additional information about color, style, etc, and even more if it has to support reassembling CURVES, GRID (and POINTS, and MESH?) structures, arrows, and so on...)

restart;

with(plots):

odesys:=[diff(x(t),t) = x(t) - x(t)*y(t),
         diff(y(t),t) = x(t)*y(t) - y(t)]:
tv:= Array([seq(j, j=0..10,0.1)]):

ics:=[x(0)=k1, y(0)=k2]:

sol:=[seq([dsolve([odesys[], eval(ics, [k1=j, k2=1])[]],
                  numeric, output=tv)[2,1][..,2..3],
           dsolve([odesys[], eval(ics, [k1=j, k2=2])[]],
                  numeric, output=tv)[2,1][..,2..3]][],
          j=1.5..2.5,0.1)]:

plt1:=plottools:-circle([1,1], 1, thickness=4):
Anim:=display([seq(display([plt1, listplot(sol[j], color=red),
                           seq(listplot(sol[k], color=blue),k=2..j+1,2)]),
                   j=1..numelems(sol),2)],insequence=true):

save Anim, cat(kernelopts(homedir),"/mapleprimes/testanim.m");

restart;

read cat(kernelopts(homedir),"/mapleprimes/testanim.m");

Anim;

Download toyAnim_dotm.mw

This is simply save, and read.

It seems to me that the main question is whether this gets undesirably slow, as the size and number of the animations increases. If it doesn't, then extracting/exporting the numeric data (and all that potential work cobbling each frame's elements back together) seems unnecessarily complicated and onerous.

@AHSAN You can suppress the label on a particular axis by using the empty string formed by a pair of double-quotes.

You can color between two (or more) colors of your choice, through the colorspace of your choice. The key "xgradient" makes it vary with the value in the axis[1] direction, "ygradient" makes it vary with the value in the axis[2] direction (unrelated to your variable name y), and "zgradient" makes it vary with the value in the axis[3] direction.

For example, coloring in hue by the values of Q,

plot3d(eval(u,[We=0.1,n=0.5,lambda=0.0095,x=0,k=0.1]),
       y = 0 .. 1, Q = 0. .. 0.7,
       labels = [y, "", "u"], orientation = [0, 90, 90],
       colorscheme = ["ygradient",[red,blue],colorspace="HSV"]);

@zenterix This is quite different from what you originally described in your Question.

Perhaps there are still more key details that matter.

Do you need maximal efficiency because, say, you're going to be reading the results back in later? How much delay can you bear, for export/import?

What happens if you assign the computed plot structures (whole), to either individual .m files or to key names within .mla files? Is the save&read too expensive and slow?

@Carl Love It should be pointed out that in order to use procedure new_ex (rather than its symbolic return value of your step 4) one must make a procedure call.

That is, if that step 4 is not made then such a procedure call is made for each and every subsequent use of new_ex.

The added cost of a user-defined procedure call in Maple is significant, if being compared to (say) purely numeric arithmetic operations.

That added cost is a bit improved if the introduced procedure will be run under evalhf, or compiled. But it's still relatively significant.

On the other hand, that step 4 must be made if the goal is further symbolic manipulation of an ensuing symbolic expression.

There is also a case in which new_ex can be used to form new symbolic expression (eg. by being passed new symbolic arguments). In that case the optimized subexpression generation that new_ex performs can be a significant cost savings (esp. for complicated arguments).

It gets complicated to assess "best", outside of precise context. We weren't told whether the OP's goal was code-translation for a microcontroller, mathematical typesetting, further symbolics (and of what kind), or other. But we were told that the OP wanted a short target expression, so it was reasonable to assume that construction was a key aspect.

I'm glad you brought this up, it's an interesting topic.

@ecterrab Yes, I used a combinatorially generated list of lists and did an iterated search. It's not cheap in general, although for this example an improved result could be obtained in reasonable time using only lists of small subselections of the names.

I used some old code that I had for doing this kind of thing. It has some speculative searching for collect (on such subsets), or combine/trig on subsets of unfrozen trig calls, and other tricks. Some of it is potentially very expensive. It spits out (in a running manner) the commands that produce a more compact result. It allows me to specify a metric.

@zenterix Yes, I mentioned that yesterday in responses (with documentation reference URL links) to another of your Question thread, i.e here and here.

The programmatic approach to which I alluded uses the PackageTools facilities. This can create a .maple file which can install/unpack your package's files when either used directly in the GUI or used from the Maple Cloud (and then accessible publicy or privately from within other's Maple GUIs). See the links I'd provided.

ps. A much older approach is to use the InstallerBuilder package, which can construct a special kind of .mla file that automatically opens a popup dialogue and runs its own installing/unpacking script when opened in the GUI using the march Maple command. This old and cloud-unaware.

ps. I have built dozens of Maple "packages" of various complexity, and I've used all the approaches described (including some others I haven't mentioned, but devised by myself or Maplesoft). There is no One True Approach; you can figure out what works best for you -- a custom approach, or use of stock facilities in the product. It can make a difference whether you want others to be able to use your package, and/or whether you want them to be able to rebuild it from source.

I have deleted a duplicate of this.

First 90 91 92 93 94 95 96 Last Page 92 of 592