How to use use an anonymous function to fit data based on the fittype and fit functions.
Show older comments
Hi there,
I have some sort of data point and I want to use an anonymous function to fit this data based on the fittype and fit functions.
Also, the function is look like this:
F(x)=a*x^2+b*x+c+d*diff(x^2)+e*diff(x)
Any suggestions?
Thanks
Accepted Answer
More Answers (2)
Denis
on 25 Jun 2022
1 vote
Thanks for post, me need it!
1 Comment
William Rose
on 27 Jun 2022
@Denis, you're welcome.
Walter Roberson
on 24 Jun 2022
0 votes
There is no chance of fitting that function.
fit() and fittype() pass in numeric data, and diff() of numeric data is always smaller than the original data. Therefore your a*x^2+b*x+c is an incompatible size to be added to d*diff(x^2)+e*diff(x)
It might make sense to rewrite in terms of gradient()
Does diff(x) happen to be constant (points are equally spaced)? If so then I suspect you can rewrite the formulas for more efficient fitting
2 Comments
Walter Roberson
on 25 Jun 2022
fit() needs to work mathematically when the order of the input vectors is changed. fitting x, y needs to give you the same sum of squared error as fitting x(P) y(P) gives, where P is a permutation of the indices.
If you were to reorder the inputs, e*diff(x) might balance out, but d*diff(x^2) cannot balance out.
Also could you confirm for us that you mean diff(x.^2) and not diff(x).^2 ?
payam samadi
on 25 Jun 2022
Categories
Find more on Linear and Nonlinear Regression 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!
