checkGradients, but the objective function has two inputs: x and xdata?
48 ビュー (過去 30 日間)
古いコメントを表示
I'm using lsqcurvefit with the following objective function and Jacobian:
function [f, jacF] = semiCircle(p, Q)
P0 = p(1);
Q0 = p(2);
r = p(3);
f = P0 + sqrt(r^2 - (Q-Q0).^2);
if nargout > 1 % need Jacobian
jacF = [1, (Q-Q0)./sqrt(r^2-(Q0-Q).^2), r./sqrt(r^2-(Q0-Q).^2)];
end
end
I'd like to use checkGradients to verify if the Jacobian is correct. However, all of the examples in the documentation just have objective functions with one input, the parameters 'x'. Whereas my function semiCircle has two inputs: the parameters 'p' and the xdata 'Q'. Is there a way to use checkGradients for such a function?
0 件のコメント
採用された回答
Torsten
2024 年 11 月 14 日 10:31
valid = checkGradients(@(p)semiCircle(p, Q),p0)
10 件のコメント
Benjamin Pepper
2024 年 11 月 21 日 11:39
編集済み: Torsten
2024 年 11 月 21 日 21:30
Torsten
2024 年 11 月 21 日 21:34
As you said: the code works fine with R2024b.
But note that the call to "lsqcurvefit" has changed in R2023a to the actual call that you use in the code. So if your desktop MATLAB version is older than R2023a, linear constraints (A,b) are not yet accepted.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!