フィルターのクリア

I get an error using fsolve but I don't understand why?

5 ビュー (過去 30 日間)
Arvind
Arvind 2024 年 4 月 17 日
コメント済み: Arvind 2024 年 4 月 17 日
I have get an error
Too many output arguments.
Error in @(r)calculate_f(r,alphai,phi,phi0,n,m,fraci) (line 21)
func = @(r) calculate_f(r, alphai, phi, phi0, n, m, fraci);
Failure in initial objective function evaluation. FSOLVE cannot continue.
function f = calculate_f(r, alphai, phi, phi0, n, m, fraci)
f = zeros(m, 1);
f(1) = log(alphai(1) / r(1)) + log(1.0 - phi0 / phi) - log(1 - ((1.0 - phi) / (1.0 - phi0))^(1.0 / n));
for j = 2:m
f(j) = f(j-1) + log(alphai(j) / r(j)) + log(r(j-1) / alphai(j-1) - fraci(j-1));
end
end
func = @(r) calculate_f(r, alphai, phi, phi0, n, m, fraci);
r0 = r * ones(m, 1);
options = optimoptions('fsolve', 'Algorithm', 'trust-region-dogleg', 'SpecifyObjectiveGradient', true, 'CheckGradients', false, 'ScaleProblem', 'jacobian', 'FunctionTolerance', phitol);
ri = fsolve(func, r0, options);

採用された回答

Steven Lord
Steven Lord 2024 年 4 月 17 日
Look at the description of the fun input argument on the documentation page for the fsolve function. The relevant part of that documentation:
"f the Jacobian can also be computed and the 'SpecifyObjectiveGradient' option is true, set by
options = optimoptions('fsolve','SpecifyObjectiveGradient',true)
the function fun must return, in a second output argument, the Jacobian value J, a matrix, at x."
Your function does not return a second output argument. Either have it return that second output argument or don't set 'SpecifyObjectiveGradient' to true.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSystems of Nonlinear Equations についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by