Need help with how to write a variable in a sequence
4 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
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.
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 Comments
See Also
Categories
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!