How to solve a non linear ovedetermined system of equations??
조회 수: 3 (최근 30일)
이전 댓글 표시
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
채택된 답변
Bjorn Gustavsson
2021년 2월 28일
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
Bjorn Gustavsson
2021년 3월 3일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!