fsolve not enough input arguments

18 次查看(过去 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

采纳的回答

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 CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by