フィルターのクリア

fsolve not enough input arguments

18 ビュー (過去 30 日間)
Pavel M
Pavel M 2019 年 12 月 7 日
コメント済み: J. Alex Lee 2019 年 12 月 7 日
Hello! Trying to get solution with the help fsolve, i see such problem:
Not enough input arguments.
Error in System (line 2)
F(1) = x(1)*[exp(x(4)/x(2)) - exp(-x(4)/x(3))] - 0.9;
Error in Work1 (line 8)
Coefficients = fsolve(System, x0)
The code is
clc, clear
x0 = [1, 1, 1, 1,1];
Coefficients = fsolve(System, x0)
function Coeffs = System(x)
F(1) = x(1)*[exp(x(4)/x(2)) - exp(-x(4)/x(3))] - 0.9;
F(2) = x(1)*[exp(-(x(4)-0.6*1.2e-6)/x(2)) - exp(-(x(4)-0.6*1.2e-6)/x(3))] - 0.3;
F(3) = x(1)*[exp(-50e-6/x(2)) - exp(50e-6/x(3))] - 0.5;
F(4) = x(1)*[exp(-x(5)/x(2)) - exp(-x(5)/x(3))] - 1;
F(5) = -x(1)/x(2)*exp(-x(5)/x(2)) + x(1)/x(3)*exp(-x(5)/x(3));
F(6) = 30e3*x(1)*(exp(-x(4)/x(2)-exp(-x(4)/x(3)))) - 30e3*x(1)*(exp(-(x(4)-0.6*1.2e-6)/x(2))-exp(-(x(4)-0.6*1.2e-6)/x(3)));
end

採用された回答

J. Alex Lee
J. Alex Lee 2019 年 12 月 7 日
You need to supply System() as a function handle to fsolve(). The way you have written it, Matlab thinks you want to simply call the function System(), and supply the result to fsolve().
As far as I know, the script itself should not execute because you can't define functions within scripts.
clc, clear
x0 = [1, 1, 1, 1,1];
Coefficients = fsolve(@(x)System(x), x0)
In a separate file (also, it looks like your function "System" will also not return an output, so need to change the output name):
function F = System(x)
F = nan(1,6);
F(1) = x(1)*[exp(x(4)/x(2)) - exp(-x(4)/x(3))] - 0.9;
F(2) = x(1)*[exp(-(x(4)-0.6*1.2e-6)/x(2)) - exp(-(x(4)-0.6*1.2e-6)/x(3))] - 0.3;
F(3) = x(1)*[exp(-50e-6/x(2)) - exp(50e-6/x(3))] - 0.5;
F(4) = x(1)*[exp(-x(5)/x(2)) - exp(-x(5)/x(3))] - 1;
F(5) = -x(1)/x(2)*exp(-x(5)/x(2)) + x(1)/x(3)*exp(-x(5)/x(3));
F(6) = 30e3*x(1)*(exp(-x(4)/x(2)-exp(-x(4)/x(3)))) - 30e3*x(1)*(exp(-(x(4)-0.6*1.2e-6)/x(2))-exp(-(x(4)-0.6*1.2e-6)/x(3)));
end
I would also ask about the math problem, which looks over-specified...5 unknowns in 6 equations
  2 件のコメント
Pavel M
Pavel M 2019 年 12 月 7 日
when i use @(x)System(x) in
Coefficients = fsolve(@(x)System(x), x0)
i get this error
Output argument "Coeffs" (and maybe others) not assigned during call to "System".
J. Alex Lee
J. Alex Lee 2019 年 12 月 7 日
It must be that you did not change your
function Coeffs = System(x)
...
end
to
function F = System(x)
...
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by