1
$\begingroup$

I have used of bisection method for finding the root of a function:

bisect[f_, {x1_, x2_, \[Epsilon]_}] :=
 Module[
  {low = Min[x1, x2], high = Max[x1, x2], mid = N[(x1 + x2)/2], 
   fmid = N[f[(x1 + x2)/2]]},
   While[Abs[fmid] > \[Epsilon],
   If[fmid < 0, low = mid, high = mid];
   mid = N[(low + high)/2];
   fmid = N[f[mid]]];
    mid]

If we have f[x_]:=x^2-10 we will face to

f[x_] := x^2 - 10
bisect[f, {0, 4, 0.0001}]
N[%]
3.16229

But finally I want to create a table with functions and their roots in a such a way that the variable of the table be y. Of course with the guarantee in which x1 and x2 are chosen to satisfying the bisection condition for boundary condition for each function.

Table[bisect[x^(2y) - 10 y, {0, 50, 0.01}], {y, 1, 5}]

The first function in table with y=1 will be similar as above, I mean x^2-10, and other functions in the same way. But it doesn't work correctly. Also, if f in the bisect variables in the first lines defined with two variables x,y, but it doesn't work again.

$\endgroup$

closed as off-topic by MarcoB, Sjoerd C. de Vries, Jens, m_goldberg, C. E. Jul 5 '15 at 1:48

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." – MarcoB, Sjoerd C. de Vries, Jens, m_goldberg, C. E.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ First of all, you are not returning anything from the Module. Add ;mid before the last ]. Secondly, x^(2 y) - 10 y is an expression, and Mathematica does not interpret this as a function. Replace this expression with #^(2 y) - 10 y&. With these two replacements everything should work. $\endgroup$ – march Jul 4 '15 at 13:24
  • $\begingroup$ Yes, it works very well. Thanks a bunch. $\endgroup$ – Unbelievable Jul 4 '15 at 13:37