Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include<math.h>
- #define f(x0,y) ((x0*x0)+y)
- int main()
- {
- int i,n;
- float x0,y0,h,y1,y2,x0n;
- printf("Enter values x00, y0, h and x0n \n");
- scanf("%f %f %f %f",&x0,&y0,&h,&x0n);
- n=(x0n-x0)/h;
- for(i=0;i<n;i++)
- {
- y1 = y0+(h*(f(x0,y0)));
- do{
- y2 = y1;
- y1 = y0 + ( (h/2)*( f(x0,y0) + f((x0+h),y2) ) ) ;
- }while(fabs((y2-y1)/y1)>0.0001);
- x0 = x0+h;
- y0 = y1;
- }
- printf("\nFinal value y(%f) = %f ",x0,y0);
- return 0;
- }
- /*
- Enter values x0, y0, h and xn
- 0 0.94 0.1 0.1
- Final value y(0.100000) = 1.039473
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement