Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 62
### Metodo de Euler def Euler(fun, a, b, N, y0): h = (b - a)/N x = [a] y = [y0] for k in range(N): x.append(x[k]+h) y.append(y[k]+(h)*fun(x[k], y[k])) return zip(x, y) ##### Datos iniciales x = var('x') y = var('y') f(x,y) = 2*x - 3*y + 1 ## -> cambiar aquí la función f(x, y) y0=5 ## Valor inicial en 'y' a = 1.0 ## Extremo inferior sobre 'x' b = 1.2 ## Extremo superior sobre 'x' ##### Solución numérica para h=0.1 n = 2 ## numero de pasos a modificar para ver aproximación Euler_puntos=Euler(f, a, b, n, y0) print 'Tabla para valores de h=0.1' print table(Euler_puntos, header_row=["x", "y"], frame='true', align='center') p0=line(Euler_puntos,color=(1,0,1), legend_label='$y\'(x)= 2x - 3y + 1$',gridlines=True) show(p0,axes_labels=([r'$x$',r'$y = f(x)$'])) ##### Solución numérica para h=0.05 n = 4 ## numero de pasos a modificar para ver aproximación Euler_puntos=Euler(f, a, b, n, y0) print 'Tabla para valores de h=0.05' print table(Euler_puntos, header_row=["x", "y"], frame='true', align='center') p0=line(Euler_puntos,color=(1,0,1), legend_label='$y\'(x)= 2x - 3y +1$',gridlines=True) show(p0,axes_labels=([r'$x$',r'$y = f(x)$']))
Tabla para valores de h=0.1 +------------------+------------------+ | x | y | +==================+==================+ | 1.00000000000000 | 5 | +------------------+------------------+ | 1.10000000000000 | 3.80000000000000 | +------------------+------------------+ | 1.20000000000000 | 2.98000000000000 | +------------------+------------------+
Tabla para valores de h=0.05 +------------------+------------------+ | x | y | +==================+==================+ | 1.00000000000000 | 5 | +------------------+------------------+ | 1.05000000000000 | 4.40000000000000 | +------------------+------------------+ | 1.10000000000000 | 3.89500000000000 | +------------------+------------------+ | 1.15000000000000 | 3.47075000000000 | +------------------+------------------+ | 1.20000000000000 | 3.11513750000000 | +------------------+------------------+