Function - Problem with fminsearch - subscripted assignment dimension mismatch
Mostrar comentarios más antiguos
I am writing a function that is part of a larger project as a demonstration for some students. The program is supposed to do a least squares fit on functions inputted.
The error is as follows:
??? Subscripted assignment dimension mismatch.
Error in ==> fminsearch at 191 fv(:,1) = funfcn(x,varargin{:});
The program is: function [c,res,model1]=lstsq(funct,xdata,ydata,start_point) model1=@fun1; options=optimset('Display','iter','MaxIter',1e40,'MaxFunEvals',1e40,'TolX',1e-40,'TolFun',1e-40); [c,res]=fminsearch(model1,start_point,options);
function [res,Funct]=fun1(c)
Funct=str2func(funct);
res=Funct(c,xdata)-ydata;
end
end
Yes, I realize that there is a nonlinear least squares program already, but I reiterate that this is for a demonstration, so I need to understand why this program gives the error it does. Here are the inputs:
>>lstsq('@(c,xdata)(10.^(-xdata)./(10.^(-xdata)+c(1)))',X,Y,1)
X=[1.20000000000000;2;3.06000000000000;3.77000000000000;4.03000000000000;4.42000000000000;4.90000000000000;8.14000000000000;8.84000000000000;8.88000000000000;10.0800000000000;11.3600000000000]
(this is a 12x1 matrix)
Y=1;0.975446654000000;0.865950488000000;0.585195335000000;0.418113;25000000;0.236419836000000;0.0907522820000000;0;0;0;0;0]
(this is a 12x1 matrix)
Any thoughts as to why fminsearch rejects it with this error? Any help is much appreciated.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Surface and Mesh Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!