Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <fstream>
- #include <math.h>
- using namespace std;
- double f(double i){
- return i*sin(i*i);
- }
- double bisect(double bis1 , double bis2, double dx){
- double bis3 = (bis1+bis2)/2;
- while ((fabs(bis1-bis2))>dx){
- if (f(bis1)*f(bis3)<0){
- bis2 = bis3;
- }
- else if (f(bis1)*f(bis3)>0){
- bis1 = bis3;
- }
- bis3 = (bis1+bis2)/2;
- }
- return bis3 ;
- }
- bool searcher(double down, double up, double a){
- return (f(down)-a)*(f(up)-a)<0 ;
- }
- int main()
- {
- FILE *FL;
- FL = fopen("data.txt","w");
- double dx= 0.001;
- double err= 0.0001;
- double a = 0.001;
- double i=0;
- for (double a = 0.001 ; a<5 ; a+=dx){
- double i=0;
- int n = 0;
- while(true){
- if (searcher(i, i+dx, a)){
- if (n==0){
- fprintf(FL, "%f %f ", a, bisect(i, i+dx, err));
- n++;
- }
- else{
- fprintf(FL, "%f \n", bisect(i, i+dx, err));
- break;
- }
- }
- i+=dx;
- }
- }
- fclose(FL);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement