lsqcurvefit error Too many input arguments.
Afficher commentaires plus anciens
I'm trying to use lsqcurvefit to find the best parameters b and k that minimize the error between the experimental and numerical solution, when I run this function I get the error.
Error using ex1>@(bk)T0/J2-(bk(1)/J2).*y(:,4)-((bk(2)/J2).*(y(:,2)-y(:,1))). Too many input arguments.
How can I get lsqcurvefit to run with my fun?
T = load('samples.txt');
xdata = T(:,1);
y2data = T(:,3);
findbk = @(t,y,b,k) [y(3);y(4);k/J1 * y(2) - k/J1 * y(1);T0/J2 - b*y(4)/J2 - (k/J2)*(y(2)-y(1))]; %ode i need to integrate
[t,y] = ode45(@(t,y) findbk(t,y,1,2),[0:0.01:10],[0,0,0,0]); % integrate ode y (1 and 2 are guesses of b and k)
fun = @(bk) T0/J2 - (bk(1)/J2).*y(:,4) - ((bk(2)/J2).*(y(:,2)-y(:,1))); %define function with b and k uknown
X = lsqcurvefit(fun,[0,0],xdata,y2data);
3 commentaires
Star Strider
le 29 Oct 2021
I demonstrated how to do this correctly in Loop over ode45 to find minimum of a parameter and even gave a complete code example, with adaptations for the posted differential equation system.
.
Clara Casado-Coterillo
le 23 Oct 2023
I do not understand the relation of the answer with the question.
I have the same problem with lsqcurvefit.
if I define the local function first
as local_fun = @(x,xdata)fun(x0,xdata,parm1,param2,parm3,ymaxVector);
and then introduce this into
[x,resn,error,jacobian]=lsqcurvefit(local_fun,x0,xdata,ydata,[],[],options)
it returns x = x0 (previously optimized using PSO or given as data);
if I introduce directly the function :
[x,resn,error,jacobian]=lsqcurvefit(@fun,x0,xdata,ydata,[],[],options,parm1,param2,parm3,ymaxVector);
it returns:
FUN must have two input arguments.
if I introduce the function in lsqcurvefit as:
[x,resn,error,jacobian]=lsqcurvefit(@(x,xdata)fun(x,xdata,ydata,parm1,param2,parm3,ymaxVector),x0,xdata,ydata,[],[],options)
it returns:
Too many input arguments.
i do not know what to try next.
Walter Roberson
le 23 Oct 2023
local_fun = @(x,xdata)fun(x0,xdata,parm1,param2,parm3,ymaxVector);
6 parameters passed. Third parameter is parm1
[x,resn,error,jacobian]=lsqcurvefit(@(x,xdata)fun(x,xdata,ydata,parm1,param2,parm3,ymaxVector),x0,xdata,ydata,[],[],options)
7 parameters passed. Third parameter is ydata, and parm1 is the 4th parameter.
Réponses (0)
Catégories
En savoir plus sur Geometry and Mesh dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!