numerical-analysis

correctly-rounded double-precision division

拟墨画扇 提交于 2021-02-05 06:46:26
问题 I am using the following algorithm for double-precision division and trying to make it correctly rounded in software emulation of floating-point. Let a be the dividend and b is the divisor. All operations are performed in Q2.62. Initial approximation to the reciprocal is . b/2 is the significand of b with its implicit bit added, and shifted one right. For what follows, when written a or b it is meant by the significand of a or b with its implicit bit added. The is approximated with

Surface plot for multivariate 5 degree polynomial regression in Python

删除回忆录丶 提交于 2020-01-17 10:57:41
问题 I am implementing a paper in Python, which was originally implemented in MATLAB. The paper says that a five degree polynomial was found using curve fitting from a set of sampling data points. I did not want to use their polynomial, so I started using the sample data points (given in paper) and tried to find a 5 degree polynomial using sklearn Polynomial Features and linear_model. As it is a multivariate equation f(x,y) where x and y are the length and width of a certain pond and f is the

Surface plot for multivariate 5 degree polynomial regression in Python

冷暖自知 提交于 2020-01-17 10:56:07
问题 I am implementing a paper in Python, which was originally implemented in MATLAB. The paper says that a five degree polynomial was found using curve fitting from a set of sampling data points. I did not want to use their polynomial, so I started using the sample data points (given in paper) and tried to find a 5 degree polynomial using sklearn Polynomial Features and linear_model. As it is a multivariate equation f(x,y) where x and y are the length and width of a certain pond and f is the

When to use DBL_EPSILON/epsilon

匆匆过客 提交于 2020-01-02 05:30:51
问题 The DBL_EPSILON/std::numeric_limits::epsilon will give me the smallest value that will make a difference when adding with one. I'm having trouble understanding how to apply this knowledge into something useful. The epsilon is much larger than the smallest value the computer can handle, so It would seem like a correct assumption that its safe to use smaller values than epsilon? Should the ratio between the values I'm working with be smaller than 1/epsilon ? 回答1: The definition of DBL_EPSILON

sparse matrix library for C++ [closed]

二次信任 提交于 2019-12-29 04:58:06
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 12 months ago . Is there any sparse matrix library that can do these: solve linear algebraic equations support operations like matrix-matrix/number multiplication/addition/subtraction,matrix transposition, get a row/column of a matrix,and so on matrix size could be 40k*40k or bigger,like 250k*250k fast can be used in Windows

What's the difference in the use and precision of fsolve, brentq and root for a system of equations?

天大地大妈咪最大 提交于 2019-12-24 12:34:36
问题 I have asked this question Is fsolve good to any system of equations?, from which I got a satisfactory answer. The system I presented there x = A * exp (x+y) y = 4 * exp (x+y) , is just a toy model which is similar with my real case problem, fsolve did the work with (code in the answer below): from scipy.optimize import fsolve import matplotlib.pyplot as plt import numpy as np def f(p,*args): x, y = p A = args[0] return (x -A* np.exp(x+y),y- 4* np.exp(x+y)) A = np.linspace(0,4,5) X = [] Y =[]

Image interpolation from random pixels

不问归期 提交于 2019-12-21 12:18:48
问题 I would like to ask a question regarding single channel image interpolation. Single channel is chosen just for simplicity otherwise I'm working on multiple channel images. Assume there is a single channel image with pure black background ( pixel intensity 0) on which there are some pixels with non-zero intensity values. I want to apply an interpolation algorithm to fill the entire black area of the image with interpolated values coming from the neighboring non-zero intensity pixels. What

Image interpolation from random pixels

天涯浪子 提交于 2019-12-21 12:17:13
问题 I would like to ask a question regarding single channel image interpolation. Single channel is chosen just for simplicity otherwise I'm working on multiple channel images. Assume there is a single channel image with pure black background ( pixel intensity 0) on which there are some pixels with non-zero intensity values. I want to apply an interpolation algorithm to fill the entire black area of the image with interpolated values coming from the neighboring non-zero intensity pixels. What

Solve this equation with fixed point iteration

╄→尐↘猪︶ㄣ 提交于 2019-12-21 04:04:15
问题 How can I solve this equation x 3 + x - 1 = 0 using fixed point iteration? Is there any fixed-point iteration code (especially in Python) I can find online? 回答1: Using scipy.optimize.fixed_point: import scipy.optimize as optimize def func(x): return -x**3+1 # This finds the value of x such that func(x) = x, that is, where # -x**3 + 1 = x print(optimize.fixed_point(func,0)) # 0.682327803828 The Python code defining fixed_point is in scipy/optimize/minpack.py. The exact location depends on

Find numbers of subarray of an array whose sum is divided by given number

廉价感情. 提交于 2019-12-18 13:36:53
问题 I got stuck in one algorithm question. Please suggest me some efficient algorithm for the below problem. Question is Find numbers of subarrays whose sum is divisible by given number. My work I made one algorithm, whose complexity is O(N^2), here, N = size of an array. My Code #include<stdio.h> using namespace std; main() { int N; int P; int T; int val; long long int count = 0; long long int answer = 0; scanf("%d", &T); //T = 20; for(int k = 1; k <= T; k++) { scanf("%d", &N); scanf("%d", &P);