acer

32490 Reputation

29 Badges

20 years, 7 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@mehran rajabi So you are back-substituting the approximate root into the original expression, to see whether the result is small. Sometimes that computed value is called the residual, or the forward error.

The plot of the expression is very steep near the larger roots. That means that any small change in the root approximation will result in a large change in the computed residual (even if the back-substitution itself is performed a very high precision).

Truncation of the approximate root (ie, rounding it to d digits) incurs such a change away from the true root. So the residual computed using only say d digits of the approximate root may be significantly larger than the residual computed using more than d digits of approximation of the root.

In the following attachment I generate approximations of the root near 22.3, with successively more digits in the approximated result. Each of these is back-substituted into the original expression, and the residual computed. It demonstrates how a more accurate approximation of that root is needed in order to get a smaller residual.

resid.mw

I notice that the curve in your image is not straight, between the first and second data points.

Are you asking about curve-fitting (ie, regression or interpolation, etc)?

Afaik an animation can only show a single `background` image, taken as the last available from all the frames.

But it should be possible to produce a heatmap in an alternative format.

For example the images could be float[8] images ie. float[8] Arrays which could be used to shade density plot GRID structures instead. Those can be more memory intensive, however.

A modest number of shaded polygons would also likely serve, if you don't need a very fine granularity, and be cheaper still.

@Adam Ledger Just because unapply sometimes provides the convenient way to construct a procedure from an expression doesn't mean that it's always the right thing to use. It's not the right thing to use with the code snippet I gave in my answer.

The best way to turn my answer into a re-usable procedure is to simply wrap it in proc()...end proc. I'll do so below. I'll change some of the names in the proceduce (params or locals) so that they are not confusingly the same as their equivalents at the higher level.

I originally used _seq with an underscore as a cheap way to use a name to which one would likely not have assigned a value. In the procedure version below I'll use s.  Kitonum used S in the procedure version he posted after me. The similarity is because we were both just working around the issue by using a dummy name for the foldl call.

restart;

Gen:=proc(f, r::list(posint))
  local n,i,j,p,s;
  n:=nops(r);
  op(eval(subs(s=seq,
               [foldl(s, f(seq('i'[j],j=1..n)),
                      seq(i[p]=1..r[p],p=1..n))])));
end proc:

Gen(F, [2,1,3]);

  F(1, 1, 1), F(2, 1, 1), F(1, 1, 2), F(2, 1, 2), F(1, 1, 3),
  F(2, 1, 3)

Gen(F, [7,2]);

  F(1, 1), F(2, 1), F(3, 1), F(4, 1), F(5, 1), F(6, 1), F(7, 1), F(1, 2),
  F(2, 2), F(3, 2), F(4, 2), F(5, 2), F(6, 2), F(7, 2)

Your original question was about how to use foldl and seq to generate all the possible F calls. There are, of course, other ways to generate those F calls, and some of the other ways are reasonably simple. I was deliberately answering the question of how you could use foldl and seq to do it.

@mweisbr I could have tested for <>1 or <0 , as you stated, but <10 happened to work since all other day was larger. It was just less typing.

@mweisbr I see now that the bad points are not isolated, which I didn't realize before. I'm not sure how interpolation (including just linear) is going to be justified.

You may be able to smooth the data by convolving the errant points. (ie. something like ImageTools:-Convolution , at least in concept)

The tricky bit can be to convolve (mostly) only the points which are unsatisfactory, because you don't want their bad values affecting other good points nearby. It helps to have a robust and flexible peak detection scheme, in order to convolve only the bad data. Sometimes it's not so hard. It helps if the bad points are quite isolated.

Can you confirm whether the uploaded data is correct?

Once you have the source code in a plaintext file, why not use Maple's read command instead of repeatedly copy & pasting it into the Maple sessions?

@Annonymouse 

line is being used in Kitonum's example as an export of the plottools package. So if you don't want to load that package (and by doing so, rebind the name line) then you'd need to reference it using the long-form plottools:-line .

A:=[1, 2, 3]: B:=[4, 5, 6]:

plots:-display(plottools:-line(A, B,
                               color=red, thickness=2));

I'll also correct Kitonum's first example below. Ie, either A+t*~(B-A) or (1-t)*~A+t*~B . And if you're just going to produce a straight line then you only need two points in a space curve.

A:=[1, 2, 3]: B:=[4, 5, 6]:

plots:-spacecurve(A+t*~(B-A), t=0..1, numpoints=2,
                  color=red, thickness=2);

Also, this seems simple.

A:=[1, 2, 3]: B:=[4, 5, 6]:

plots:-pointplot3d([A,B], style=line,
                   color=red, thickness=2);

@Annonymouse Personally I think you should just add additional details and rephrasings etc to a Comment/Reply on this Question.

If you'd rather edit the Question then it's better to leave the original matter and mark the new as new. It's a reasonable choice.

Adding your own details to an Answer here would be not be clear and most useful, I think.

@Annonymouse Please don't post such a close duplicate as a separate Question. Put the followup details here instead.

@Christian Wolinski 

Sometimes kernel built-in functions like eval will call out to the interpreted Library.

Here's an example where it makes a difference, using Maple 2018.

restart;

a:=2:
trace(`eval/piecewise`):

p:=piecewise(x<a, 1/(x-a), x=a, 22, 33):

eval(p, x=a);

{--> enter \`eval/piecewise\`, args = piecewise(x < 2, 1/(-2+x), x = 2, 22, 33), {x = 2}

expr, eqs := piecewise(x < 2, 1/(-2+x), x = 2, 22, 33), {x = 2}

oper := piecewise

eqs := {x = 2}

eqs := {x = 2}

tmp := table([])

t := x = 2

tmp := {}

i := 1

piecewise(x < 2, 1/(-2+x), x = 2, 22, 33)

false

false

2 < 2

false

3

2 = 2

true

<-- exit \`eval/piecewise\` (now at top level) = 22}

22

restart;

a:=2:
unassign('`eval/piecewise`'): # not reall a good thing to do

p:=piecewise(x<a, 1/(x-a), x=a, 22, 33):

eval(p, x=a);

Error, numeric exception: division by zero

 


Download CW_pw.mw

The given examples all return 22, without emitting an error, in Maple 2018.0.

There are options which make the solver try harder.

restart;
f:=sin(3*x)-cos(7*x)+sin(17*x)+cos(20*x)-sin(67*x):

Optimization:-Maximize(f, x=0..2*Pi, method = branchandbound);
           [3.17327920314180, [x = 4.10406174848180]]
Optimization:-Minimize(f, x=0..2*Pi, method = branchandbound);
          [-4.46537362759898, [x = 1.71553210252725]]

Optimization:-Maximize(f, x=0..2*Pi, method = branchandbound, evaluationlimit=100);
           [3.40373784598076, [x = 4.94786409656254]]
Optimization:-Minimize(f, x=0..2*Pi, method = branchandbound, evaluationlimit=100);
          [-4.82606452700204, [x = 3.59004152499192]]

Of course there will always be examples which make a global optimizer miss the best extreme points. And indeed there are examples for which DirectSearch fails to find the global optima with its own defaults. However I suspect that DirectSearch is stronger in general (and with default options too).

Unfortunately the extra options for method branchandbound are listed only on the help page for NLPSolve and not on that for Maximize/Minimize.

Setting infolevel[Optimization]:=3 or higher shows information on working parameters (default or otherwise).

It seems to work ok for me in Maple 2015 (or 2017), if I use plot(sin(x)/x, legend=sinc(x))  [note minor invalid syntax correction].

By that I mean I see the legend in the examples which use the list assigned to A.

Could you please upload a Worksheet or Document that exhibits the problem?

First 257 258 259 260 261 262 263 Last Page 259 of 594