Clear Filters
Clear Filters

Need help with how to write a variable in a sequence

4 views (last 30 days)
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.

Answers (1)

Chad Greene
Chad Greene on 3 Dec 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.
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;
To get b_0, type this:
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
Paul on 3 Dec 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 on 3 Dec 2014
Edited: Paul on 3 Dec 2014
Updated based on your advice:
a = 0.5;
for n = 2:10
b(n) = b(n-1)+a;

Sign in to comment.


Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!