How to solve a nonlinear least squares with 3 variables
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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,
0 comentarios
Respuesta aceptada
Pratyush Roy
el 1 de Dic. de 2021
Hi John,
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)
Ver también
Categorías
Más información sobre Systems of Nonlinear Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!