How to obtained matris vector solution using fminunc function?
1 回表示 (過去 30 日間)
古いコメントを表示
採用された回答
Torsten
2023 年 3 月 25 日
編集済み: Torsten
2023 年 3 月 25 日
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 ?
2 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!