Message Boards Message Boards

GROUPS:

Help with Recursion equations

Posted 10 years ago
3633 Views
|
2 Replies
|
1 Total Likes
|
a = 2;
n = 1;
j = 10;
tabj = Table[0, {i, j}];
Do[tabj[[i]] = n;
  n1 = a n;
  n = n1, {i, j}];
a2plot = ListPlot[tabj, Joined -> True][/i]

I was instructed to use this as a model to form my own program like this and just wanted to know what exactly is going where. This may sound like nonsense but this is what i got and don't quite know where I'm going wrong.
 [i]f = 0.1;
 g = 1.1;
 m = 1100;
 tabj = Table[10000, {i, g}];
 Do[tabj[[i]] = n;
   Subscript[r, n + 1] =
    Subscript[r, n] - Subscript[fr, n] + Subscript[gfr, n];
   Subscript[m, n + 1] = Subscript[gfr, n], {i, g}];
 a2plot = ListPlot[tabj, Joined -> True][/i][/i]
POSTED BY: Jordi Gaton
2 Replies
Posted 10 years ago
Actually, based on how most of your original post is strangely italicized and the fact that the missing characters in each of your listings are "[ i ]", it seems that the original code you were given probably was working fine. You could edit your post by re-inserting your original code listings using the 'Code' or 'MCode' formatting buttons above the post editor.

Given that, here are some comments on your second listing:
  • In both your Table expression and your Do expression, you're using g (1.1) as the upper limit of iteration when you probably meant to use m (1100).
  • As in the first listing, the element in the Table expression doesn't matter. tabj is simply being initialized to be a list with a certain number of elements. All of those elements are set and not used by the Do loop.
  • Your subscripted r, fr, and gfr have no initial values.
  • You probably meant to use the subscripts themselves as indices into a sequence of values corresponding to each symbol.
  • Since your final expression is plotting tabj, and tabj is only ever set to the value of n, and you never set the value of n, the loop won't give you any results in tabj to give to ListPlot.
To figure out where you're going wrong in the context of your goal and how to adjust your code to reach that goal, you'll need to (a) clearly and exactly formulate your goal and (b) read enough Mathematica documentation to read and write basic Mathematica code (the Introduction and Core Language sections of the Virtual Book will get you started).

Hope this helps.
POSTED BY: William Rummler
Posted 10 years ago
Carefully review the first code listing you've provided here. Try running it as is in Mathematica. You should see that there is a problem or two with it, but you may not immediately recognize the exact cause(s). If you don't, study it again after taking a quick read through the following Virtual Book section: The Four Kinds of Bracketing in Mathematica.

Once you have that original bit of code working properly, you'll be able to see the output of that ListPlot expression. From there, you should be able to figure out what is going on where in the code, and then you'll be able to tweak it, experiment with it, and eventually adapt it to whatever you're trying to accomplish here.
POSTED BY: William Rummler
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract