## 442 Reputation

17 years, 192 days

## Similar question here...

I am running Maple 16.02 under Windows 7 Pro (SP1), 64-bit; the cpu is an i5-3427U.  In a Maple document, `evalhf(Digits)` returns 15, i.e. the same as on a 32-bit computer.  Why is 15 returned?

## DirectSearch and Optimization...

DirectSearch works beautifully!  It quickly and reliably finds the minima of the functions that I have, using the method='brent' option.  Markiyan Hirnyk, thank you greatly for pointing me to this.

The Optimization package is clearly not implemented correctly.  Most real-world applications will want/need to have the procedure evaluation done in hardware.  Because Optimization does not (directly) use hardware, the package cannot really be used in most applications.  Maplesoft obviously put substantial time and effort into implementing Optimization, and the architecture is really nice.  Maplesoft should make the small extra effort to complete the implementation.

A big *HUGE* thank you to Sergey Moiseev for implementing DirectSearch.  This is an important contribution.

## residual mean square...

I suggest using the residual sum of squares or the residual mean square. Further to acer's comment, the Statistics package has options to return these directly. For example, if the function that you are fitting is a+b*t+c*t^2, then try
`Statistics:-LinearFit([1,t,t^2], X, Y, t, output = 'residualmeansquare');`
For more information, see the Options section in `?LinearFit`.

## Digits=14...

Having `Digits=14` does not guarantee that the computations are done with hardware arithmetic. The `Digits` value indicates how many digits of precision you would like in the result of a primitive computation. The computation itself might be done with, say, `Digits+2` precision, in order to achieve `Digits` precision in the result. There are some Maple routines that increase `Digits` internally. I do not know if that is that case with the LinearAlgebra routines you are using. To force hardware floats, I think that you should set `UseHardwareFloats=true` and ensure that your Matrices/Vectors have `datatype` set appropiately. See `?EffNumLA` for details. I do not have much experience with this. Perhaps others can suggest more.

## Numeric solution?...

I agree with Robert Israel, that it might be too late to do numeric integration, because round-off error might already have occurred (in obtaining the constants). Having said that, can we try the following? ``` f:= unapply(P[through], k[2]); plot(f, 0 .. 1); ``` which indicates that the function is decreasing on the interval, and thus the maximum is indeed at `k[2]=0`. You can test that via `Optimization:-Maximize(f, 0 .. 1, method='branchandbound');` Regarding increasing `Digits`, this does not affect the `plot` command, which tends to use hardware floats for evaluation. (There are ways around this, via defining a function with its own `Digits`.)

## modeling the XY data...

The first rule of data analysis is “look at the data”. The graph below was drawn via Statistics:-PointPlot (with a log scale). This looks like some sort of power spectrum—a noise floor with peaks. One immediate question is this: is there some pattern in the placement of the peaks? To find the positions of the peaks I tried the following, where `XY` is the sorted list of pairs of numbers and `k` is a constant. `XYpeaks:= XY[select(i-> sort([seq(j[2],j=XY[i-k..i+k])])[-1]=XY[i][2], [\$(k+1..nops(XY)-k)])];` Using `k=30` seems okay. Next, I tried   `PointPlot([seq(j[1], j=XYpeaks)])`.  That displays as an approximate straight line—but nowhere near exactly. If the line is supposed to be exactly straight (which would seem likely), then the data must have noise/errors in the x coordinates. Most curve-fitting routines assume that x coordinates are exact, and all the noise/error is in the y coordinate. Such routines would be inappropriate here. (Moreover, the residuals of the straight line are autocorrelated; so specialized routines are needed to model this.) How to proceed from here depends on what is important for your application. Do you want to accurately model the noise floor? Is it more important to accurately place the highest peaks, or to place all the peaks. How important is it to accurately specify the heights (and shapes?) of the hightest peaks? Etc. As an example, if we use two parameters for the placing of the peaks (i.e. fitting their placements to a straight line), and a third parameter for the noise floor, then there are three parameters left to model the heights (and shapes?) of the peaks.

## precision...

You can see the effects of increasing Digits using something like this:
`for d from 8 to 20 do evalf[d](eval(theRatio, f0=5e9)) end do;`
84.533996 2.76902582 0.3832106715 0.45853662433 0.456853381170 0.4560144647218 0.45601446472291 0.456016978775341 0.4560168949732729 0.45601697877528942 0.456016982965391820 0.4560169819597674829 0.45601698196814768301 There is a related issue. It might be that the constants in your expression need to be specified to greater precision, in order to get an accurate final answer. As a partial test of this, I replaced each occurrence of 0.6666666666e-14 with ((2/3)*10^(-14)), and got the following: 96.518370 2.76902582 0.3832106715 0.47576578081 0.475765780540 0.4740104054132 0.47395785560670 0.473963986083011 0.4739638985041114 0.47396393353565157 0.473963946672481361 0.4739639466724813721 0.47396394663744982527 Several other constants in your expression also appear to be truncations of exact numbers. I do not believe that you can accurately evaluate the expression without increasing the precision of the constants. (Where did the constants come from?)

## partial solution...

Here is a partial solution. Perhaps someone can think of how to get farther.
```with(plots):
p1:= plot(100*x, x=0..1, color='red'):
p2:= plot(x^2, x=0..1, color='blue'):
p12:= display([p1, plottools:-scale(p2,1,100)]):
p0:= plot(x^2, x=0..1, color='white', axis[1]=[color='white']):
display(Matrix(1, 2, [p12,p0]));
```
A color-coded variant is the following.
```with(plots):
p1:= plot(100*x, x=0..1, color='red'):
p2:= plot(x^2, x=0..1, color='blue'):
p12:= display([p1, plottools:-scale(p2, 1, 100)], axis[2]=[color='red']):
p0:= plot(x^2, x=0..1, color='white', axis[1]=[color='white'], axis[2]=[color='blue']):
display(Matrix(1, 2, [p12, p0]))
```
[Aside: why doesn't `display(p2,color='white')` display a blank plot?]

## image export workarounds...

I have sometimes had problems exporting plots in particular formats. When that has happened, there has always been another format that did work (so far!). Hence, if a .ps is needed, maybe try exporting in .bmp (for example), then converting the .bmp to .ps. I use The Gimp to convert (because I have it installed), and there are several other free programs that can convert.

## sets vs. lists...

I was trying for the answers that Schivnorr gave in his examples. If order and repeats do not matter (as Schivnorr says), then just replace `[]` with `{}` in the the folding code. `L-> foldl((l,r)->{seq(seq(i+j,i=l),j=r)}, {0}, op(L))`

## fold?...

For example,   `foldl((l,r)-> [seq(seq(i+j,i=l),j=r)], [0], op(L))`

## bug in limit...

Here is a simpler example. ```p:= piecewise(t<0, <0,t>, <t,0>): limit(p, t=0, 'left'); ``` The result is <0,t>. [I cannot get Vectors to display properly either; JacquesC, tell us the incantation!]

## Analytic Functions and matrices...

orionlt, see the Help for  `MatrixFunction`.

## maximum and minimum...

The problem apparently asked for the maximum and minimum. Hence the local Optimization routines cited by Scott03 would be inappropriate. Maple provides `maximize` and `minimize`, which swiftly give the exact answers. ```y := 3*X^4+2*X^3-15*X^2+13*X+3; maximize(y);```         infinity `minimize(y);` [answer is long and complicated] `evalf(%);`         -51.00552571
 1 2 3 Page 1 of 3
﻿