MATLAB: How to converge curve with fminsearch with the code given below

i find all the values of y2 as infinity

I am doing curve fitting using fminsearch . My code is like…
X=....
Y=....
X1=(X./(42*(10^-9)));
Y1=(Y./(pi*((5*10^-6)*(5*10^-6))));
Q=sqrt(X1);
P=(Y1./X1);
plot(Q,log(P)./log(exp(1)),'o');
hold on
A= 5.53*(10^(-17));
B= 2.6*(10^(-19));
C= 4.26*(10^(48));
x0=fminsearch('function_2',[A B C]);
%

A=x0(1)
B=x0(2)
C=x0(3)
x2=linspace(min(Q),max(Q),100);
x3=linspace(min(X1),max(X1),100);
xp=x3.';
y2=(C.*(exp((B.*sqrt(x3))-A)));
yp=y2.'
V=(y2./x3)
plot(x2,log(V)./log(exp(1)),'m.')
%legend('meas','fitted')

grid on
Dont know why I am having all infinite in my 'y2 '?
Any suggestion is appreciable.
…..Ayesha
x0=fminsearch('function_2',[A B C]);
%
A=x0(1)
B=x0(2)
C=x0(3)
x2=linspace(min(Q),max(Q),100);
x3=linspace(min(X1),max(X1),100);
xp=x3.';
y2=(C.*(exp((B.*sqrt(x3))-A)));
yp=y2.'
V=(y2./x3)
plot(x2,log(V)./log(exp(1)),'m.')
%legend('meas','fitted')
grid on

Best Answer

I do not see ‘function_2’ anywhere, so I have no idea what it is doing. The function you minimise has to take one argument (the parameter vector you want to minimise) and return one scalar value.
Since ‘function_2’ appears to be external to your code (and not an anonymous function, for example), call it instead as:
x0=fminsearch(@function_2, [A B C]);