lsqnonlin: failure in initial user-supplied function

2 次查看(过去 30 天)
Dear MATLAB users, I have some troubles with lsqnonlin. I either obtain an error saying: Failure in initial user-supplied objective function evaluation. LSQNONLIN cannot continue. if I use the function as provided below, or obtain an error saying: User-defined Jacobian is not the correct size: the Jacobian matrix should be 3-by-3. if I define the Jacobian as
J = [-TE.*x(2).*e; e+delta; delta];
But I disagree with this because I have only one function with three variables, hence the jacobian should be 1 by 3...
Any idea to help me would be greatly appreciated! Thank you!
My function:
function map = r2PixelFitNonLinDelta(M, TE)
M = squeeze(M);
if(size(TE,1) == 1)
TE = TE';
end
options = optimset('Display','off','MaxIter',100,'TolFun',1e-6,'Jacobian','on');
R2 = 0.08;
M0 = 1;
delta0 = 0.09;
x0 = [R2;M0;delta0];
map = zeros(size(M,1),size(M,2),numel(x0));
for y = 1:size(M,1);
parfor x = 1:size(M,2);
dat = reshape(M(y,x,:),[numel(TE) 1]);
map(y,x,:) = lsqnonlin(@(x)fun(x, TE, dat), x0 , [] , [], options);
end
end
end
function [F J] = fun(x, TE, M)
delta = x(3);
e = exp(-TE.*x(1));
F = x(2).*(e + delta) - M;
J = [-TE.*x(2).*e, e+delta, delta];
end
  1 个评论
Matt J
Matt J 2016-10-28
编辑:Matt J 2016-10-28
I disagree with this because I have only one function
You should probably give us input M,TE with which to test your function, but I see no reason why F as returned by fun(x, TE, M) would be a scalar, as you seem to claim.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by