필터 지우기
필터 지우기

Failure in initial objective function evaluation. LSQNONLIN cannot continue.

조회 수: 20 (최근 30일)
sree chak
sree chak 2020년 9월 4일
댓글: Ameer Hamza 2020년 9월 5일
I am getting the LSQNONLIN error and I am hoping that someone can take a look at my objective function. I am sure I have written it completely wrong.
x will be an input vector of [rx ry rz mx my mz]. And what I would like to get out of this are the optimized values for [rx ry rz mx my mz].
G_measured calls a function that takes in a vector called Rmeasured and dipoleMoment and spits out data of 4x6 vector (4 measurement points measuring G elements), same with G_estimate.
Any help or guidance would be appreciated as I am fairly new to this.
options = optimoptions(@lsqnonlin);
options.Display = 'iter';
options.Algorithm = 'levenberg-marquardt';
options.StepTolerance = 1e-6;
options.MaxFunctionEvaluations = 1000;
x = lsqnonlin(@lm_obj,x_init, [],[],options)
x_init = [1, 3, 5, 10, 0, 10]
function F = lm_obj(x)
G_estimate = getGradientsEstimate(x);
G_measured = getGradientsMeasured(Rmeasured, dipoleMoment)
Difference = G_estimate - G_measured;
F = norm(Difference)
end
  댓글 수: 3
sree chak
sree chak 2020년 9월 4일
Thanks for helping me with this. I did change the inputs of the getGradientsEstimate and getGradientsMeasured functions slightly. They are identical functions except the estimate function does not include noise.
Both functions sensorLoc ([x y z] position of a sensor), a targetLoc ([x y z] position of a target) and a dipoleMoment ([mx my mz] of a target). The outputs give us the five tensor elements [Gxx Gxy etc.] that are then subtracted and the error is formulated. The getGradientsEstimate instead of the targetLoc and dipoleMoment will taken in the x_init values.
getGradientsEstimate and getGradientsMeasured are defined in a separate m.files (within the same workspace) as the following:
function [G] = getGradientsEstimate(sensorLoc,targetLoc,dipoleMoment)
%Constants
mu = 4*10^(-7);
R = targetLoc - sensorLoc;
r = norm(R);
M_R = dot(dipoleMoment, R);
%B = mu/(4*pi)*((3*M_R*R(i,:))/r^5 - dipoleMoment(i,:)/r^3);
Gxx = mu/(4*pi)*((-15*M_R*(R(1,1))^2)/r^7 + 3*(2*dipoleMoment(1,1)*R(1,1) + M_R)/r^5);
Gyy = mu/(4*pi)*((-15*M_R*(R(1,2))^2)/r^7 + 3*(2*dipoleMoment(1,2)*R(1,2) + M_R)/r^5);
Gxy = mu/(4*pi)*((-15*M_R*R(1,1)*R(1,2))/r^7 + 3*(dipoleMoment(1,1)*R(1,2)+ dipoleMoment(1,2)*R(1,1))/r^5);
Gxz = mu/(4*pi)*((-15*M_R*R(1,1)*R(1,3))/r^7 + 3*(dipoleMoment(1,1)*R(1,3)+ dipoleMoment(1,3)*R(1,1))/r^5);
Gyz = mu/(4*pi)*((-15*M_R*R(1,2)*R(1,3))/r^7 + 3*(dipoleMoment(1,2)*R(1,3)+ dipoleMoment(1,3)*R(1,2))/r^5);
G = [Gxx Gyy Gxz Gyz Gyz];
end
function [G] = getGradientsMeasured(sensorLoc,targetLoc,dipoleMoment)
%Constants
mu = 4*10^(-7);
%Gaussian Noise added individually to each tensor element
gradSigma = (50/3)*10^(-15); %based on the 100fT description in the data sheet
noise = gradSigma*randn(1);
R = targetLoc - sensorLoc
r = norm(R);
M_R = dot(dipoleMoment, R);
%B = mu/(4*pi)*((3*M_R*R(i,:))/r^5 - dipoleMoment(i,:)/r^3);
Gxx = mu/(4*pi)*((-15*M_R*(R(1,1))^2)/r^7 + 3*(2*dipoleMoment(1,1)*R(1,1) + M_R)/r^5) + noise;
Gyy = mu/(4*pi)*((-15*M_R*(R(1,2))^2)/r^7 + 3*(2*dipoleMoment(1,2)*R(1,2) + M_R)/r^5)+noise;
Gxy = mu/(4*pi)*((-15*M_R*R(1,1)*R(1,2))/r^7 + 3*(dipoleMoment(1,1)*R(1,2)+ dipoleMoment(1,2)*R(1,1))/r^5)+noise;
Gxz = mu/(4*pi)*((-15*M_R*R(1,1)*R(1,3))/r^7 + 3*(dipoleMoment(1,1)*R(1,3)+ dipoleMoment(1,3)*R(1,1))/r^5)+noise;
Gyz = mu/(4*pi)*((-15*M_R*R(1,2)*R(1,3))/r^7 + 3*(dipoleMoment(1,2)*R(1,3)+ dipoleMoment(1,3)*R(1,2))/r^5)+noise;
G = [Gxx Gyy Gxz Gyz Gyz];
end
Ameer Hamza
Ameer Hamza 2020년 9월 5일
getGradientsEstimate() needs 3 input variables, whereas you are only passing in one variable. I guess the vector x_init combines the value of sensorLoc, targetLoc, and dipoleMoment, but you need to split x vector into 3 variables and then pass it to these functions.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by