Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
import numpy as np def jacobi(A, b, tol=1e-10, max_iter=1000): """ Resuelve sistemas de ecuaciones lineales Ax = b usando el metodo de Jacobi Parametros: A: Matriz de coeficientes. b: Vector de terminos independientes. tol: Tolerancia para la convergencia. max_iter: Maximo numero de iteraciones. Retorna: x: Solucion aproximada. """ n = len(b) x = np.zeros(n) x_new = np.zeros(n) for k in range(max_iter): for i in range(n): x_new[i]= (b[i] - sum(A[i,j] * x[j] for j in range(n) if j != i))/A[i,i] if np.linalg.norm(x_new - x) < tol: print(f"Total de iteraciones necesitadas: {k}") return x_new x = x_new.copy() print(f"No se pudo converger en {max_iter} iteraciones.") return x A = np.array([[3,-0.1,-0.2],[0.1,7,-0.3],[0.3,-0.2,10]], dtype=float) b = np.array([7.85,-19.3,71.4], dtype=float) ejemplo_jacobi = jacobi(A,b) print(f"Solucion por gauss seidel: {ejemplo_jacobi}")
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)