lsqcurvefit error Too many input arguments.

3 views (last 30 days)
Nader Mohamed
Nader Mohamed on 29 Oct 2021
Commented: Star Strider on 29 Oct 2021
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);
  1 Comment
Star Strider
Star Strider on 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.
.

Sign in to comment.

Answers (0)

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!