generate y(n)=y(n-1)+x(n)

56 vues (au cours des 30 derniers jours)
Marwan Malaeb
Marwan Malaeb le 20 Avr 2017
Commenté : Joshua Iascau le 13 Avr 2022
hello i want to generate y(n)=y(n-1)+x(n). by using a for loop I can find the last value of y, but i need to store all values of y from n =1 till n. Who do I do that?

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 20 Avr 2017
n=10
y0=0; % Initial conditions
y(1)=y0+x(1);
for k=2:n
y(k)=y(k-1)+x(k)
end
  1 commentaire
Marwan Malaeb
Marwan Malaeb le 20 Avr 2017
that is right, thanks Azzi.

Connectez-vous pour commenter.

Plus de réponses (2)

Roger Stafford
Roger Stafford le 20 Avr 2017
That is precisely what the matlab ‘cumsum’ function does:
y = cumsum(x);
  1 commentaire
Joshua Iascau
Joshua Iascau le 13 Avr 2022
you said what?

Connectez-vous pour commenter.


polat kayhan
polat kayhan le 24 Mai 2021
𝑋𝑛+1 = 𝑋𝑛 2 + 0.25
Information about its relation, calculate the value of its relation for a value of n, register
Write a computer program whose result will be output for n = 0, 5, 10, 15,… communication only.
n = 0,1,2,3,…., 54

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by