Euler yontemi ile
import numpy as np
import matplotlib.pyplot as plt
def euler_method(f, x0, y0, h, n):
x = np.zeros(n+1)
y = np.zeros(n+1)
x[0] = x0
y[0] = y0
for i in range(n):
x[i+1] = x[i] + h
y[i+1] = y[i] + h * f(x[i], y[i])
return x, y
def f(x, y):
return -y+x+1
x0 = 0
y0 = 1
h = 0.1
n = 10
x, y = euler_method(f, x0, y0, h, n)
# Sonuçları yazdır
print("x:", x[-1])
print("y:", y[-1])
Hiç yorum yok:
Yorum Gönder