Azzera filtri
Azzera filtri

lsqnonlin: failure in initial user-supplied function

2 visualizzazioni (ultimi 30 giorni)
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 Commento
Matt J
Matt J il 28 Ott 2016
Modificato: Matt J il 28 Ott 2016
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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Configure Simulation Conditions in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by