evaluate curve fit sum of sine

Good evening,
I am having troubles in evaluating my curve fitting using the sum of sines methot, as it best suits my datas.
I have read the related page that prompts by typing doc cfit, but it seems to be relatend only with polynomial curve fitting.
Basically I need to have something to input in another function, to evaluate P(t).
I'have tried to copy the general model with the given coefficients and replace x with a t vector from 0 to 1.4 in order to do so, but it seems not to work.
What am I doing wrong?
Is there a quicker/easier way to do so?
Thanks for your help!

Respuestas (1)

Matt J
Matt J el 27 de Mzo. de 2021
Editada: Matt J el 27 de Mzo. de 2021
The cfit object returned by fit() can be used as a function handle, to evaluate the fitted function at any desired query points.
load enso;
f = fit( month, pressure, 'sin6');
y=f(50), %evaluate at t=50
y = 10.8555
So, you can just pass f around to any code that needs to query the fit.

2 comentarios

Giulio Rossi
Giulio Rossi el 28 de Mzo. de 2021
thanks for you help!
the problem is that when i try to multiply the function f ( in my case is a time dependant function), matlab prompts
Undefined operator '*' for input arguments of type 'cfit'.
how can I solve this?
You cannot perform multiplications with a fit object, but you can multiply with values returned by a fit object, e.g.,
load enso;
f = fit( month, pressure, 'sin6');
y=f(1:10).',
y = 1×10
12.4425 12.3078 11.4515 10.2027 8.9859 8.2036 8.1253 8.8129 10.1047 11.6591
ytimes10 = 10*f(1:10).'
ytimes10 = 1×10
124.4250 123.0784 114.5152 102.0265 89.8588 82.0364 81.2526 88.1293 101.0474 116.5914

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 26 de Mzo. de 2021

Comentada:

el 28 de Mzo. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by