I was asked to calculate area from noisy points of given function (the function can represent any closed abstract shape). im getting function and take something like 1000 noisy points from that function (randomly given by samples). I’ve tried to use sklearn.cluster.kmeans to find ‘x’ centers points and on them im doing the shoelace formula, ..

#### Category : numerical-analysis

I wrote a python code to find root of 2*x-4 using bisection method def func(x): return 2*x-4 def bisection(a,b): if (func(a) * func(b) >= 0): print("You have not assumed right a and bn") return c = a while ((b-a) >= 0.01): c = (a+b)/2 if (func(c) == 0.0): break if (func(c)*func(a) < 0): b = ..

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 tried to write my own code for linear regression. the code is below: import numpy as np class LinearRegression: def __init__(self,x=None,y=None): self.x = x self.y = y def fit(self,x=None,y=None,method = "SGD",num_iter=1000,learning_rate = 0.01): y_new = np.array(y).reshape(-1,1) if np.ndim(x)==1: self.theta = np.zeros(2).reshape(-1,1) x_new = np.array([[1]+[x[i]] for i in range(len(y))]) else: x_new = np.array([[1]+list(x[i,:]) for i ..

I am working on an implementation of a numerical tridiagonal hessian in Python. To do this, I use a finite difference method, this is what I’ve tried so far: import numpy as np def principal_diagonal(x, fun): h = 10e-6 result = list() for i in range(len(x)): temp_forward = np.array(x) temp_backward = np.array(x) temp_forward[i] = temp_forward[i] ..

I am curious. I know this can be solved by using odeint, but I’m trying to do it from scratch, and I’ve encountered an interesting behaviour. Assume a simple oscillator, of equation "m * x_ddot + k * x = 0". Wiki Initial conditions are x0 != 0; Theoretically, the solution is a sine function. ..

I’m trying to implement the Adams-Moulton method by using as a intermediate step to calculate the seed the Newton-Raphson method. I have gotten the following: from pylab import * from time import perf_counter def AM3c(a,b,N,y0,fun,dfun): y = zeros(N+1) yy = zeros(N+1) t = zeros(N+1) f = zeros(N+1) C = zeros(N+1) L = zeros(N+1) t[0] = ..

I’m working on a numerical prediction of a pendulums motion for a project. while running the program I’ve noticed the time between each peak (when the value reaches the same theta value as the beginning value of theta) is not the same as the following equation predicts(T = 2pisqrt(l/g)). If there’s anyone how could take ..

I think it happens because x[j] – x[i] = 0 at some points, however I have said j != i. Because of this the graph is empty too. Here is my code: def Lebesgue(x,z): n = len(x) L = np.ones((1,n)) for i in range (1,n): for j in range (1,n): if j != i: L[i] ..

I have a function that for every given x it gives me y with some noise(I don’t how much). I need to calculate the area of a shape(which I also don’t know). I thought to use t, c, k = interpolate.splrep(x_arr, y_arr, s=0, k=3) spline = BSpline(t, c, k) and using some of the points ..

## Recent Comments