Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #define h 0.1
- #define x0 1
- #define y0 2
- #define N 50
- double f(double x, double y) // dy/dx = f(x,y)
- {
- return 3*x*x*y; // função a ser resolvida
- }
- double T4(double x, double y)
- {
- double K1 = f(x,y);
- double K2 = f(x+h/2.,y+(h/2.)*K1);
- double K3 = f(x+h/2.,y+(h/2.)*K2);
- double K4 = f(x+h,y+h*K3);
- return (1./6)*(K1 + 2.*K2 + 2.*K3 + K4);
- }
- int main(void)
- {
- int i;
- double x, y, yn=0.;
- x=x0;
- y=y0;
- for (i=0; i<N; i++)
- {
- // K1 = f(x,y);
- // K2 = f(x+h/2,y+(h/2)*K1);
- // K3 = f(x+h/2,y+(h/2)*K2);
- // K4 = f(x+h,y+h*K3);
- // yn = y + (h/6)*(K1 + 2*K2 + 2*K3 + K4);
- yn = y + h*T4(x,y);
- x+=h;
- printf("%f\t%f\n",x,yn);
- // printf("%lf\t%lf\t%lf\n",i,yn,x);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement