Undefined function or method 'minus' for input arguments of type 'struct'
조회 수: 10 (최근 30일)
이전 댓글 표시
I create a function file that consist of
function f = ASM_1(x,xi,uH,Ks,KOH,KNO,ng,KNH,KOA,bH,bA,Ka,Kh,nh,Yh,Ya,fp,iXB,iXP,Kx,uA)
..........
f(1)=xi(1)-x(1);
........
f(9)=xi(9)-x(9)+(-1*iXB*p1)-(iXB*p2)+(-1*iXB-1/Ya)*p3+p6;
f(10)=xi(10)-x(10)-p6+p8;
f(11)=xi(11)-x(11)+(iXB-fp*iXP)*p4+(iXB-fp*iXP)*p5-p8;
end
then, i create another file
clc;
clear;
fun = @ASM_1;
xi = [1,1,1,1,1,1,1,1,1,1,1];
x0 = [1,1,1,1,1,1,1,1,1,1,1];
[x,fval,exitflag,output] = fsolve(fun,xi,x0)
I run the program but it shows
??? Undefined function or method 'minus' for input arguments of
type 'struct'.
Error in ==> ASM_1 at 47
f(1)=xi(1)-x(1);
Error in ==> fsolve at 254
fuser = feval(funfcn{3},x,varargin{:});
Error in ==> root2dd at 8
[x,fval,exitflag,output] = fsolve(fun,xi,x0,options)
Caused by:
Failure in initial user-supplied objective function
evaluation. FSOLVE cannot continue.
I have no idea how to solve this. Please help if you have any idea. Thanks
댓글 수: 0
답변 (1개)
Walter Roberson
2016년 2월 23일
You defined ASM_1 as a function with 21 parameters. You defined fun as @ASM_1 which is a direct function handle, so fun needs to be passed 21 parameters.
fun is a function that accepts a vector x and returns a vector F, the nonlinear equations evaluated at x
so fsolve() will be passing only 1 parameter, a vector, to your function that expects 21 parameters. Where are you expecting xi, uH, Ks and so on to come from?
댓글 수: 2
Walter Roberson
2016년 2월 26일
How are you expecting them those values to reach the function? If they exist in the workspace and you want them to reach the function then you need
[x,fval,exitflag,output] = fsolve(@(x)ASM_1(x,xi,uH,Ks,KOH,KNO,ng,KNH,KOA,bH,bA,Ka,Kh,nh,Yh,Ya,fp,iXB,iXP,Kx,uA), xi, x0)
참고 항목
카테고리
Help Center 및 File Exchange에서 Memory Usage에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!