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 ..

#### Category : numerical-methods

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 ..

I’m trying to implement incremental search method to find the interval with the smallest positive zero. I’m trying to iterate the list of x-values i made but the error says: TypeError: ‘float’ object is not iterable. How can i iterate over the float x-values? here is my code: https://paste.pythondiscord.com/iweguhivir.py # function: f(x) = x**3 – ..

I have real data which formatted as a set of x,y data. I would like to conduct a Mellin Transformation on this data and find Mellin Image. There is a python package sumpy integrals that can be used for Mellin tranformation The syntax is rather simple as can be see from the example below: from ..

## Recent Comments