lsqnonlin: failure in initial user-supplied function

1 回表示 (過去 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 Center および File ExchangeConfigure Simulation Conditions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by