Category : numerical-analysis

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

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([+[x[i]] for i in range(len(y))]) else: x_new = np.array([+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 = ..