numerical

gauss-legendre in c++

风格不统一 提交于 2019-12-11 10:49:15
问题 i am trying to create gauss-legendre code according to the following algorithm: for n points That is,it is created a 2n equation system (if we demand to be accurate for polynominals of order 2n-1 , ti are roots of the legendre polynominals of order n.The legendre poynominals are given : and wi : My code is : #include <iostream> #include <cstdio> #include <cstdlib> #include <iomanip> #include <cmath> using namespace std; const double pi=3.14; //my function with limits (-1,1) double f(double x)

Python Function That Receives Letter, Returns (0-Based) Numerical Position Within Alphabet

最后都变了- 提交于 2019-12-11 06:56:51
问题 I'm trying to create a Python function that receives a letter (a string with only one alphabetic character) and returns the 0-based numerical position of that letter in the alphabet. It should not be case-sensitive, and I can't use import. So entering "a" should return 0 Entering "A" should also return 0 Entering "O" should return 14 And so on. I had noticed this question but the top answer uses import and the second answer doesn't make any sense to me / doesn't work. I tried to apply the

Why is implicit transformation of numerical types inconsistent between “for/comprehension” expressions compared to(!) assignment operations?

大城市里の小女人 提交于 2019-12-11 04:35:59
问题 Why is desugaring and implicit transformation of numerical types inconsistent between "for/comprehension" expressions compared to(!) assignment operations? I'm sure there are many general perspectives on this but I couldn't figure out a concise and logical explanation for the current behavior. [Ref:"Behavior of Scala for/comprehension..." ] For the sake of correctness all translations below was generated with the scala compiler ("scalac -Xprint:typer -e") For example, during implicit numeric

Given a number series, finding the Check Digit Algorithm…?

纵饮孤独 提交于 2019-12-11 03:35:40
问题 Suppose I have a series of index numbers that consists of a check digit. If I have a fair enough sample (Say 250 sample index numbers), do I have a way to extract the algorithm that has been used to generate the check digit? I think there should be a programmatic approach atleast to find a set of possible algorithms. UPDATE: The length of a index number is 8 Digits including the check digit. 回答1: No, not in the general case, since the number of possible algorithms is far more than what you

Problems with the Trapezoidal Rule

北城以北 提交于 2019-12-11 03:08:42
问题 I'm having some troubles to calcule the integral of e^x inside and interval [b.a] using fortran. I think I'm doing something wrong in the funcion calls. Thanks for helping me. program trapezium implicit none integer :: i, n, b, a real :: sumation, mean, deltax, f(i), integral ! The value of the integral using the trapezium rule can be found using ! integral = (b - a)*((f(a) +f(b))/2 + sumation_1_n-1 )/n write(*,*) "type the limits b, a and the number of intervals" read *, b, a, n deltax = (b

Numerical Pattern Matching

旧城冷巷雨未停 提交于 2019-12-10 17:05:18
问题 A project I'm researching requires some numerical pattern matching. My searches haven't turned up many relevant hits since most results tend to be around text pattern matching. The idea is we'll have certain wave patterns we'll need to be watching for and trying to match incoming data vs the wave database we will be building. Here is and example of one of the wave patterns we'll need to be matching against. alt text http://tmp.stayhealthy.com/wave.png There is clearly a pattern there, but the

Numerical instability FFTW <> Matlab

早过忘川 提交于 2019-12-10 02:46:54
问题 I am trying to numerically solve the Swift-Hohenberg equation http://en.wikipedia.org/wiki/Swift%E2%80%93Hohenberg_equation using a pseudo-spectral scheme, where the linear terms are treated implicitly in Fourier space, while the nonlinearity is evaluated in real space. A simple Euler scheme is used for the time integration. My problem is that the Matlab code I have come up with works perfectly, while the C++ code, which relies on FFTW for the Fourier transforms, becomes unstable and diverges

Test if a floating point number is an integer

若如初见. 提交于 2019-12-09 14:10:48
问题 This code works (C# 3) double d; if(d == (double)(int)d) ...; Is there a better way to do this? For extraneous reasons I want to avoid the double cast so; what nice ways exist other than this? (even if they aren't as good) Note: Several people pointed out the (important) point that == is often problematic regrading floating point. In this cases I expect values in the range of 0 to a few hundred and they are supposed to be integers (non ints are errors) so if those points "shouldn't" be an

Numerical Differentiation

五迷三道 提交于 2019-12-08 02:45:09
问题 How can I calculate the numerical second derivative of a function involving an exponential and a singularity at infinity. Unfortunately, the numerical derivative by Ridder's methods provided in "Numerical Recipes in C" can only calculate the first derivative (It requires analytical expression of the function beforehand.) Furthermore I have tried Chebyshev approximation and differentiating the function afterwards but the values given were way off the actual values. I have also tried some

Speed up a program that calculate the average of the neighbors in a huge array

你离开我真会死。 提交于 2019-12-06 11:47:10
I have a problem with the speed of my program. I want to calculate the average of four neighbors in a huge array. Here is a part of my code. Do you have any ideas how to change the last line? Or should I use another array? for a in np.arange(100000): for x in np.arange(size): for y in np.arange(size): if unchangeableflag[x*size+y] == 0: vnew[x*size+y] = (v[(x+1)*size+y] + v[(x-1)*size+y] + v[x*size+y+1] + v[x*size+y-1]) / 4.0 You would not need the loop at all. Assuming v , vnew and unchangeableflag are 1-d arrays with size*size entries, you can do v = v.reshape(size, size) vnew = vnew.reshape