#include <stdio.h>
// Definimos la función que representa la ecuación diferencial
double f(double x, double y) {
return x * y; // Ejemplo: dy/dx = x * y
}
// Implementación del método de Runge Kutta de cuarto orden
void rungeKutta(double x0, double y0, double h, double xEnd) {
double k1, k2, k3, k4, y = y0, x = x0;
printf("x\t\ty\n");
printf("%.2f\t\t%.6f\n", x, y);
while (x < xEnd) {
k1 = h * f(x, y);
k2 = h * f(x + h / 2, y + k1 / 2);
k3 = h * f(x + h / 2, y + k2 / 2);
k4 = h * f(x + h, y + k3);
y += (k1 + 2 * k2 + 2 * k3 + k4) / 6;
x += h;
printf("%.2f\t\t%.6f\n", x, y);
}
}
int main() {
double x0 = 0; // Valor inicial de x
double y0 = 1; // Valor inicial de y
double h = 0.1; // Tamaño del paso
double xEnd = 2; // Valor final de x
rungeKutta(x0, y0, h, xEnd);
return 0;
}