Matlab alternatives for gradient optimisation problems?
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kristóf Berta
am 8 Nov. 2022
Bearbeitet: Torsten
am 8 Nov. 2022
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 Kommentare
Akzeptierte Antwort
Torsten
am 8 Nov. 2022
Bearbeitet: Torsten
am 8 Nov. 2022
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!