Need help with how to write a variable in a sequence

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.

Antworten (1)

Chad Greene
Chad Greene am 3 Dez. 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 Kommentare

Paul
Paul am 3 Dez. 2014
Bearbeitet: Paul am 3 Dez. 2014
here is what i have done since i posted that question.
for n = 2:10;
a = 0.5;
bn = b(n-1)+a;
end
a can and should be assigned before the loop. Also you need to have b(n), not bn. And b(1) must be set before the loop like Chad said. Finally, you don't need the semicolon at the end of the "for" line of code.
Paul
Paul am 3 Dez. 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 am 3 Dez. 2014
Bearbeitet: Paul am 3 Dez. 2014
Updated based on your advice:
a = 0.5;
b(1)==0;
for n = 2:10
b(n) = b(n-1)+a;
end

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 3 Dez. 2014

Bearbeitet:

am 3 Dez. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by