From: Jonathan on
I'm trying to use fminsearch to find the minimum values of two functions, but I'm getting this error message:
Error in ==> fminsearch at 176
fv(:,1) = funfcn(x,varargin{:});

Error in ==> calc_max_fy at 36
Fy_inner=fminsearch(Fyi,alpha);
Can anyone help me figure out the problem with my code?

Thanks in advance for your help.

My progam code is:
alpha=[0:0.1:12];
Fzi=5;
Fzo=3;

Fy=calc_max_fy(alpha,Fzi,Fzo)

My function code is:

function Fy=calc_max_fy(alpha,Fzi,Fzo)

a0=0;
a1=-22.1;
a2=1011;
a3=1078;
a4=1.82;
a5=0.208;
a6=0;
a7=-0.354;
a8=0.707;

Ei=a6*Fzi^2+a7*Fzi+a8;
Ci=1.30;
Di=a0*Fzi^3+a1*Fzi^2+a2*Fzi;
Bi=(a3*sin(a4*atan(a5*Fzi)))/(Ci*Di);
PHIi=(1-Ei)*alpha+((Ei/Bi)*atan(Bi*alpha));
Fyi=@(alpha)-1*Di*sin(Ci*atan(Bi*PHIi));

Eo=a6*Fzo^2+a7*Fzo+a8;
Co=1.30;
Do=a0*Fzo^3+a1*Fzo^2+a2*Fzo;
Bo=(a3*sin(a4*atan(a5*Fzo)))/(Co*Do);
PHIo=(1-Eo)*alpha+((Eo/Bo)*atan(Bo*alpha));
Fyo=@(alpha)-1*Do*sin(Co*atan(Bo*PHIo));

Fy_inner=fminsearch(Fyi,alpha);
Fy_outer=fminsearch(Fyo,alpha);

Fy=-1*(Fy_inner+Fy_outer)