I'm attempting to solve a difference equation(adsbygoogle = window.adsbygoogle || []).push({});

y(k+1) = -0.5*y(k) + x(k)

where y(0) = 0 and x(k) is in my case a unit step function ie = 1

well, i'm trying to solve this using a for loop, but am having some trouble. The code i've generated gets an error, "Index into matrix is negative or zero."

Any ideas?

My code is below.

k = 0 ; %counter variable

y = 0; %y(k)

x = 1; %x(k), unit step function

for k = 0 : 5

y(k+1) = -.5*y(k) + x;

y(k) = y(k+1)

end

Thanks for any help.

**Physics Forums - The Fusion of Science and Community**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab for loop and difference equation question

Loading...

Similar Threads - Matlab loop difference | Date |
---|---|

Matlab Arduino-MATLAB communication using SerialEvent() for PID Loop | Oct 28, 2016 |

Matlab -- how can i use a FOR loop if I have 2 variables changing | Oct 12, 2016 |

Matlab What is wrong with this WHILE loop? | Aug 26, 2016 |

MATLAB sum loop issue | Feb 18, 2016 |

Matlab Difference Equation Loop? | Sep 19, 2012 |

**Physics Forums - The Fusion of Science and Community**