Nonlinear least square minimization using 2 variables
이전 댓글 표시
Hello,
I am trying to fit computed data (dIdV) with experimental data (STSavg). I would like write a function where A and B is varied such that the sum of the squares of the function (f) is minimized. Ideally, I would be able to see the minimum value and also the values for A and B.
f = ((STSavg - B)/ A - 10^10*dIdV)^2
%STSavg is a 300x1 array. (Values ~ 10^-1)
%dIdV is also a 300x1 array. (Values ~ 10^-9)
%dIdV by a factor of 10^10, to have comparable magnitude as STSavg
I have written this in Mathematica, but would like to convert it to Matlab. Here is the Mathematica script, which may provide an idea of what my goal is:
1. Minimize X^2 between STS and dI/dV, assuming linear transformation.
2. Cut off points near edge, as they may be noisy.
cutpts = 10;
OM = FindMinimum[Total[((STSavg2[[cutpts ;; TotPts - cutpts]] - B)/A - 10^10 didv[[cutpts ;; TotPts - cutpts]])^2],{{A, 0.1}, {B, 1}}]
OFFSET = B /. OM[[2]] , MAGNITUDE = 10^10 A /. OM[[2]]
Output: {639.834, {A -> 0.0389278, B -> -0.174553}}
Output: OFFSET = -0.174553
Output: MAGNITUDE = 3.89278 * 10^8
I've read about "fminsearch" and using anonymous functions, but I'm slightly confused as to what the input arguments should be when creating the function for two variables (A and B).
Thanks, Chris
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Linear Least Squares에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!