I am trying to do a backtracking line search algorithm for a stepest decent problem. This bascial means I need to keep using the gradiant and eventually the hessian alot. But I am trying to compare the operators to be able to compare and I just cant get it. below is my code and a photo of what i am trying to do.

 採用された回答

Walter Roberson
Walter Roberson 2020 年 12 月 4 日

0 投票

You missed the point that requires that the gradient of f be evaluated at x. You are taking the symbolic gradient of f into gf, but you are not evaluating it at x.
Note: if you have a symbolic gradient gf, then you do not need to re-calculate it every iteration: you can calculate gf once and evaluate gf with the current x at every step.

5 件のコメント

Chance Anderson
Chance Anderson 2020 年 12 月 4 日
thank you
Chance Anderson
Chance Anderson 2020 年 12 月 4 日
So on this function the orginal function would be comprised of x_1, x_2, x_3, x_4, x_5, x_6 how would one evaluate the overall funtion at one particule point?
Walter Roberson
Walter Roberson 2020 年 12 月 4 日
subs(gf, [x_1, x_2, x_3, x_4, x_5, x_6], x)
Chance Anderson
Chance Anderson 2020 年 12 月 4 日
hey thanks for the help, im not very good at this and your help is very useful cause.
Chance Anderson
Chance Anderson 2020 年 12 月 4 日
So im sorry to ask again
I tried using this evalualtion at several different points of the code. Am i using it in the wrong context
f =
-log((x_2/5 - 1)*(x_5/2 - 1)*((2*x_4)/5 - 1)*(x_1/10 - 1)*((3*x_6)/5 - 1)*((3*x_3)/10 - 1)*(x_1^2 - 1)*(x_2^2 - 1)*(x_3^2 - 1)*(x_4^2 - 1)*(x_5^2 - 1)*(x_6^2 - 1))
gf =gradient(f);
subs(gf, [x_1, x_2, x_3, x_4, x_5, x_6], x);
deltax = -1*gf;
a = .3;
b = .8;
t = 1;
inc = 1;
step = 0;
startq = f + a * t * gf.' * deltax;
track = f + a * t * gf.' * deltax;
while startq < track
t = t * B^inc;
disp(inc);
inc = inc +1;
disp(track)
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSymbolic Math Toolbox についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by