matlab,math,equation,bisection

You almost have it correct. The bisection method requires that you need to check the sign of f(xl)f(xc). You are only checking for f(xc). As such, you just need to modify your code with two lines: Add one line to compute f(xl) Modify your if statement to check the sign...

It's a lot easier to understand if you split the "clever" line into multiple lines. Here's some modifications, plus comments: double root(FD2D fun, double a, double b) { static const double EPS = 1e-15; // 1×10^(-15) double fa = fun(a), fb = fun(b); // if either f(a) or f(b) are...

If you want to use pointers to member functions. Change double bisect(double, double, double, double f(double), bool&); to double bisect(double, double, double, double (solution::*f)(double), bool&); in declaration and definition. Change the call from root = s.bisect (s.xLeft, s.xRight, s.epsilon, s.f, s.error); to root = s.bisect (s.xLeft, s.xRight, s.epsilon, &solution::f, s.error);...

matlab,linear-algebra,equation-solving,bisection

The following should solve both equations with y on the left-hand-side: y1 = solve(eqn1,y) y2 = solve(eqn2,y) Result: y1 = - 3*x - 1 y2 = x/3 - 1/3 As an aside, it would be much faster to solve this system by thinking of it it as a matrix inversion...

I compared what you posted here to the solution for your previous post and noticed some differences. For the smaller z, you said mask = b > history[..., -1:] index = argmax(mask, axis=-1) They said: mask = b >= a[..., -1:] index = np.argmax(mask, axis=-1) - 1 For the larger...

python,square-root,bisection,epsilon

The issues in the cases are - First Case : You are assuming that the input you get x would always be positive , since you are always setting it to high, so when sending a negative number, ans in first iteration is -13.5 and since (-13.5)**3 is negative, it...

It's because a and b are declared as ints. When you write x = (a + b) / 2;, all the elements on the right side are integers, so they will be evaluated to an integer. Moreover, as the difference of a and b is 1, the value would be...

python,string,python-2.7,recursion,bisection

You have two bugs in your tests. You are testing against the whole list, containing one element, here: elif len(aStr)==1: return aStr==char aStr may be set to ['n'] and it'll still not be equal to 'n'. Use indexing: elif len(aStr)==1: return aStr[0]==char Next, you are testing against the list again...