Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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...





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,-,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)]

share|improve this 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
add comment

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.

1 Answer

up vote 1 down vote accepted

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]}]

enter image description here

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.

share|improve this answer
Can you please help me write in module form? –  user9461 Sep 11 '13 at 8:40
@user9461 I am not certain what it is you wish to "automate" or use Module for. I have not addressed, the implementation of the Newton-Raphson method. I merely wished to illustrate how to pick the intervals with the desired property. –  ubpdqn Sep 11 '13 at 8:45
i already use the code you given and try to write in module form...but i doenst work. can you help me check, whats the error? Interval[a_, b_, s_] := Module[{}, f[x_] = 4 x^2 - 4 x^3 + x^4; r = Partition[Range[a, b, s], 2, 1] intv = Pick[r, # == {-1, 1} & /@ Map[Sign@f@# &, r, {2}]]] –  user9461 Sep 11 '13 at 8:47
@user9461 There are a number of issues including use of protected symbol. There are othe syntac errors and the new function you use yields empty set. I will provide module form as update. –  ubpdqn Sep 11 '13 at 8:53
Thanks a lot...if can, please make the function as input also –  user9461 Sep 11 '13 at 8:54
show 2 more comments

Not the answer you're looking for? Browse other questions tagged or ask your own question.