How to solve a non linear ovedetermined system of equations??
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Alphonce Owayo
el 28 de Feb. de 2021
Comentada: Alphonce Owayo
el 4 de Mzo. de 2021
Please help me how solve this, using fmincon fsolve etc I am tired of syntax errors
eq(k)=(sqrt(x1-x0)^2+(y1-y0)^2+(z1-z0)^2)==c*(t1-t0); Unknowns are x0 y0 z0 and t0, eqn(k) are 8. I am not exactly sure what tricks to unleash with the optimization algorithms in matlab. I have even tried to simplify the equation further to sqrt (a1^2+a2^2+a3^2+a4^2==c*(ti-t0)); hoping to simplify it and solve for a1 a2 a3 and a4, find the sqrt and hopefully give a good estimate for the unknowns at this point I am frustrated its not working. I have watched all the optimization videos,they make really look easy but it isnt, someone help please before I loose my mind, thanks.
3 comentarios
Respuesta aceptada
Bjorn Gustavsson
el 28 de Feb. de 2021
You can always try with regular minimization. Perhaps something like this:
function err = err_1(pars,x,y,z,y)
c = 3; % guess, perhaps close to some factor of 10 off?
x0 = pars(1);
y0 = pars(2);
z0 = pars(3);
t0 = pars(4);
err = sum(((sqrt(x-x0).^2 + (y-y0).^2 + (z-z0).^2) - c*(t-t0)).^2);
end
Then you'll have to make an initial guess - that should preferably be close to the solution, this might be more or less important depending on the function (I haven't thought about what would be the case for your...);
x0y0z0t0_0 = [1,2,3,4]; % you hopefully have a hunch..
x0y0z0t0 = fminsearch(@(pars) err_1(pars,x,y,z,y),x0y0z0t0_0)
You can also use lsqnonlin if fminsearch is too slow. But then you'll have to modify err_1 to return reiduals instead of the sum of the residuals squared.
HTH
4 comentarios
Bjorn Gustavsson
el 3 de Mzo. de 2021
My pleasure.
...and: Yeah, in my experience lsqnonlin is "typically" more efficient. Though I find it easier to start with writing an explicit sum-of-squared-residuals and minimize that using fminsearch it is often better to rephrase the problem to use lsqnonlin.
Más respuestas (0)
Ver también
Categorías
Más información sobre Surrogate Optimization 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!