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!