fzero: Not Enough Input Arguments
이전 댓글 표시
EDIT: I have edited this section of my question as advised by Ammer Hamza.
Problem Statement:
To minimise an underconstrained linear symbolic system equations in the form of:
a1*X1i + a2*X2i + a3*X3i + a4*X4i + a5*X5i = Yi
(where i=1 to 100)
I have 5 coefficients (X1 to X5), which I have as inputs from a spreadsheet, 5 unknown variables (a1 to a5), and 100 equations.
======================================================================
Hi, I have referred to the other threads on the same error message but I am still unable to solve my problem. I have an underconstrained linear symbolic equation generated from other variables that I would like to minimise. Below is a simplified example of the script I have:
EDITED after comments from Alan Weiss:
a=sym('a',[2,1]);
a1=a(1);a2=a(2);
eqn_a(1)=a(1)+a(2)-3;
eqn_a(2)=2*a(1)+a(2)-4;
eqn_a(3)=a(1)-a(2)+1;
fun=matlabFunction(eqn_a);
x0=[1 10];
fzero(fun,x0)
This is the error message I get:
Error using fzero (line 241)
FZERO cannot continue because user-supplied function_handle ==> @(a1,a2)[a1+a2-3.0,a1.*2.0+a2-4.0,a1-a2+1.0] failed with the error
below.
Not enough input arguments.
Additionally, is this a suitable function or the best function to solve this problem? I have 5 coefficients, 5 variables and 100 equations.
Thank you very much.
댓글 수: 3
Ameer Hamza
2018년 6월 27일
편집: Ameer Hamza
2018년 6월 27일
Although there are several errors with that use of fminunc() in your code, but it appears that in trying to explain those errors, we will again run into a case of XY problem. fminunc () might be a correct function for this task, but the objective function you are defining is surely not correct. It appears that you are trying to solve some system of equations and are interested in the least square solution. Please explain the actual problem you are trying to solve so that we can suggest the relevant solution.
Ameer Hamza
2018년 6월 27일
Now the problem is clear. This problem has a much easier solution in MATLAB as compared to the using syms, writing all equations and using fminunc(). Please refer to my answer.
채택된 답변
추가 답변 (1개)
Alan Weiss
2018년 6월 27일
1 개 추천
As formulated, your problem does not make sense.
- You give a scalar value of x0, but you have a 2-D problem.
- You give a 3-output function eqn_a. when objective functions must be scalar-valued.
- You are attempting to solve a set of equations using fminunc, when fsolve is the appropriate solver for a system of equations.
- You do not give the equations in the correct syntax for fsolve.
- For systems of linear equations, you should probably use backslash ( mldivide )
Alan Weiss
MATLAB mathematical toolbox documentation
카테고리
도움말 센터 및 File Exchange에서 Common Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!