Hi tomtomo,

Maple has two different facilities for optimization: one that works symbolically (the minimize and maximize commands), and one that works numerically (the Optimization package). Only the numerical optimization package understands units.

Indeed, if you replace minimize with Optimization:-Minimize, and do a little surgery to the line after it to get the parameter assignments to work correctly, you get an answer. You need to change the assign command on the next line to just "assign(%[2])" to make it work with the simpler output from Optimization:-Minimize. Moreover, you also need to change the visualization commands a bit to work with units. However, once you've done this, you'll see that the fit is not really great. I think this is a case where you aren't really guaranteed a good fit without a **global** rather than local optimization solver. This does not come with Maple (though there are third party solutions, and indeed even a Maplesoft toolbox, that do that).

That said, as I was writing this up, I noticed a mistake earlier on. You use the convert/radians command, together with Unit(degrees). They do not work together, and indeed there should be at least a warning to that effect in both the help page and the command itself. This ends up causing *two* conversions from degrees to radians, which is not what we need. Instead, you can just use '90*Unit(degrees)' there.

I reworked that section of your worksheet a bit, which ended up with the following -- and note that the fit in this case ends up being very good. To make it self-contained, I'll include the definition of the 'data' Matrix. Some of the things I do manually below happen automatically when you load the Units:-Simple package; I would recommend that, actually, but figured I'd show how to do it without that.

`data := Matrix([`

[81*Unit(knot), 1600*Unit(ft), 0, 89*Unit(knot), 179*Unit(degrees), 179*Unit(degC)],

[81*Unit(knot), 1600* Unit(ft), 0, 77*Unit(knot), 303*Unit(degrees), 303* Unit(degC)],

[81*Unit(knot), 1600*Unit(ft), 0, 95*Unit (knot), 72*Unit(degrees), 72*Unit(degC)],

[81*Unit(knot), 1600*Unit(ft), 0, 98*Unit(knot), 95*Unit(degrees), 95* Unit(degC)]]);

F := a*x + b*y + x^2 + y^2 + c;

XY := Matrix(4, 2);

for i to 4 do

X := evalf(data(i, 4)*cos(-(data(i, 5) - 90*Unit(degrees))));

Y := evalf(data(i, 4)*sin(-(data(i, 5) - 90*Unit(degrees))));

XY[i, 1] := X;

XY[i, 2] := Y;

end do;

Optimization:-Minimize(add(eval(F, {x = XY[n, 1], y = XY[n, 2]})^2, n = 1 .. 4));

# result: approx. [1941 * Unit(m^4/s^4), [a = -10.5*Unit(m/s), b = 2.8*Unit(m/s), c = -1971*Unit(m^2/s^2)]]

assign(%[2]);

# Original: TAS := evalf(sqrt(c)); # this shows the unit 'sqrt(m^2/s^2)'; to simplify that, use combine(..., units) - and you don't need the evalf here, it's automatic.

TAS := combine(sqrt(c), units);

xC := 0.5*a;

yC := 0.5*b;

wind_spd := sqrt(xC^2 + yC^2); # result: about 5.43*Unit(m/s)

# Original: wind_dir := arctan(yC/xC); # because Maple doesn't know where the negative sign comes from after the division, you don't find the correct quadrant -- instead, use 2-argument arctan:

wind_dir := arctan(yC, xC); # result: 2.88 (implied unit: radians)

# Need to evaluate the sines and cosines; this would happen automatically with Units:-Simple

XY_combined := map(combine, XY, units);

A := plots:-pointplot(XY_combined);

# implicitplot doesn't know how to handle units, so we need to strip them out and deal with them manually

F_no_units := eval(F, Units:-Unit = 1);

B := plots:-implicitplot(F_no_units, x=-180..180, y=-180..180, color=green);

plots:-display(A, B);

Hope this helps!

Erik Postma

Manager, mathematical software group

Maplesoft.