How to use MATLAB to solve difference equations with initial conditions
Mostrar comentarios más antiguos
To begin this I would like to state that I have only recently started using MATLAB since one of my classes requires it. For one of my assignments I have to use loops in MATLAB to solve a difference equation.
The equation has an input x(n) and initial conditions, with one condition starting at 0, and the other starting at -1.
I won't post the exact question itself, as I would like to make the code myself after understanding how to do it.
An example of the problem is as follows:
The a,b,and c in the above example can be any value, but since I'm attempting to make a code, I've set the values to each be 
This is my attempt at the code (it does not work and gets an error at "y(0) = 1"):
%---Example for Mathworks Community QnA Forum---
% arbitrary constants
a = 0.5;
b = 0.5;
c = 0.5;
%initial conditions
y(0) = 1;
y(-1) = -1;
% loop for finding y(n)
for n = 1:10
x(n) = c^n;
y(n) = x(n-1) -a*y(n-1) - b*y(n-2)
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!