#### Category : numerical-methods

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