gone gone gone deleted

gone gone gone gone

1 Comment

Original question by Sarah Garcon:
FMINCON error: Failure in initial objective function evaluation. FMINCON cannot continue.
I am trying to find the coordinates of the center of rotation as seen by the coordinate systems of the two sensors using a file (data1.mat) that includes the coordinates of the positions (rM3 and rM4, 3xN vectors, with N=1001 measurements for the components of x, y, and z of the sensor position vector) and orientations (R3 and R4, 3x3xN vectors, including the rotation matrices describing the orientation of the sensor frame as seen from the world frame) of two sensors placed on two rigid bodies subject to a rotation about a single point.
Below if what I tired and the error that i keep on getting
main code
function y = normcalc(x,rM3, R3, rM4, R4)
rs1 = rM3 + R3*x(1:3);
rs2 = rM4 + R4*x(4:6);
y = sum(norm(rs1-rs2));
end
from command window
>> load('data1.mat')
>> fun = @normcalc;
>> x0 = [0,0,0,0,0];
>> A = [];
>> b = [];
>> x = fmincon(fun,x0,A,b)
Not enough input arguments.
Error in normcalc (line 2)
rs1 = rM3 + R3*x(1:3);
Error in fmincon (line 546)
initVals.f = feval(funfcn{3},X,varargin{:});
Caused by:
Failure in initial objective function evaluation. FMINCON cannot continue.

Sign in to comment.

Answers (1)

Try this instead:
x = fmincon(@(x)fun(x,rM3, R3, rM4, R4),x0,A,b)
I cannot run your code since I don’t have the file. I assume it otherwise works, and the calculations are correct.

2 Comments

That operation is never going to work.
First,
R3*x(1:3)
needs to be replaced by:
bsxfun(@mtimes,R3,x(1:3))
that if ‘x’ is a row vector then produces a (3x3x1001) result because that is the size of ‘R3’, however if ‘x’ is a column vector, regardless of the order, the dimensions are incompatible and there is no result.
In any event, since ‘rM3’ is a (3x1001) matrix, those results are incompatible so the addition operation will fail.
You need to reconfigure whatever it is that you’re doing.
I will delete my Answer in a few hours.
Original comment by Sarah Garcon:
Array dimensions must match for binary array op.
Error in normcalc (line 2)
rs1 = rM3 + R3.*x(1:3);
Error in @(x)fun(x,rM3,R3,rM4,R4)
Error in fmincon (line 546)
initVals.f = feval(funfcn{3},X,varargin{:});
Caused by:
Failure in initial objective function evaluation. FMINCON cannot continue.
I have also attached the file

Sign in to comment.

Categories

Tags

Asked:

on 3 Dec 2020

Commented:

on 3 Dec 2020

Community Treasure Hunt

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

Start Hunting!