Matlab alternatives for gradient optimisation problems?
17 次查看(过去 30 天)
显示 更早的评论
At school, I have been using maltab to solve various optimisation problems manually, without the optimisation toolbox as this is what they want us to do. I have an assignment in which I have to document solving these kinds of problems with an open-source software of my choice. I have done some research, but so far did not find any alternatives which would fit the problem. Could you suggest open-source / free software that handles data something like matlab does? Or anything that could be used for this kind of problem?
For example, this is how my implementation looks for the Newton-Raphson method:
d0 = 1
i = 0
x0 = [-1, 0]';
[f0, g0] = fun4(x0)
syms x1 x2
f = (x1-1)^2+(x2-x1^2)^2;
Hs = hessian(f)
H0 = eval(subs(Hs, [x1, x2],[x0(1), x0(2)]))
tab = [i, x0', g0, d0];
while d0 >= 0.01
x0 = x0 - H0^-1*g0'
[f0, g0] = fun4(x0)
d0 = g0*g0'
H0 = eval(subs(Hs, [x1, x2],[x0(1), x0(2)]))
i = i + 1
tab = [tab; i, x0', g0, d0];
end
I would need the same or similar functionality as used in the code, so mainly similar functions as eval(), hessian()/jacobian() and syms. fun4 includes the function defined in the variable f, its in a separate script so that it can be used repeadetly.
Thanks!
0 个评论
采纳的回答
Torsten
2022-11-8
编辑:Torsten
2022-11-8
If it fits your needs: this code would run under Octave.
%pkg load symbolic
syms x1 x2
f = (x1-1)^2+(x2-x1^2)^2;
H = hessian(f);
H = matlabFunction(H);
g = gradient(f);
g = matlabFunction(g);
x0 = [-1;0]
d0 = 1;
i = 0
while d0 >= 0.01
H0 = H(x0(1),x0(2));
g0 = g(x0(1),x0(2));
x0 = x0 - H0^-1*g0
d0 = g0'*g0;
i = i + 1
end
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!