필터 지우기
필터 지우기

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 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