Curve Fit Transient Functions using Optimization
Show older comments
I am trying to curve fit test data using optimization. I have 2 functions which characterize the data that are dependent on each other and their previous time steps, similar to what is shown below.
ydata = csvread('testdata.csv')
y1(t) = y1(t-1) + a^2 + b -( (c + y2(t-1) ) / d )
y2(t) = (b*c/a) + ( y1(t-1) - y2(t-1) ) / d )
err(t) = (y1(t) - ydata(t))^2
total_err = sum(err)
I am trying to curve fit y1 to the data by minimizing the total_err term by adjusting a, b, c, and d. Would I use fmincon or lsqcurvefit for this? If so, I cannot figure out how to apply them to these equations. Any advice is appreciated.
Answers (1)
Alan Weiss
on 14 Sep 2018
0 votes
2 Comments
Alex R
on 14 Sep 2018
Alan Weiss
on 17 Sep 2018
You are free to write a full function, with as many conditions as you need to handle edge cases, something like
function z = myfun(x,xdata)
for I = 1:size(xdata,1)
if I = 1
% your code here
else
% more code here
end
end
Alan Weiss
MATLAB mathematical toolbox documentation
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!