fsolve not enough input arguments
32 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
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 件のコメント
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 Exchange で Symbolic Math Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!