Undefined function or method 'minus' for input arguments of type 'struct'
18 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Walter Roberson
on 23 Feb 2016
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 Comments
Walter Roberson
on 26 Feb 2016
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)
See Also
Categories
Find more on Memory Usage in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!