필터 지우기
필터 지우기

fsolve error when I change the given matrix

조회 수: 1 (최근 30일)
Quynh tran
Quynh tran 2016년 4월 7일
편집: Walter Roberson 2016년 4월 8일
I have my prolems like this:
function F=myfun(x)
F=[x(1)+a*x(2)+b*x(3)
x(1)+5*x(2)+4*x(3)
x(1)+2*x(2)+3*x(3)]
P=[1 5 2
3 4 7] %I want to keep this matrix to make easier when I change a and b
a=P(1,1), b=P(1,3)
x0=[0 0 0]
[x,fval,exitflag]=fsolve(@myfun,x0)
and the error is:
Attempt to execute SCRIPT a as a function:
D:\Tinhtraoluucongsuat\flie goc\opt - KG_3_current_constraint_3_7_2015\a.m
Error in myfun (line 2)
F=[x(1)+a*x(2)+b*x(3)
Error in fsolve (line 219)
fuser = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.

채택된 답변

Walter Roberson
Walter Roberson 2016년 4월 7일
On your line
F=[x(1)+a*x(2)+b*x(3)
you have not defined a or b yet. MATLAB assumes they might be functions, and goes looking for them. It finds an a.m that you have sitting around, but it happens that a.m is a script rather than a function, so it fails trying to execute it as a function to get a value for "a".
In MATLAB, if you name a function without passing it any parameters, it is the same as if you had used (), so MATLAB is treating your line as if it had been written
F=[x(1)+a()*x(2)+b()*x(3)
I suggest that you move your lines
P=[1 5 2
3 4 7] %I want to keep this matrix to make easier when I change a and b
a=P(1,1), b=P(1,3)
to before you assign anything to F.
  댓글 수: 1
Quynh tran
Quynh tran 2016년 4월 8일
Thank you very much, I found may errors.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by