MATLAB: Why when i run code this error fv(:,1) = funfcn(x,varargin{:})

errorfminsearch

global Nt Lf
Nt = 14;
Lf = 3.00;
d = 0.081;
OD = 0.800;
x_start = [ d OD ];
[ x_solution, min_val ] = fminsearch( 'pr02_spring', x_start )
d = x_solution(1);
OD = x_solution(2)
rho = 0.28;
G = 11.7e6;
Lw = 1.5;
D = OD - d;
w = rho * ( pi*d*d/4 ) * (pi*D) * Nt;
ID = D - d;
Na = Nt - 2;
k = d*d*d*d*G / (8*D*D*D*Na);
Fw = k * ( Lf - Lw );
Ls = Nt * d;
Fs = k * ( Lf - Ls );
C = D / d;
Ks = 1 + 0.5/C;
tau = Ks*8*Fs*D / (pi*d*d*d);
Sut = 184649 * ( d ^ -0.1625 );
Sys = 0.45 * Sut;
Nfs = Sys / tau;
disp( ' d OD Nt Lf weight' )
disp( ' [inch] [inch] [inch] [lbf]' )
disp( [ d OD Nt Lf w ] )
disp( ' ID k Fw Ls Nfs' )
disp( ' [in] [lbf/in] [lbf] [inch]' )
disp( [ ID k Fw Ls Nfs ] )

Best Answer

I don't even understand why you'd try to pass your variable w to fminsearch. The whole purpose of the fminsearch is to minimise a function. How is it going to achieve that if you pass it a variable?
The error message tells you that matlab can't find the function pr02_spring. That function should be its own m file, hence you should have a pr02_spring.m file which is the function you want to minimise.
So which function are you trying to minimise? What is its name? And where is the file where it is defined?