Fit data to lagged custom function

3 ビュー (過去 30 日間)
Paolo
Paolo 2024 年 8 月 1 日
編集済み: Walter Roberson 2024 年 8 月 4 日
Hello,
I would like to ask if you can advice the correct approach I can follow to estimate the parameters of a custom lagged function
(1) y(t)=c^2*a+y(t-1)*(a-1)
where c is a known constant.
to a time series data (I can use the symbilic function to create (1) )
Thank you.
Best regards
Paolo
  2 件のコメント
Torsten
Torsten 2024 年 8 月 1 日
編集済み: Torsten 2024 年 8 月 1 日
I would like to ask if you can advice the correct approach I can follow to estimate the parameters of a custom lagged function
You mean the parameter "a" ?
Paolo
Paolo 2024 年 8 月 2 日
Hi Torsten,
thank you for your feedback. Yes I mean "a"; I forgot to mention that the time series of Y is already available and I know Y(0)= 0.04356
Best regards
Paolo

サインインしてコメントする。

採用された回答

Harsh Kumar
Harsh Kumar 2024 年 8 月 2 日
編集済み: Walter Roberson 2024 年 8 月 4 日
Hope this may help ,
% Assuming you have your y data in a vector called 'y'
% and c is your known constant
% Step 1: Prepare data
y_lag = [NaN; y(1:end-1)]; % Create lagged y, with NaN for the first value
y = y(2:end); % Remove the first value of y to match dimensions
y_lag = y_lag(2:end);
% Step 2 & 3: Define the objective function
obj_fun = @(a) sum((y - (c^2*a + y_lag*(a-1))).^2);
% Step 4: Use optimization to find the best 'a'
options = optimset('Display', 'iter');
a_est = fminsearch(obj_fun, 0.5, options); % 0.5 is an initial guess for 'a'
% Print the result
fprintf('Estimated value of a: %f\n', a_est);
% Optional: Plot the results
y_pred = c^2*a_est + y_lag*(a_est-1);
plot(y, 'b-', 'DisplayName', 'Observed');
hold on;
plot(y_pred, 'r--', 'DisplayName', 'Predicted');
legend('show');
title('Observed vs Predicted y(t)');
  1 件のコメント
Paolo
Paolo 2024 年 8 月 4 日
thanks!
Paolo

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by