필터 지우기
필터 지우기

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