Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %initiation values
- accuracy = abs(xr - xl);
- tolerance = 1e-8;
- xl = -1;
- xr = 1;
- funct = (6425*x.^8 - 12012*x.^6 + 6930*x.^4 - 1260*x.^2 + 35)/128;
- %call the bisect function
- x = bisect(funct, xl, xr, accuracy, tolerance);
- function root = bisect(f, xl, xr, accuracy, tolerance)
- %start with midpoint
- xmid = (xl + xr)/2;
- i = 0;
- while (accuracy > tolerance)
- i = i + 1;
- %if we found the root
- if f(xmid) < tolerance
- root = (xl + xr)/2;
- else
- %check which side the root is on
- if f(xl)*f(xmid) < 0
- xr = xmid;
- else
- xl = xmid;
- accuracy = abs(xr - xl);
- end
- end
- end
- print root
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement