On 2/12/2013 2:09 PM, Pl Pl wrote: > Alan_Weiss <firstname.lastname@example.org> wrote in message >> Your function llgfix returns a three-element vector instead of a >> scalar. The objective function for fmincon must be a scalar, just as >> the error message states. >> >> Alan Weiss >> MATLAB mathematical toolbox documentation > > Oh of course, thank you Alan! But then, how can I solve this system > with the unit-sphere constraint..?
Well, you could add the squares of dm. I mean,
function dm = llgfix(t,m,param) dm = zeros(3,1);
dm(1) = f1(m(1),m(2),m(3)); dm(2) = f2(m(1),m(2),m(3)); dm(3) = f3(m(1),m(2),m(3)); % And here is the change: dm = sum(dm.^2); end
This will have fmincon try to minimize the sum of squares of the vector field, which should give you the solution you seek.
If it fails, then start at a different point. And I suggest you set the fmincon algorithm to interior-point.
Alan Weiss MATLAB mathematical toolbox documentation