Need help with how to write a variable in a sequence

4 visualizaciones (últimos 30 días)
Paul
Paul el 3 de Dic. de 2014
Editada: Paul el 3 de Dic. de 2014
Im working with a sequence where b_n = (b_n-1)^0.8+a. How do i write b_n as well as b_n-1 (though im sure its the same thing)
I have to create a loop that calculates b_0 thru b_10, i havnt an issue with the loop just need to find out how to write that type of term.
I hope im clear, bear with me as im still pretty new to both math and MATLAB.

Respuestas (1)

Chad Greene
Chad Greene el 3 de Dic. de 2014
The code below is a little inefficient and it does some redundant steps, but hopefully the extra steps will help get the point across instead of confusing you.
First, you need to seed the series with the first value, b_0, because to calculate b_1, you have to know b_0. Below, I'll say that b_0 = 5 just to give us a starting point. Perhaps for your problem b_0 equals 0 or 1 or some other value.
The thing that makes this problem confusing is that matlab indexes starting with 1, whereas your problem is indexed starting at 0. So I'll build an array called n that will have the n subscript values.
a=2;
b(1)=5; % the first b is b_0
n(1)=0; % this array will have the subscripts
for k = 2:11
b(k) = b(k-1)^0.8+a;
n(k) = k;
end
To get b_0, type this:
b(n==0)
And b_0 equals 5, just as we expect. To get higher-order values of b you can do the same thing. For example, b_8 is given by
b(n==8)
  4 comentarios
Paul
Paul el 3 de Dic. de 2014
when i didnt use the semi colon i ended up with a huge list of numbers on the command window, thats why i added it.
Paul
Paul el 3 de Dic. de 2014
Editada: Paul el 3 de Dic. de 2014
Updated based on your advice:
a = 0.5;
b(1)==0;
for n = 2:10
b(n) = b(n-1)+a;
end

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by