How to solve a nonlinear least squares with 3 variables

18 visualizaciones (últimos 30 días)
John Lee
John Lee el 19 de Nov. de 2021
Comentada: John Lee el 1 de Dic. de 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,

Respuesta aceptada

Pratyush Roy
Pratyush Roy el 1 de Dic. de 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!

Más respuestas (0)

Categorías

Más información sobre Problem-Based Optimization Setup en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by