acer

32358 Reputation

29 Badges

19 years, 331 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

How did you obtain the Arrays of values, btw?

I ask because if you obtained them from calling dsolve(...,numeric) then we can often do better than ArrayInterpolation (or often any other quadrature approach, after the fact)  by using dsolve itself. That flavour of this question comes up quite a bit.

The choice of most efficient method will depend on how many elements there are in your Arrays, and how many times you need compute a numeric integral. For example, a spline interpolation approach (from CurveFitting, say) can gets somwhat slow as the Array length gets very large, partly beacause of the cost of forming the piecewise (once) and partly on account of the cost of evaluating the piecewise (each time).

acer

@Carl Love Please pardon me while I make a clarifying comment, just in the interest of being clear to the OP:

The first element of the solution returned by DirectSearch:-DataFit is the minimal achieved value of the objective function used for the particular fitting method. And different fitting methods may use a different objective formula as their respective measure.

So it is not generally sensible to compare results obtained from the various fitting methods simply by comparing the magnitude of the first element in each returned solution. The minimal values from different objectives, evaluated at their different optimal parameter points, are not directly comparable. So one cannot just pick the solution which gives the smallest first element.

It thus becomes up to the user to decide what measure of optimality (ie. what objective) may produce a "better" fit.

How does your supervisor feel about an interactive solution using Embedded Components?

acer

@Carl Love Yes, that kind of deferment (userinfo, etc) is part of the unfortunate way that Document Blocks are implemented (the pair of execution  groups, one with output suppressed and the other with input hidden...).

But the OP mentioned printf, and is I recall corectly that particular kind of i/o can usually be obtained asynchronously even in a Document Block. So that's one reason why I asked for more details.

[edit] I must correct myself. In a Document Block it seems that even printf display is deferred. dbdefer.mw

However, the OP has now clarified: this is about a Worksheet, so the above not relevant.

More details might help here. What OS? Is this in a Worksheet and an Execution Group or a Document and a paragraph (Document Block)?

How much output are we talking about? Very many short-ish lines?

Is there any natural amount of output which you actually would like to see, in a block? Or do you want every line? Or only one last line is useful?

Do you have a sample of code that demonstrates the problem, that we can work with?

Have you tried sprintf and redirecting that to a TextArea embedded component? (Just an idea... may not be suitable here, depending on the details above.)

acer

So your problem is with the final call to `solve`, when epsilon is greater than 0?

If so, then you could try using `fsolve` (repeated, with the avoid option built uo) or the `DirectSearch` (3rd party add-on from the Application Center) rather than `solve`. 

Let us know if you need all the roots, or just one real root, or all the real roots, etc.

acer

assumptions, internal remember tables... if the OP wants a clean slate then it seems sensible to restart. The premise that a restart should be avoided because package initialization is onerous seems faulty to me.

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.

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