Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Have a pair of two variable equations, and get the error "Not enough input arguements".

조회 수: 2 (최근 30일)
Nick Barker
Nick Barker 2015년 7월 9일
마감: MATLAB Answer Bot 2021년 8월 20일
Hello:
I am very new to MatLab, and having some issues with a system of two-variable equations. Whenever I try to run the run the script I get the following error: Not enough input arguments.
The script is as follows:
function F=eqns(x)
% p=x(1) and q=x(2)
c = input('input value c');
F(1) = (x(1).^(2).*x(2).^(2).*(x(2).^(2)+x(1).^(2))+c^(2).*(x(1).^(4)-6.*x(1).^(2).*x(2).^(2))-3*c^(4).*(x(1).^(2)-x(2).^(2))-4*c^(6))*sin(x(1)).*sinh(x(2))+2.*x(1).*x(2).*(-x(1).^(2).*x(2)^(2)+3.*c^(2)*(x(1).^(2)-x(2).^(2))-7.*c^(4))*cos(x(1)).*cosh(x(2))-x(1).*x(2).*(x(1).^(4)+x(2).^(4)+2.*c^(2).*(x(2).^(2)-x(1).^(2))+2*c^(4))*cos(2*c);
%
F(2) = 2.*c*x(1).*(3.*x(1).^(2).*x(2).^(2)-x(2).^(4)-c^(2).*(x(1).^(2)+x(2).^(2))+4.*c^(4)).*cos(x(1)).*sinh(x(2))+2*c*x(2)*(x(1).^(4)-3*x(2).^(2)*x(1).^(2)-c^(2)*(x(1).^(2)+x(2).^(2))-4*c^(2))*sin(x(1))*cosh(x(2))+x(1)*x(2)*((x(1).^(2)+x(2).^(2))*(x(1).^(2))-x(1).^(2)+2*c^(2))*sin(2*c);
I would ultimately like to apply fsolve to my system.
As stated previously, I am very new to MatLab and programming in general, so any help, advice, and corrections are greatly appreciated. Thank you in advance.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 7월 9일
You did not mention how you are invoking the code. You need to run it from the command line or from a different line of code and you need to pass in a vector of two values such as
eqns(rand(2,1))
To use the code with fsolve you should rewrite it to not prompt for c...
function F=eqns(x, c)
And then
c=input('what c? ')
fsolve(@(x) eqns(x, c), x0)
  댓글 수: 2
Nick Barker
Nick Barker 2015년 7월 10일
Unfortunately this did not work. When I type the script, I get a warning of a "parse error at c: usage might be invalid MatLab syntax.
I was also not aware that you could designate the two unknowns (in this case x(1) and x(2)) under an umbrella term such as "x". I apologize for my ignorance; fsolve has been a thorn in my side for the past couple of weeks.
Walter Roberson
Walter Roberson 2015년 7월 11일
function eqns_driver
c = input('input value c');
x0 = rand(2,1); %replace with initial conditions appropriate for your purpose
result = fsolve(@(x) eqns(x, c), x0);
end
Put the above in eqns_driver.m
The below should go in eqns.m
function F=eqns(x)
% p=x(1) and q=x(2)
F(1) = (x(1).^(2).*x(2).^(2).*(x(2).^(2)+x(1).^(2))+c^(2).*(x(1).^(4)-6.*x(1).^(2).*x(2).^(2))-3*c^(4).*(x(1).^(2)-x(2).^(2))-4*c^(6))*sin(x(1)).*sinh(x(2))+2.*x(1).*x(2).*(-x(1).^(2).*x(2)^(2)+3.*c^(2)*(x(1).^(2)-x(2).^(2))-7.*c^(4))*cos(x(1)).*cosh(x(2))-x(1).*x(2).*(x(1).^(4)+x(2).^(4)+2.*c^(2).*(x(2).^(2)-x(1).^(2))+2*c^(4))*cos(2*c);
%
F(2) = 2.*c*x(1).*(3.*x(1).^(2).*x(2).^(2)-x(2).^(4)-c^(2).*(x(1).^(2)+x(2).^(2))+4.*c^(4)).*cos(x(1)).*sinh(x(2))+2*c*x(2)*(x(1).^(4)-3*x(2).^(2)*x(1).^(2)-c^(2)*(x(1).^(2)+x(2).^(2))-4*c^(2))*sin(x(1))*cosh(x(2))+x(1)*x(2)*((x(1).^(2)+x(2).^(2))*(x(1).^(2))-x(1).^(2)+2*c^(2))*sin(2*c);
end

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by