![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/255811/image.png)
Solving a non linear least square of a sum function with two unknowns
1 次查看(过去 30 天)
显示 更早的评论
Hello,
i have a Chi-Square merit function with two unknown k1 and k2. Unfortunately, I don't know exactly which syntax to use to minimize this function in order to determine k1 and k2.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/255673/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/255674/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/255675/image.png)
Unfortunately, I am also relatively new with Matlab. I would be very happy about a step by step explanation. I have already found out that lsqnonlin can be used as a solver.
I appreciate your help. Thank you.
2 个评论
Star Strider
2019-12-18
Note that lsqnonlin fits a function to data.
Do you have a matching vector for
?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/255811/image.png)
采纳的回答
Matt J
2019-12-18
编辑:Matt J
2019-12-19
It would look like this,
kInitial = __________; %initial guess of k
kOptimal = lsqnonlin(@(k) residual(k,am,bm,cm,g,ch,bh,ah) , kInitial); %do the optimization
function r=residual(k,am,bm,cm,g,ch,bh,ah)
k1=k(1); %extract k(i) into separate variables, for convenience
k2=k(2);
numerator=cm+bm*k2+am*k1; %calculate numerator expression for all m
denominator=ch+bh*k2+ah*k1; %calculate demonator expression for all m
r=numerator./denominator - g; %calculate the vector of residuals, for all m
end
3 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!