Solve Conjugate Gradient using excel
Software
n this tutorial, we try to illustrate how to solve non linear function using conjugate gradient method by excel. We will use example 3.9 page one 20 in the book of engineering optimization methods and applications. A second edition. Here are, as you can see, our objective function is equal to four X one squared plus three X two squared minus four X one X two plus X one. Then we have our initial point X zero, which is equal to zero and zero. We found our we found the gradient of our objective function to be 8 X one minus four X two plus one 6 X two minus four X one. Then when we evaluate our X zero point, the initial point, and the gradient, we found the gradient at X zero to be one and zero. Now we have to define the matrix, the gradient of X zero, first we label the matrix that we want to define, then we go to insert, name, then define and we write the name of the matrix that we want to define. Gradient of F of X zero, then we have to define S zero the same way we go to insert, name, define then S zero now we have to find the next point which is X one using this formula. X one is equal to X zero plus alpha zero S zero. And S zero is equal to the negative of the gradient. Here we write first we label the S zero as a matrix, then we write equal minus the name of the gradient that we defined gradient of X zero. Then we have to click at control shift enter. As you can see, the value of S zero is minus one and zero. Then we have to give alpha zero an initial point. Here we will give it an initial point, which is ten. Then X one is equal to X zero, which is zero plus alpha alpha zero which is ten times S zero, which is minus one, and so then here is the same way zero plus alpha times zero. As you can see, the value of X one is minus ten and zero. Here we have to find the value of X one at the objective function. We write equal four times X one, which is minus ten squared. Plus three times X two, which is zero squared. Plus X one, which is minus ten. As you can see, the value of X one is equal to 390. Now we should find the exact value of alpha zero using the excel solver by going to tools, solver, and this cell you specify the function cell in our case this cell. And you click on minimizer, and this cell you specify the variable cell, which is AlphaZero, then you add the constraint that AlphaZero should be greater than or equal to zero. Then you click the solve, so here you can see the exact value of AlphaZero and X one. Now we want to find X two, so we need to find the gradient of the function at X one, which is zero and .5. So S one by using this formula is the negative of the gradient at F one plus the norm of the gradient at X one squared divided by the norm of the gradient at X zero squared, multiplied by S zero. So first we should define this matrix by going to insert name define, let's name it the gradient of the function at X one. And we should define S one as well. We're going to answer it name defined. Let's name it SS one. Okay. So S one equals negative of the gradient function at X one. Plus the norm of the norm of the gradient at X one, which is this cell squared plus this cell squared divided by the norm of the gradient at X zero, which is this cell squared plus this cell squared, multiplied by S zero. Then we should click on control shift enter. So here we can see the value of S one, which is -.25 and -.5. After finding S one, now we need to find X two, which is defined by this formula X two equals X one plus alpha one multiplied by S one. So now we will repeat the same steps that we have done for X one. So we will give alpha one an initial value. Let's just say ten. And then we have to we have to find X two, which is equal to X one plus alpha one, multiplied by S one. Then X one. Plus alpha one, multiplied by S one. After that, we have to find the F of X two, which is equal to four multiplied by X one squared plus three multiplied by X two. Squared. Minus. Four multiplied by X one, multiplied by X two plus X one. Enter. So now we will find the exact value of alpha using the solver. We can reach the solver by going to tools, solver. In this cell, we will define the objective function F of X two. And in this cell, we will define our variable, which is in our case. Alpha one after that, we will add a constant, which is alpha one, greater than or equal to zero. Okay, then solve. Okay, and this is the exact solution of alpha one and X two. So you can repeat these iterations to reach the optimal solution. Thank you for listening to us, and that's the end of our tutorial.