Divide and Conquer Polynomials - polynomial-math

I am looking for a recursive and a non recursive divide and conquer algorithm for a polynomial equation. Let a[0..n-1] be a real array where n is a power of 2.
Compute P(x)=a[0]+a[1]x+a[2]x^2+...+a[n-1]x^n-1 for any x.

Related

slow calculation of General Polynomial Equation

I'm trying to make a General Polynomial Function which given the time period to calculate it, the highest Polynomial power powr, and each constant a; which a and powr are the same length.
My approach of the code is the following: where each element of time is transformed into a vector from powr then when multiplied element by element with a, then calculating the sum of the resulting vector to make it one element.
for i=1:length(time)
result(i)=sum((time(i).^[powr]).*[a]);
end
Problem is that It takes way too long to do this calculation the more elements time has and/or the longer a and powr are. Is there a way to do this calculation faster ?
Armia:
The reason the code runs slowly is that the computation is not polynomially factored, meaning that it doesn't take advantage of the running products. Say for example your polynomial is of degree 3 (i.e., y = a*x^3 + b*x^2 + c*x + d). The way your code is set up makes it so that x (analogous to your time variable) would first be cubed (3 multiplications + 1 to multiply by a), then squared (2 multiplications + 1 to multiply by b), then referenced (0 multiplications + 1 to multiply by c), and finally, you add d. This amounts to 9 multiplications and 3 additions. Evaluating polynomials this way requires sum(1:n) multiplications and n additions.
If instead one factors the polynomial as: y = ((a*x + b)*x + c)*x + d the number of multiplications goes down to 3 (from 9) and the additions remain at 3. In fact, the polynomial factoring approach evaluates the polynomial with n multiplications and n additions (n is the order of the polynomial). Thus, one can see that polynomial factoring scales in computational effort significantly slower than, let's call it, the brute force approach.
To do this for higher degree polynomials, I suggest you modify the code to:
N = length(time); %Get number of time values on which the polynomial evaluation is needed.
hmp = length(a); %I'm assuming a contains the polynomial coefficients in ascending order.
result = ones(N,1)*a(end); %Preallocate memory for results.
for i=hmp-1:-1:1
result = result.*time + a(i); %Compute the factored parenthesis 'outward'
end
Where N is the number of time values at which you want to evaluate the polynomial, hmp is the highest magnitude power. Making result a vector makes the loop compute the polynomial for all your time entries simultaneously. This for loop takes advantage of polynomial factoring, which will scale much more lovely than unnecessarily having to compute powers from scratch element by element.

Choice of cost function in Michael Neilsen's book: Neural Networks and deep learning

Here, w denotes the collection of all weights in the network, b all
the biases, n is the total number of training inputs, a is the vector
of outputs from the network when x is input, and the sum is over all
training inputs, x. Of course, the output aa depends on x, w and b,
but to keep the notation simple I haven't explicitly indicated this
dependence.
Taken from Michael Neilsen's Neural Network and Deep Learning
Does anyone know why he divides the sum by 2? I thought he was going to find the average by dividing by n; instead, he divides by 2n.
This is done so that when the partial derivatives of C(w, b) are computed, it will counter out with the 2 that is produced by the derivative of the quadratic term.
You are correct, normally we'd divide by n, but this trick is done for computational ease.

Why does treating the index as a continuous variable not work when performing an inverse discrete Fourier transform?

I have a set of points describing a closed curve in the complex plane, call it Z = [z_1, ..., z_N]. I'd like to interpolate this curve, and since it's periodic, trigonometric interpolation seemed a natural choice (especially because of its increased accuracy). By performing the FFT, we obtain the Fourier coefficients:
F = fft(Z);
At this point, we could get Z back by the formula (where 1i is the imaginary unit, and we use (k-1)*(n-1) because MATLAB indexing starts at 1)
N
Z(n) = (1/N) sum F(k)*exp( 1i*2*pi*(k-1)*(n-1)/N), 1 <= n <= N.
k=1
My question
Is there any reason why n must be an integer? Presumably, if we treat n as any real number between 1 and N, we will just get more points on the interpolated curve. Is this true? For example, if we wanted to double the number of points, could we not set
N
Z_new(n) = (1/N) sum F(k)*exp( 1i*2*pi*(k-1)*(n-1)/N), with n = 1, 1.5, 2, 2.5, ..., N-1, N-0.5, N
k=1
?
The new points are of course just subject to some interpolation error, but they'll be fairly accurate, right? The reason I'm asking this question is because this method is not working for me. When I try to do this, I get a garbled mess of points that makes no sense.
(By the way, I know that I could use the interpft() command, but I'd like to add points only in certain areas of the curve, for example between z_a and z_b)
The point is when n is integer, you have some primary functions which are orthogonal and can be as a basis for the space. When, n is not integer, The exponential functions in the formula, are not orthogonal. Hence, the expression of a function based on these non-orthogonal basis is not meaningful as much as you expected.
For orthogonality case you can see the following as an example (from here). As you can check, you can find two n_1 and n_2 which are not integer, the following integrals are not zero any more, and they are not orthogonal.

Can any function be decomposed as sum of Gaussians?

In Fourier series, any function can be decomposed as sum of sine and
cosine
In neural networks, any function can be decomposed as weighted sum over logistic functions. (A one layer neural network)
In wavelet transforms, any function can be decomposed as weighted sum of Haar functions
Is there also such property for decomposition into mixture of Gaussians? If so, is there a proof?
If the sum allows to be infinite, then the answer is Yes. Please refer to Yves Meyer's book of "Wavelet and Operators", section 6.6, lemma 10.
There's a theorem, the Stone-Weierstrass theorem, which gives conditions for when a family of functions can approximate any continuous function. You need
an algebra of functions (closed under addition, subtraction, and
multiplication)
the constant functions
and you need the functions to separate points:
(for any two distinct points you can find a a function that assigns them different values)
You can approximate a constant function with increasingly wide gaussians. You can time-shift gaussians to separate points. So if you form an algebra out of gaussians, you can approximate any continuous function with them.
Yes. Decomposing any function to a sum of any kind of Gaussians is possible, since it can be decomposed to a sum of Dirac functions :) (and Dirac is a Gaussian where the variance approaches zero).
Some more interesting questions would be:
Can any function be decomposed to a sum of non-zero variance Gaussians, with a given, constant variance, that are defined around varying centers?
Can any function be be decomposed to a sum of non-zero variance Gaussians, all having 0 as the center, but defined with alternating variances?
The Mathematics Stack Exchange might be a better place to answer these questions though.

Roots of bessel function of first kind for negative n in Matlab

There are some codes which compute the roots of
J_n(x), n > 0
I want to calculate the roots of:
J_n(x), n < 0
n is a real number.
Is there some algorithm or yet better some Matlab code which does this.
In this paper there is an algorithm to calculate the N first roots of Bessel function of the first kind. This works only if n > -1 in J_n(x).
The whole root calculation turns into an eigenvalue problem. The estimated errors have been calculated in the paper.