Message Boards Message Boards

0
|
4232 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Alter the 'n' step size into a manipulate control?

Posted 7 years ago
f[x_, y_] = 2 + (x y^2)/7;
    (*initial conditions*)
    Y[0] = 0; x[0] = 0;
    (*number of intervals and step size*)
    n = 4; h = 2/n // N;
    (*table of points*)
    pnts = Table[{x[i] = x[i - 1] + h, 
       Y[i] = Y[i - 1] + h f[x[i - 1], Y[i - 1]]}, {i, 1, n}]
    {{0.5, 1.}, {1., 2.03571}, {1.5, 3.33172}, {2., 5.52105}}
    ListPlot[pnts, AxesLabel -> {x, y}]

I was wondering how i can set up a control to have a slider for the 'n' steps? Any pointers would be great

POSTED BY: Jack Mellor

I'm not sure I got right your question. Are you looking for something like this?

nmax = 15;
Manipulate[
 ListPlot[Table[{x[i] = x[i - 1] + (2/n), 
    Y[i] = Y[i - 1] + (2/n) f[x[i - 1], Y[i - 1]]}, {i, 1, n}], 
  AxesLabel -> {x, y}], {n, 1, nmax, 1}]
POSTED BY: massimo fazio
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