I have a function in 2 variables x1,x2
f = 3*x1^2 + 4*x2^2 + 5*x1 + 6*x2 + 10
Consider x
is a row vector such that x = [x5,x6]
, where x5,x6
are components of the vector. If the notation is confusing, let us consider x = [x1,x1]
but x1,x2
can be any arbitrary components. The same argument holds for y
.
Then I want to find a
from (x + ay)
such that it will minimize the f
. a
is real constant, x
and y
are vectors. This is explained above.
If this does not make sense, then let us consider x,y
as a 1-dimensional arrays with 2 locations. So, x(1),x(2),y(1),y(2) be their components. Then I want to multiply array y
by a symbolic variable a
.
For example, x=[4,5]
, y=[-2,3]
then, (x + ay) = (4,5) + a(-2,3) = (4-2a,5+3a)
. a
is symbolic variable that is unknown here.
Substituting in f1
(To be more clear, first argument in the definition of f
x1 = 4-2a
, second argument x2=5+3a
)
f1 = 3*(4-2a)^2 + 4*(5+3a)^2 + 5*(4-2a) + 6*(5+3a) + 10
............(eq. 1)
Then function f1
becomes unknown in one variable, a
and can be minimized using 1D minimization algorithm, such as golden section search, given an interval [x_lower,x_upper]
.
My question is:
Given different x
,y
,
- How to evaluate
(x+ay)
and pass (or substitute ?) it into functionf (eq1)
? - How to create 'dynamic' function
f1
, as in eq. 1, to pass it to 1D minimization algorithm? By dynamic, I mean here is functionf1
will change every time forx
,y
.
I am interested in a low-level implementation of this problem (sticking to the basic features of a language as much as possible and without using language specific features or object oriented features) in python, MATLAB, C or any other language, but again in 'low level.' Can you suggest something?
UPDATE: I don't want to use symbolics from python, MATLAB or from any other language.