Matlab alternatives for gradient optimisation problems?
조회 수: 19 (최근 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!