Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- algorithm
- start
- input x0,y0,h,last point n
- m1 = f(xi,yi)
- m2 = f(xi+h/2,yi+m1*h/2)
- m3 = f(xi+h/2 , yi+m2*h/2);
- m4 = f(xi+h,yi+m3*h)
- y(i+1) = yi + ( (m1 + 2m2 + 2m3 + m4)/6)
- display Output
- stop
- // program
- #include <stdio.h>
- #include<math.h>
- #define f(x,y) (x*y)
- int main(){
- int n,i;
- float x0,xn,y0,h,s,s1,s2,s3,s4;
- printf("Enter the x0,y0,h & xn\n");
- scanf("%f %f %f %f",&x0,&y0,&h,&xn);
- while(x0<xn){
- s1 = h*f(x0,y0);
- s2 = h*f((x0+(h/2)),(y0+(s1/2)));
- s3 = h*f((x0+(h/2)),(y0+(s2/2)));
- s4 = h*f((x0+h),(y0+s3));
- s = (s1 + (2*s2) + (2*s3) + s4)/6;
- y0 = y0+s;
- x0 = x0+h;
- printf("\ny(%f) = %f",x0,y0);
- }
- printf("\n\nFinal Output y(%f) = %f",x0,y0);
- return 0;
- }
- /*
- Enter the x0,y0,h & xn
- 1 2 0.2 1.4
- y(1.200000) = 2.492143
- y(1.400000) = 3.232107
- Final Output y(1.400000) = 3.232107
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement