mmcdara

4009 Reputation

17 Badges

6 years, 176 days

MaplePrimes Activity


These are questions asked by mmcdara

How can I use fdiff within Optimization:-NLPSolve and get rid of this error?

Here is an example

restart:
with(Optimization):

# with exact gradient
obj := proc(v)
         10*v[1]^2 - 2*v[1]*v[2]^2 + v[2]^4 + 1 - 2*v[2] + v[2]^2
       end proc:

objgrad := proc(v, w)
        w[1] := 20*v[1] - 2*v[2]^2:
        w[2] := -4*v[1]*v[2] + 4*v[2]^3 - 2 + 2*v[2]
end proc:

NLPSolve(2, obj, objectivegradient=objgrad);
[0.276597509679878506, [0.0364560120817733,0.603788442821000]]


# with approximated gradient estimated "by hand"
objgrad := proc(v, w)
        local eps  := 1e-8:
        w[1] := ( obj(v+~[eps, 0]) - obj(v-~[eps, 0]) )/(2*eps):
        w[2] := ( obj(v+~[0, eps]) - obj(v-~[0, eps]) )/(2*eps):
end proc:

NLPSolve(2, obj, objectivegradient=objgrad);
[0.276597509679878562, [[0.0364560121188285,0.603788442801479]]


# with approximated gradient computed with diff
objgrad := proc(v, w)
        w[1] := fdiff(obj, [1], v);
        w[2] := fdiff(obj, [2], v);
end proc:

NLPSolve(2, obj, objectivegradient=objgrad);
Error, (in Optimization:-NLPSolve) invalid input: fdiff expects its 3rd argument, X, to be of type {algebraic, equation, list(algebraic), list(equation), set(equation)}, but received Vector[row](2, {(1) = 1.0, (2) = 1.0}, datatype = float[8])


Thanks in advance

Could someone suppress one of these two questions
232574-Error-In-Parametric-Plot
232573-Error-In-Parametric-Plot

and put tomleslie's answer and mine on the same threads?

TIA

Hi,

This question is related to the answer I gave to this question 232564-I-Need-To-Learn-What-Type-Of-Calculation

In a few words the OP (planetmknzm) wanted to know how a Maple's procedure (PlanePlot) was doing some calculus.
I proposed him to redirect the output of print('PlanePlot') to a mpl file, to open this latter, to insert a DEBUG() command and follow step by step what was going on.

If I execute the whole procedure (whose name is MyPlanePlot) I get this strange error
Error, (in MyPlanePlot) Colours is not a command in the Student package
Indeed PlanePlot contains instructions like this one

pl_Basis := plots['arrow']([[p, B[1]], [p, B[2]]], 'width' = pl_scale, 
      'colour' = Student:-Colours[2], op(basisoptions))

Searching for Colours in the help pages confirms what the error message says, but browsing the library with the assistant reveals that Student:-Colours does exist.

PlanePlot.mw

Do packages contain commands that are not accessible to users?
Why does PlanePlot work but its "clone" MyPlanePlot doesn't?
Last but not least, is there a way to fix this ?


Thanks in advance


PS : I discovered this issue as I was about to propose to planetmknzm another way to asked his previous question  232518-How-Can-We-Assign-The-Values-Of-Basis (just insert return B[1], B[2]: before the end of MyPlanePlot to get the vector basis)

Here is an example where (f@g)(..) cannot be written f(g(..)): When is @ necessary?

restart:
with(Statistics):
interface(displayprecision=4):
S := Sample(Uniform(-1, 1), 10):
((max-min)/Mean)(S);  # correctly evaluated

abs(Mean(S)); # correctly evaluated

((max-min)/abs(Mean))(S);  # unevaluated value: abs(Mean) appears as  |Statistics:-Mean| 

((max-min)/(abs@Mean))(S);  # correctly evaluated

 

Why does  1e-(Digits) return 1. and 1e-Digits generate an error?
 

1e-Digits;
Error, missing operator or `;`

1e(-Digits); 
                               1. 
type(Digits, posint)
                              true

 

5 6 7 8 9 10 11 Last Page 7 of 34