Maple - Substituting into Equation
I am having difficulty setting up a function that I am inserting into x1[1]
and x2[1]
into it. Any help would be greatly appreciated.
My code:
restart;
with(LinearAlgebra);
x1[1] := -2+1606*alpha;
x2[1] := 2+400*alpha;
f := proc (alpha) options operator, arrow; (-x1[1]^2+1)^2+100*(-x1[1]^2+x2[1])^2 end proc;
Exiting f reserves x1[1]
and x2[1]
does not replace them -2+1600*alpha
and 2+400*alpha
on request.
f(0);
then does not give the desired output 409.
I can physically substitute -2+1606*alpha
and 2+400*alpha
a, as shown in the following function g
. Although this is not what I would like as I would like it to accept everything x1[1]
and x2[1]
rather than execute them manually.
g := proc (alpha) options operator, arrow; (1-(1606*alpha-2)^2)^2+100*(2+400*alpha-(1606*alpha-2)^2)^2 end proc
g(0);
Here g(0);
gives 409 at will.
I have attached a photo below of how the maple tree exit appears on my screen.
source to share
When a statement procedure is applied to an expression, Maple does so before evaluating. In the expression
f := proc (alpha) options operator, arrow; (-x1[1]^2+1)^2+100*(-x1[1]^2+x2[1])^2 end proc;
which is the same as using the notation "arrow"
f2 := alpha -> (-x1[1]^2+1)^2+100*(-x1[1]^2+x2[1])^2;
then Maple looks for anyone alpha
. There's nothing here. When you call f(0)
, the expression is evaluated with (non-existent) alpha
from the operator invocation. Thus, f(x) = f(0)
for anyone x
. From the help page :
Using the option arrow also disables Maple's simplification rules, which add any non-local names in a statement to the parameter list. This parameter is irrelevant for modules.
Instead, you can use an operator unapply
that returns the operator of the expression being evaluated. It becomes a little clearer when you define a variable expr
as the content of your function.
expr := (-x1[1]^2+1)^2+100*(-x1[1]^2+x2[1])^2;
f := alpha -> expr;
h := unapply(expr, alpha);
h(0); # returns 409
source to share