lsqnonlin: failure in initial user-supplied function

조회 수: 2 (최근 30일)
Emilie Mussard
Emilie Mussard 2016년 10월 28일
편집: Matt J 2016년 10월 28일
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