What does this error mean? fminsearch error: "Assignment has more non-singleton rhs dimensions than non-singleton subscripts"

3 ビュー (過去 30 日間)
I am trying to Optimize these set of equations to find vector c with i=1,2:
Bold variables are 3D Vectors.
Known Variables: R, o, u1, u2, l1, l2
My code works when I use fsolve but gives me an error for fminsearch
fun.m :
function F = fun(x1,R,o,u1,u2,l1,l2)
c=x1(1:3);
kq1=x1(4);
kq2=x1(5);
q1=x1(6:8);
q2=x1(9:11);
b=x1(12:14);
bnorm=x1(15:17);
kc=x1(18);
F(1:3) = o + kq1*(o-u1) - q1;
F(4:6) = o + kq2*(o-u2) - q2;
F(7) = norm(q1-c) - R;
F(8) = norm(q2-c) - R;
F(9) = (dot((o-q1),(q1-c))*norm(l1-q1)) - (dot((l1-q1),(q1-c))*norm(o-q1));
F(10) = (dot((o-q2),(q2-c))*norm(l2-q2)) - (dot((l2-q2),(q2-c))*norm(o-q2));
F(11:13) = (kc*bnorm)-(c-o);
F(14:16) = (b/norm(b))- bnorm;
F(17:19) = (cross(cross((l1-o),(u1-o)),cross((l2-o),(u2-o)))) - b;
end
script.m :
clear all; clc;
R = 7.8;
o=[0,0,0];
u1= [7.4390,7.1380,-0.0607];
u2=[6.5360,7.1380,-0.0607];
l1=[-83.7542,77.3087,-58.0508];
l2=[66.2458,74.8087,-51.0508];
x0 = ones(1,18);
[x fval]= fminsearch(@fun,x0,[],R,o,u1,u2,l1,l2);
OUTPUT:
%

採用された回答

Matt J
Matt J 2017 年 7 月 21 日
編集済み: Matt J 2017 年 7 月 21 日
Unlike fsolve, fminsearch is not an equation solver. It minimizes a scalar-valued function. Your code fails because the objective function fun() doesn't return a scalar.
  3 件のコメント
Matt J
Matt J 2017 年 7 月 21 日
編集済み: Matt J 2017 年 7 月 21 日
@Goku,
If you do have 18 unknowns, fminsearch is, in any case, unlikely to work well. It is meant for minimizing functions of a small number of variables (typically <= 6).
Goku
Goku 2017 年 7 月 21 日
This helps.
@Alan, I now realize that the output needs to be a scalar value. I made my function to now output the norm(F) instead of F, and that does not give the error. Thank you.
Also, as @Matt J mentions, the objective function doesn't converge well, I would like to see a zero, but it gives value of 5.6196e+05 after 2275 iterations. I will have to make changes to way I solve them. But thank you for pointing that out.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by