How to obtained matris vector solution using fminunc function?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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 ?
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!