Help with console input

Pages: 12


That's not what I need to do... :'(

I only need a way to insert whatever user input in variable "funcion", after the return in the f function...
All you have to do is change the value of fVal and evaluate the expression again, over and over, and it will be like plugging in an testing each point as you want.
That's the problem...

The expression and the values will change with every user. I will test x*x*x-x-2 with 1 and 2, but another user will test (x-1)(x-2) with -3 and 3, another user will test it with whatever crazy formula he thinks...
I don't see the problem here. A different user can just type in a different formula in when they run your program.
Yes, I try other formulas myself, but muparser doesn't like parenthesis, and even if you don't use parenthesis in your formula, the results of the bisection method are not accurate.

For example. x*x*x-x-2 using 1 and 2, should give a root of 1.52138, instead I got a root of 2.

Now, looking more closely to the results I see:

Iteration          A       B       C       f(c)
     1          1.5     2       1.5     1.5
     2          1.75    2       1.75    1.75
     3          1.875   2       1.875   1.875

The right results should be:

Iteracion          A       B       C       f(c)
     1          1.5     2       1.5     -0.125
     2          1.5     1.75    1.75    1.60938
     3          1.5     1.625   1.625   0.666016

In second iteration something happens and B don't change, I don't see why.
Is there integer rounding involved?
I'm not doing any kind of rounding. I don't know if muparser is, I don't think so...
Are you dealing with integers anywhere, then?
Yes, Maxiter and numiter are both integers, but they play a role only in stopping the bisection method, they are not involved in any calculation.
Topic archived. No new replies allowed.
Pages: 12