# how to extract a subinterval from a previous element in a list (in condition) [closed]

question: i need to use mathematica to write an intermediate value theorem's algorithm, but i don't know how to write in a module form...

i have a function and then, we need to set up a range and also its stepsize...

example:

f(x)=8x-12x^2+4x^3

range=[-0.5,3.5]

stepsize=1

thus, x={-0.5,0.5,1.5,2.5,3.5 }

compute f(-0.5),f(0.5),f(1.5),f(2.5),f(3.5)

a series of element will showed y={-7.5,1.5,-1.5.7.5,52.5}

condition: an interval of x will be choose when it consists a -ve value and follow by a +ve value in its function value.

result: since {-7.5,1.5} and {-1.5,7.5} hence subinterval[-0.5,0.5]and [-1.5,7.5] selected.

question (cont)

random choose a value from interval(s) selected and run a newton method step x[n+1]=x(n)-(f[x(n)]/f'x(n)]

-

## closed as off-topic by Kuba, Artes, Sjoerd C. de Vries, Yves Klett, rm -rf♦Sep 11 '13 at 15:24

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Kuba, Artes, Sjoerd C. de Vries, Yves Klett, rm -rf
If this question can be reworded to fit the rules in the help center, please edit the question.

Dear user9461, welcome to Mathematica.SE. To get the most out of the site, you really need to learn the basics of Mathematica first. Then, when you have some problems you'll ask questions providing valid Mathematica code. Define f[x_]:=8x-12x^2+4x^3, take a look at Map, Range and so on. I hope this is helpful. –  Artes Sep 11 '13 at 7:34

Just dealing with the specific request of finding intervals of functions increasing and crossing x axis.

Define function:

f[x_] := 8 x - 12 x^2 + 4 x^3;

Partition range into intervals:

r = Partition[Range[-0.5, 3.5, 1], 2, 1]

Pick intervals with desired property:

intv = Pick[r, # == {-1, 1} & /@ Map[Sign@f@# &, r, {2}]]

Visualize selected intervals:

Plot[f[x], {x, -0.5, 3.5},
Epilog -> {Red, Thick, Line /@ Map[Transpose[{#, {0, 0}}] &, intv]}]

EDIT After discussion (and using original f(x):

interval[a_, b_, s_] :=
Module[{f, r, intv}, f[x_] := 8 x - 12 x^2 + 4 x^3;
r = Partition[Range[a, b, s], 2, 1] ;
intv = Pick[r, # == {-1, 1} & /@ Map[Sign@f@# &, r, {2}]]]

The function could also be added as an argument but I leave that up to questioner.

-