Need help with how to write a variable in a sequence

4 次查看(过去 30 天)
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.

回答(1 个)

Chad Greene
Chad Greene 2014-12-3
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 个评论
Paul
Paul 2014-12-3
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 2014-12-3
编辑:Paul 2014-12-3
Updated based on your advice:
a = 0.5;
b(1)==0;
for n = 2:10
b(n) = b(n-1)+a;
end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by