How to solve a nonlinear least squares with 3 variables

6 visualizzazioni (ultimi 30 giorni)
John Lee il 19 Nov 2021
Commentato: John Lee il 1 Dic 2021
% I would like to find u=[ u(1); u(2); u(3)]; size(u)=3-by-1;
"rho" and "rho2" are also functions of "u" and all scalar values and defined as below.
rho=norm(s-u) % s is a known 3-by-1 vector; so rho is Euclidian distance between s and u, i.e. sqrt((s(1)-u(1))^2+(s(2)-u(2))^2+(s(3)-u(3))^2).
rho2=a'*(s-u)/norm(s-u); % a is a known 3-by-1 vector
Does anyone know how to minimize the functin below?
h-G*u-Q*rho-R*rho2 ; % h is 4-by-1 kown matrix; G is a 4-by-3 kown matrix; and Q, R all are 4-by-1 kown matrix;
Actually I wanated to solve h-G*u-Q*rho-R*rho2=0 but it is overdetermined. So the nonlinear least squares method can be applied to this problem.
Thanks,
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Risposta accettata

Pratyush Roy il 1 Dic 2021
Hi John,
The lsqonlin can be used to solve non linear least squares problems numerically.
The following code snippet might be helpful:
u0 = rand([3,1]);
s = rand([3,1]);
a = randi(10,[3,1]);
h = rand([4,1]);
G = rand([4,3]);
Q = rand([4,1]);
R = rand([4,1]);
f1 = @(u)(h-G*u-Q*norm(s-u)+R*a'*(s-u)./norm(s-u));
x = lsqnonlin(f1,u0)
Hope this helps!
1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
John Lee il 1 Dic 2021
Great, thanks, Pratyush!

Accedi per commentare.

Categorie

Scopri di più su Problem-Based Optimization Setup in Help Center e File Exchange

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by