How to solve a nonlinear least squares with 3 variables

10 vues (au cours des 30 derniers jours)
John Lee
John Lee le 19 Nov 2021
Commenté : John Lee le 1 Déc 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,

Réponse acceptée

Pratyush Roy
Pratyush Roy le 1 Déc 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!

Plus de réponses (0)

Catégories

En savoir plus sur Systems of Nonlinear Equations dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by