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
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!