It's not surprising that calling Optimization:-Maximize would take longer, as the routine is truly trying to find the optimal point within given tolerances. Note that the Optimization package usually does local optimization, but in this particular case -- one-variable optimization over a bounded range -- a branch-and-bound global solver is used.
The way ctomkins was doing the optimization was to use the plot routine to sample the function and then take the maximum value of the sample points. That in itself is a simple form of numerical optimization, and if the answer is good enough to meet the accuracy needs, then that's a fast way of doing it. The danger was in using the plot routine recursively and examining the internal structure. An alternative is to write a simple routine to do your own sampling of the expression and compute the maximum value. That would be even faster than calling the plot routine. I suggested Optimization because I believe that is closer conceptually to what ctomkins is really trying to do: find the point at which a mathematical expression is maximized.
Paulina Chin
Maplesoft
I used an approach similar to acer's and was able to get the desired results. The only minor problem in acer's example is that the maximum value is being returned. Instead, ctomkins would like the point at which the maximum value is achieved. The line "return result[1];" needs to be replaced by "return rhs(op(result[2]))". A nicer way to get the solution value, using slightly more code, is to use the Optimization solution module. (See the Optimization/Solution help page for more details.)
Paulina Chin
Maplesoft
The reason you are seeing strange results is because you are calling plot() recursively, and the command was not designed to handle this situation. I wouldn't recommend calling plot() and examining the internal data structure to compute the maximum value of an expression. Instead, try using the Optimization:-Maximize routine. To do this, replace your plot() call in Q_opt by a call to Optimization:-Maximize. This returns a result that looks like [u, [Q=v]], where u is the maximum value and v is the point at which it's achieved. Q_opt should then return v.
Paulina Chin
Maplesoft
I've verified that the error message is occurring because there are more variables than residuals, as Robert had stated. This is a limitation of the default algorithm used (method=modifiednewton). An alternative workaround to the one suggested by Robert is to use method=sqp, as our SQP algorithm doesn't have the same limitation.
I'll submit this bug to our database. We'll try to fix in a future release both the choice of default algorithm and the wording of the error message if method=modifiednewton is specified.
Paulina Chin
Maplesoft
I've submitted two bugs to our database, one for the error message originally described, and another for the missing arrow in the display when using Joe's suggested workaround. If you've already submitted the problem to Maplesoft Support, that's no problem. The report will eventually come to me anyhow and I'll close it as a duplicate. Indeed, it's best to submit problems to Support if you don't get a reply from someone saying the bugs have been submitted.
In the meantime, one workaround you can use is to set the typesetting mode to extended using interface(typesetting=extended) or the Typesetting Rule Assistant. If you then use Joe's suggestion of converting the entire expression to an atomic identifier, the arrow will show up in the display.
Paulina Chin
Maplesoft
There is indeed a problem with the axefont option and axes labels that are provided as strings. I've added this report to our bugs database and we plan to have it fixed in a future release.
Paulina Chin
Maplesoft
Robert writes: "But I would have thought that plot3d would fall back on using software floats if presented with something for which evalhf didn't work."
Yes, this ought to happen, but I've verified there is a bug in one of the internal routines which prevents the fall-back to software floats in this particular case. This will be recorded in our bugs database and fixed in a future release.
Paulina Chin
Maplesoft
Brian writes:
I'm using Maple 10 and find the Classic Interface comfortable.
Is the Classic Interface supported in 11?
OK, first understand that I'm very biased, as I was part of the team that implemented most of the Maple 11 plotting features. :-)
I truly believe that, if nice plotting features are important to you, you really ought to move to Maple 11 and the Standard Interface. The Classic Interface is still supported in Maple 10 but doesn't include the new features. The new features include: much improved array plots including the ability to combine 2-d and 3-d plots in an array; captions for plots; ability to display typeset math in titles, captions, axes labels and other places. There are many more features but these are the ones used by most people.
The view and scaling problems you're seeing with array plots still exist in Maple 11 with the Classic Interface. They're more design limitations than bugs and are very difficult to fix, but these problems don't exist with the Standard Interface implementation.
Paulina
Which version of Maple are you using? In Maple 10 and earlier, plots in an array were combined into a single plot, and consequently, view and scaling options were not always respected. In Maple 11, the plots are not combined; they maintain their individual properties and can be controlled individually through the context menus as well.
Paulina Chin
Maplesoft
As David states, the change to densityplot in Maple 11 was intentional. There were many advantages to the change, including more efficient representation. However, we felt the new behaviour is much closer to what people really want, a continuous representation of the given function. Indeed, our basic plot routines make this assumption, unless an option is given saying that the input is supposed to be discontinuous. If such an option is provided, we do our best to handle the discontinuity correctly, but this is not always easy to do. The densityplot code does not have the ability to treat discontinuities properly. The fact that the Maple 10 version gave a plot that did not look continuous was, in our view, undesirable, and indeed the change was motivated by many users who agreed.
Having said this, there is still a way to get back the Maple 10 result. We decided that listdensityplot should have behaviour slightly different from densityplot. Because users give a set of discrete points, it is possible that they would want the collection of rectangles plotted that Maple 10 provided. So for that routine, there is a smooth=false option to remove the smoothing. It is not difficult to adjust your input slightly to use that routine; you just have to do the sampling yourself and provide the actual values instead of the expression or procedure.
Paulina
I don't think it's easy to return the lowess curve as a piecewise function, unless you're just looking for a spline to go through the computed points. There is a not-so-pretty way to extract the points out of a plot data structure. Once you've done that, you can fit a spline through them.
I should state here that I'm not an expert on lowess smoothing, and I didn't work on this part of the Statistics package. However, from what I understand, lowess smoothing involves computing each new point by fitting a polynomial through a local subset of the data. I'm not sure how one can get a continuous piecewise function from the result without resorting to a spline. Perhaps someone else who better understands lowess smoothing will have an answer.
Paulina
Hi Douglas,
You cannot easily recover the curve from ScatterPlot. However, if you have the form of a curve that you want to fit to the entire set of data, you can use the regression routines described on the Statistics/Regression help page to do this fitting. These routines will return the expression representing the curve to you, and you can plot it or do other computations with it. There is also a way to get the computed residuals immediately. See the Statistics/Regression/Solution help page for instructions.
However, these routines don't offer the lowess smoothing. Because lowess smoothing involves fitting locally over a small number of points, it's not so easy to get a general curve out of the results. For local interpolation (rather than least-squares fitting), you can also look at the CurveFitting[Spline] command.
Paulina
dcasimir writes:
I sent a private message to Paulina Chin.
Any other ideas of bringing this to
Maplesoft's attention ?
While I don't mind getting questions from users and I do try to answer when I can, sending general support questions directly to me is not the most reliable way to get a quick response. I try to read MaplePrimes regularly, but as a developer, I participate as time permits and might go for days without visiting the site.
If you don't get an answer to your post within a reasonable amount of time, then the best thing to do is contact the Maplesoft support team. (See the "Customer Support" menu at the top of our company home page, www.maplesoft.com.) The support team members are able to direct your question to the most appropriate developer, if they can't answer it themselves. Also, if your problem turns out to be a bug, they will make sure it's recorded in our database.
Paulina
Andrew, did you try the instructions for uploading files at
this page?
I had trouble replying to your private message. Do you have receipt of private messages enabled in your settings? You can also send a message or worksheet to me via Maple Support. If you include my name, it will get to me.
Paulina Chin
Maplesoft
Andrew, could you send the worksheet to me? It'll be easier to determine the problem if I can see the exact input you're giving to Maple. Thanks.
Paulina Chin
Maplesoft