acer

32400 Reputation

29 Badges

19 years, 345 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

If you are loading packages using the mouse and the menubar Tools->Load Package... then I suggest that instead you make the package loading be done explicitly by code in the Document/Worksheet.

You can even paste all the package loading commands (calls to the `with` command) on the same line, so that you can execute them all in one keystroke.

You can even make the Standard GUI insert the actuall command for you, the first time you load the packages in the worksheet. See the menubar item Tools->Options->Display and the checkbox "Expose commands inserted from Load/Unload Package menus". If you check that then subsequent use of Tools->Load Package from the menubar will embed the `with` command call in the document.

acer

@MTata94 You can define the "subroutine" inside the outer procedure, but you don't have to.

One disadvantage of defining the subroutine `q` inside the body of the calling procedure `p` is that it incurs the cost of defining `q` each time `p` is called. That cost may be negligible for simple examples, though.

For example, here I define q at the top-level, alongside p. Note that `q` is no longer declared local inside p.

restart:

q:=proc(s) s^2 end proc:

p:=proc(x::numeric)
  local k,r;
  r:=x;
  for k from 1 to 5 do
    r:=q(r)
  end do;
  evalf(sin(r))
end proc:

p(2);

                                -0.4619865795

If you wish to organize things, and so manage the name-space a little nicer, you can also make use of modules. For example,

restart:

p:=module()
  local ModuleApply, q;
  ModuleApply:=proc(x::numeric)
  local k,r;
  r:=x;
  for k from 1 to 5 do
    r:=q(r)
  end do;
  evalf(sin(r))
  end proc:
  q:=proc(s) s^2 end proc:
end module:

p(2);
                                -0.4619865795

q(2); # note that now q is not assigned at the higher level.
                                    q(2)

See the Programming Manual ([1], [2]) for more details and examples.

@Markiyan Hirnyk Just to be clear, I meant as b->1 from below, while d->infinity.

@Markiyan Hirnyk Are you sure about the case of b < -1 ? Why not b/(b-1)?

And for the case of b>=-1 and b<0, why not undefined?

@dbachito Another way is to keep the Spline data (your e3) exact and differentiate the piecewise Spline before applying evalf. That works, but depending on the original function the process can become very slow as N gets large.

There are three real roots close to 0.085786 which give difficulty. Note that applying evalf to P before passing to fsolve will actually solve a different problem if Digits is not large enough to encapsulate the original exact data. And there is also the matter of the accuracy of the results.

The following is on Maple 2015.1 on a 64bit Linux system. With Digits<21 as the working precision I see at least two of those three problematic roots as being returned with nonzero and nonnegligible imaginary parts, when sending evalf(P) to fsolve. And with Digits=21 I see those particular three real roots' estimates as still having about 1e-9 absolute error. And when repeated (clean session or carefully with forget(evalf)) at even higher working precision those three roots get computed this way with about 15 fewer accurate digits than the others.

This is indeed a bug. Internally the candidate approximations to the problematic roots should be found wanting earlier (the bug is that `fsolve/refine2` is being passed candidates with Float(undefined) in them) and skipped so that `fsolve/polyill` can tackle them more robustly. I submitted a but report.

(I see also that robust RootFinding:-Isolate is never used when the complex option is passed. But it might help in such situations, perhaps making life easier on `fsolve/polyill`.)

In my 64bit Maple 18.02 and 2015.1 for Windows 7 the cited dsolve/numeric example (with the compile=true option) works ok.

I suppose that this is because dsolve/numeric in my Maple 18 and Maple 2015 is using the 3rd party "free" MSVC++ compiler and JDK components that I had installed to make Compiler:-Compile run in Maple 17 or some earlier Maple version.

In Maple 18 and Maple 2015 the Compiler:-Compile command uses the bundled LLVM compiler on 64bit Windows. But prior to those Maple releases one had to set up a 3rd party compiler to enable Compiler:-Compile. Here are the Maple 17 instructions, for example. I believe that I'd also installed the "2008" version of the "free" MSVC++/JDK components, for enabling Compiler:-Compile in Maple 15.

So my supposition is that configuring (at least one... particular?) version of the "free" MSVC++/JDK components for 64bit Windows 7 might allow your Maple 2015.1 dsolve/numeric to compile relevant examples in Windows 7. I don't know the situation on Windows 10.

It would nicer and simpler if dsolve/numeric were made to use the LLVM that is bundled with Maple.

I know how to change the settings which Compiler:-Compile uses to call a compiler. But that's not your issue, Preben, it seems. I don't know a good way to change arbitrarily the way dsolve/numeric attempts to call a compiler.

acer

@Carl Love rtable_eval(A, inplace) sets a bit on the rtable's DAG, I believe, to mark it.

There are efficiency considerations, when accessing rtable entries within a proc (of an rtable argument say). For example the situation of needing to access only a few entries of a large rtable with symbolic entries with nested assignment chains, versus needing to access all entries possibly multiple times each. Entry access involves evaluation, but it may be beneficial to not have to duplicate effort.

I'm on vacation with only a smartphone so cannot say more just now.

@Thomas Dean See also the `unapply` example above, at end.

So you can indeed get your methodology to work. But if you cannot remember why you need `unapply`, and when, then perhaps you might reconsider the whole approach and try to stick to expressions or procedures, only, as much as possible... Just a suggestion.

I note that confusion between functions and expressions is #1 on Robert Israel's Top Ten list. Worth a read.

One pattern I've observed is people creating a procedure like your original `f`, only to ever call it once as `f(x)`. If it's only ever called once, just to get an expression, then the odds seem good that there is a procedure/expression muddle of some sort.

Why not just assign the values into a Matrix or Array and then use ExcelTools:-Export?

I don't see why printing all the values would be useful or convenient for exporting, or anything but very inefficient.

acer

@Kitonum When the two points lie on adjacent faces you could consider three kinds of flattened cross. One cross has as its center square the face containing point A. The other two crosses can have as their center squares respectively one of the two faces which are adjacent to both the face containing A and the face containing B. For each of these three kinds of cross take the straight line distance between A and B. Will the answer for this case (A and B lying on adjacent faces) then be the minimal length of the three straight line segments formed on each of these three flattened crosses?

 

@Markiyan Hirnyk There is also time taken by RandomArray to first produce M.

On my 64bit Maple 2015.1 on Windows I see timings that on average look like so,

restart:
CodeTools:-Usage(map[evalhf,inplace](c->.1*c+2,
                                     ArrayTools:-RandomArray(1000,1000,distribution=normal))):
memory used=61.71MiB, alloc change=7.63MiB, cpu time=998.00ms, real time=994.00ms, gc time=62.40ms

restart:
CodeTools:-Usage(Statistics:-Sample(Statistics:-RandomVariable(Normal(2,.1)),[1000,1000])):
memory used=8.16MiB, alloc change=7.63MiB, cpu time=125.00ms, real time=134.00ms, gc time=0ns

It's also worth pointing out that the OP asked about vectors and matrices. The RandomArray command produces Arrays, while Sample can produce Vectors and Matrices directly. Sure, a 1D and 2D Array can be toggled inplace into a Vector and a Matrix using rtable_options(...,subtype=...) but it makes the task more complicated.

The code using Sample is more straightforward, and even more so than above if one wants to reuse the random variable or generate a numeric sample more than once.

FWIW, the help-page for RandomArray says that it produces matrices/Matrices when called like RandomArray(m,n,distribution=normal) but that is not true. I see RandomArray(m,n,distribution=normal) make a 2D Array, and RandomArray(m,distribution=normal) make a Matrix, and no option to make a 1D Array or a Vector or a nonsquare Matrix directly.

@Kitonum Until the OP responds we don't for sure whether he just wants a random sample from some Normal(a,b), or whether he wants a Matrix of random variable placeholders.

Here is one (slightly crazy) way to produce Matrix of sample values from that.

M := Matrix(2,3,(i, j)->Statistics:-RandomVariable(Normal(0,1))):

map(`?[]`,map(Statistics:-Sample,M,1),[1]);

         [-0.531692519958605  1.99932940923732   0.105259473657208]
         [                                                        ]
         [ 0.127790495266725  1.37115530221358  0.0925191256937789]

Slightly less crazy might be,

map(c->Statistics:-Sample(c,1)[1],M);

          [0.342696098518556  0.837118218825433  -1.10381342439977]
          [                                                       ]
          [ 1.39898388585646   1.87933504556442  0.477078415677388]

@nm Well, that free MaplePlayer already exists, and your proposed way of doing things is already possible (and, I agree, results in a more responsive and robust experience). And that free player also provides direct access to download directly from the Maple Cloud.

 

@erik10 Sorry to belabour it, but just to make sure:

1) You can share private access to a Maple Could group with 1 or more other people. So once that is done you no longer need to send them URLs -- each party knows where to deposit or find something new.

2) The material on the MapleCloud can be downloaded from a brower and then opened in the MaplePlayer. Or it can be accessed from the cloud and opened directly from within the Player. Or it can be accessed and opened and interacted with in a (html5 conforming) browser, without the Player. And if you login at maplecloud.maplesoft.com then you get access to your own private groups, in your browser.

The browser support for all interactive aspect of a Document (via Embedded Components) seems to be still being polished. But it seems to me that point 2) speaks to your original Question.

First 326 327 328 329 330 331 332 Last Page 328 of 592