フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Some trouble with difference equations

1 回表示 (過去 30 日間)
paul
paul 2012 年 2 月 15 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hey,
I'm not a heavy matlab user and started programming on ml this weak...
I've got the following problem (whicht i can't solve despite heavy use of google):
I got the following equation system which i want to solve nummeric over time
r(t)=-a_r-b_r*y(t-1)-c_r*ir(t-1)-d_r*lamda(t-1)+r(t-1)
y(t)=a_y+b_y*(ir(t)-pi(t))+c_y*r(t)
pi(t)=a_pi+b_pi*y(t)+c_pi*r(t)
ir(t)=a_i+b_i*y(t)+c_i*pi(t)+d_i*r(t)+e_i*lamda(t)
lamda(t)=a_l+b_l*y(t)+c_l*ir(t)+d_l*pi(t)
the variables indicated with t are the one of interest and start values are given...
the variables a,b,c,d,e are constant coefficients given as well... The problem is to solve for one period and then in the next step for arbitraly many.
I have tried with loops (the problem was to integrate the break condition properly) and fsolve (here i failed to add time index) but came to no conclusion.
I would be very gratefully for any help
lg
  2 件のコメント
Andrew Newell
Andrew Newell 2012 年 2 月 15 日
What are your starting values for r, y, etc.?
Andrew Newell
Andrew Newell 2012 年 2 月 15 日
What is your criterion for stopping? Is it a fixed number of time intervals, e.g., 0, dt, 2*dt, ..., n*dt - or perhaps convergence?

回答 (1 件)

Rick Rosson
Rick Rosson 2012 年 2 月 16 日
Please try:
% Number of time steps:
M = 200;
% Number of state variables:
N = 5;
% Pre-allocate data array:
x = zeros(M,N);
% Coefficients for difference equations:
a = [ ... ];
b = [ ... ];
c = [ ... ];
d = [ ... ];
% List of names for the state variables:
varNames = { 'r' 'y' 'pi' 'ir' 'lambda' };
% Time increment:
dt = ... ; % <---- replace ... with desired value
% Time domain:
t = dt*(0:M-1)';
% Initial values:
x(1,:) = [ ... ]; % <---- replace ... with five initial values
% Main Loop - update state variables using difference equations:
for k = 2:M
x(k,1) = ... ;
x(k,2) = ... ;
x(k,3) = ... ;
...
...
end
% Plot results:
figure;
plot(t,x(:,1));
title(varNames{1});
HTH.
  6 件のコメント
Rick Rosson
Rick Rosson 2012 年 2 月 16 日
Yes, Walter makes several good points. The code I posted is meant to provide a template that you can use as a starting point. Once you get something that works, you can tweak the code for speed, memory, precision, convergence rate, etc.
Walter Roberson
Walter Roberson 2012 年 2 月 16 日
Additional note that becomes obvious once you know it:
current time (t) is always the initial time plus the sum of the time steps that have been taken.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by