Message Boards Message Boards

0
|
4703 Views
|
5 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How can I capture the output from an Do function and use in ListPlot

Posted 11 years ago

The function I have used is fine for getting the output, but I am not able to capture the list, I have tried all kids of ideas, but now I need help from someone more skilled than I. I set the variables first.

t = 500; d = 200;[Alpha] = 0.5;[Beta] = 0.4;[Gamma] = 0.1;[Delta] = 0.17;

Do[Print[{t = ((1 - [Alpha])*t) + ([Beta]*d), 
    d = (-[Delta]*t) + (1 + [Gamma])*d}], {10}];

The above lets me print the output on the screen, please help me to capture this output so I can plot. I am looking at the Prey-predator model.

POSTED BY: Declan Flynn
5 Replies
Posted 11 years ago

Just something I learned about using the initial expressions, the second expression is updated by the first inside the table, so if you read this and are looking at the Linear Prey-Predator model don't copy the set of expressions that I used. Mine go ahead of themselves compared to the books.

POSTED BY: Declan Flynn
Posted 11 years ago

Yes, this is a much better way to go, again thank you.

POSTED BY: Declan Flynn

Dear Declan,

just to make sure, that it is what you want to do. You see, if you want to create a list, there is a much easier way to do that. In the code above there are three functions Do, Sow, and Reap. This is because I understood that you want to use a Do loop. You can of course also do this:

t = 500; d = 200; alpha = 0.5; beta = 0.4; gamma = 0.1; delta = 0.17;

Table[{t = ((1 - alpha)*t) + (beta*d), d = (-delta*t) + (1 + gamma)*d}, {i, 1, 10}]

which does the same thing with only one (!) function.

Cheers, Marco

POSTED BY: Marco Thiel

What about

t = 50; d = 200; alpha = 0.5; beta = 0.4; gamma = 0.1; delta = 0.17;

output = Reap[
   Do[Sow[t = ((1 - alpha)*t) + (beta*d), 
     d = (-delta*t) + (1 + gamma)*d], {i, 1, 10}]][[2]]

Cheers,

Marco

POSTED BY: Marco Thiel
Posted 11 years ago

Thank you, I am on my way again, these are new functions to me, however they do the job.

POSTED BY: Declan Flynn
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