I have a task of implementing QR algorithm with Rayleigh shift. Here is the algorithm: def qr_algorithm_reileigh(A_init, num_iter): """ QR algorithm without shifts input: matrix A_init of size n x n to find its eigenvalues num_iter number of iterations for algorithm to run """ convergence = np.empty(num_iter) Ak = A_init for i in np.arange(num_iter): mu ..

#### Category : numerical-methods

I have never used stack overflow before and am unsure whether asking for help identifying errors is appropriate to ask but I shall ask anyway. I am writing a script to numerically integrate a particular function using trapezoid from the Scipy library. My code is below: from scipy.integrate import trapezoid import numpy as np def ..

Following is my attempt to create a function to differentiate multivariable functions, but as you see it only seems to be able to differentiate with respect to the first positional argument (namely x). How can I extend this to be able to take partial derivatives with respect to y and z? def firstderivative(func,x,*args): return((func(x+0.001,*args)-func(x-0.001,*args))/0.002) def ..

I am new to python and stack overflow. I am trying to find both the electric Potential and E field of a box with 0 potential in all sides except top V = 10. I have the potential part now, but not sure how to use the array (result) of found potential V in the ..

I am trying to solve an eigenvalue problem through python, based on a mesh file (which I imported using meshio). I am using libraries: import numpy as np import matplotlib.pyplot as plt import meshio I am using the following functions: n_core = 1.46 n_clad = 1.44 def assem(coords, elems, rindx): """ Stiffness and mass matrix ..

I am trying to implement the Crank-Nicolson method, which is described in Burden and Faires 10th edition as below: Observation: I was avoiding using images in the problem description, but could not think of a better way to present the steps. I tried fixing the code in the related question Crank-Nicolson Method, but was unable ..

I’m trying to implement a RK4 for a equation that is given by x'(t)=0.4x(t)-0.018x(t)y(t); x(0)=30 y'(t)=-0.8y(t)+0.023x(t)y(t); y(0)=4 and i got this code def f(x,y,t): return 0.4*x*t-0.018*x*t*y def rk4(x0,y0,xn,n): h = (xn-x0)/n print(‘n——–SOLUTION——–‘) print(‘————————-‘) print(‘x0ty0tyn’) print(‘————————-‘) for i in range(n): k1 = h * (f(x0, y0)) k2 = h * (f((x0+h/2), (y0+k1/2))) k3 = h * ..

I’m new to Python and struggling. I get the error message "TypeError: only integer scalar arrays can be converted to a scalar index" when running my code. I am trying to answer this question: Given the function f(x) = e^x+x^2, use the composite trapezium rule to compute the integral using n equally spaced sub-intervals. Write ..

So I’ve been trying to implement Jacobi’s method for solving systems of linear equations in python, and I’ve developed my code based on something like the following: from numpy import array, zeros, diag, diagflat, dot def jacobi(A,b,N=25,x=None): """Solves the equation Ax=b via the Jacobi iterative method.""" # Create an initial guess if needed if x ..

i have made a program that makes an approximation of the integral with Gaussian Quadrature method. My code is: import numpy as np def gaussian_quadrature(f, n): x, A = np.array(np.polynomial.legendre.leggauss(n)) a,b = 0,1 result = 0 for i in range(0, n): q = ((b-a)*x[i] + a + b)/2 p = ((a-b)*x[i] + a + b)/2 ..

## Recent Comments