How to obtained matris vector solution using fminunc function?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
c_1=[3;5;8];
c_2=[2;6;8];
fun = @(x) (x(1)-c_1).^2 + (x(2)-c_2).^2; % cost function
x0 = [[0.1;0.1;0.1],[0.1;0.1;0.1]]; % İnitial Gues
[x,fval] = fminunc(fun,x0) % Results
0 Kommentare
Akzeptierte Antwort
Torsten
am 25 Mär. 2023
Bearbeitet: Torsten
am 25 Mär. 2023
You will have to use fminunc three times:
c_1=[3;5;8];
c_2=[2;6;8];
x1_sol = zeros(size(c_1));
x2_sol = zeros(size(c_1));
for i=1:numel(c_1)
fun = @(x) (x(1)-c_1(i)).^2 + (x(2)-c_2(i)).^2; % cost function
x0 = [0.1,0.1]; % İnitial Guess
[x,fval] = fminunc(fun,x0); % Results
x1_sol(i) = x(1);
x2_sol(i) = x(2);
end
x1_sol
x2_sol
Or do you try to solve a different problem ?
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!