how to solve a general equation using Mathematica - wolfram-mathematica

Solve[x^2 + 2x^2 + 2x + 1 == 0, x]
Can anyone suggest me how this or any general polynomial equation of any degree could be solved using Mathematica.

Related

Solving recurrence equations

My professor gave me some practice problems to do. But they aren't homework or graded, it's meant to be practice for an upcoming quiz. I would ask my professor, but she's notorious for not being very helpful. But im struggling with this problem, and was hoping to get some help.
The problem is as follows:
T(n) = 1 if n = 1
T(n-1) + n(n-1) if n>= 2
She gives a hint to use a summation, and to assume n = 2^k
So far this is what I have:
T(n) = T(n-1) + n(n-1)
T(n-1) = T(n-2) + n-1(n-2)
T(n-2) = T(n-3) + n-2(n-3)
Therefore...
T(n) = T(n-3) + n(n-1) + n-1(n-2) + n-2(n-3)
this is about when I get stumped, but i tried to push forward and guess which summation to use.
T(n) = T(n-k) + (n(n+1)(2n+1))/6
Well, by telescoping the series, T(n) = 1 + sum(i(i-1) for i = 2..n). That's n(n-1)(n+1)/3 + 1 according to Wolfram Alpha.
Or if you want to do it by hand,
sum(i(i-1) for i = 2..n)
= sum(i(i-1) for i = 1..n)
= sum(i^2 for i = 1..n) - sum(i for i = 1..n)
And then use the well known equations for sums of consecutive squares, and sums of consecutive integers.

How can I unfold the recurrence: T(n)=2T((n+2)/3)

I'm trying to solve this recurrence, but I don't know how to unfold it.
T(n)=2T((n+2)/3) + 1
Can I ignore that "+2" and solve it as it was 2T(n/3) + 1?
This comes from a from a problem that uses a V[a..b] array and makes this return:
return V(X) + f(V, a, Y) + f(V, Z, b)
Where Y is (2a+b)/3 and Z is (a+2b)/3
So: ((b-a+3)/3) = ((n+2)/3)
Sort of. The rigorous version of this trick is to set U(n) = T(n+1) and write
U(n) = T(n+1)
= 2T((n+1+2)/3) + 1
= 2T(n/3 + 1) + 1
= 2U(n/3) + 1.
Then solve for U (e.g., U(n) = O(n^log3(2))) and then you should be able to find an asymptotic expression for T of the same order.

Big O Proof by Induction With Summation

I've been ripping my hair out trying to solve this:
Σ(k=0,n)3k = O(3n)
I've been looking through various things online but I still can't seem to solve it. I know it involves the formal definition of Big O, where
|f(x)| <= C*|g(x)|, x>=k
Since they are the same, I am assuming C is some value I have to find through induction to prove the original statement, and that k=0.
Thanks for your help with this.
Σ(k=0,n)3k
= 30 + 31 + ... + 3n
= (1 - 3n+1) / (1 - 3) ; sum of geometric series
= (3/2)*3n - k
<= c*3n ; for c >= 3/2
= O(3n)
Induction is not needed here; that sum is a geometric series and has closed form solution
= 1(1-3^(n + 1))/(1-3) = (3^(n + 1) - 1)/2
= (3*3^n - 1)/2
Pick C = 3/2 and F = 3/2*3^n - 1/2, G = 3^n, and this satisfies the requirement for O(3^n), but really in practice, though it might be thought informal and sloppy, you don't really worry much about an exact constant since any constant will do for satisfying Big-O.
You can rewrite it as 3n * ( 1 + 1/3 + 1/9 + ....1/3n).
There is an upper bound for that sum. Calculate the limit of that infinite series.
From there, it's easy to get a good C, eg: 2.

Matrix multiplicatiion

I was reading Introduction to Algorithms by Cormen on dynamic programming.
The ordering of matrices is important to perform a matrix multiplication. If I multiplied a number of matrices and come up with the best result, how to keep that result optimal by adding a matrix to the series ?
If you have:
DP[i, j] = minimum cost of multiplying matrices i to through j
then DP[1, n] will be your answer.
To find DP[1, n + 1], just apply the same recurrence you used to build the table:
DP[1, n + 1] = min {DP[1, k] + DP[k + 1, n + 1] + multiplication cost}
1<=k<n+1
This will be O(n).

polynomial multiplication using fastfourier transform

I am going through the above topic from CLRS(CORMEN) (page 834) and I got stuck at this point.
Can anybody please explain how the following expression,
A(x)=A^{[0]}(x^2) +xA^{[1]}(x^2)
follows from,
n-1 `
Σ a_j x^j
j=0
Where,
A^{[0]} = a_0 + a_2x + a_4a^x ... a_{n-2}x^{\frac{n}{2-1}}
A^{[1]} = a_1 + a_3x + a_5a^x ... a_{n-1}x^{\frac{n}{2-1}}
The polynomial A(x) is defined as
A(x) = a_0 + a_1 x + a_2 x^2 + a_3 x^3 + ...
To start the divide-and-conquer strategy of polynomial multiplication by the FFT, CLRS introduces two new polynomials: one of the coefficients of the even-powers of x called A[0] and one of the coefficients of the odd-powers of x called A[1]
A[0](x) = a_0 + a_2 x + a_4 x^2 + ...
A[1](x) = a_1 + a_3 x + a_5 x^2 + ...
Now if we substitute x^2 into A[0] and A[1], we have
A[0](x^2) = a_0 + a_2 x^2 + a_4 x^4 + ...
A[1](x^2) = a_1 + a_3 x^2 + a_5 x^4 + ...
and if we multiply A[1](x^2) by x, we have
x A[1](x^2) = a_1 x + a_3 x^3 + a_5 x^5 + ...
Now if we add A[0](x^2) and x A[1](x^2), we have
A[0](x^2) + x A[1](x^2) = (a_0 + a_2 x^2 + a_4 x^4 + ...) + (a_1 x + a_3 x^3 + a_5 x^5 + ...)
= a_0 + a_1 x + a_2 x^2 + a_3 x^3 + ...
= A(x)
Q.E.D.
If you divvy the polynomial up into "odd exponents" and "even exponents", you'll find the annoying fact that the A[1] polynomial (the one with odd exponents) has, well odd exponents! Even exponents are easier to work with, for FFT. So, one can simply factor out a single "x" from all of the values in A[1], and move it outside of the expression.
FFT likes working with even-exponented polynomials only. Thus, when you're dividing-and-conquering, you want to turn your A[1] expression into an "even-exponented" polynomial, and recurse on that, and then multiply-back-in that x. You will see that occur in the inner loop of the actual algorithm.
Edit: I realize that your confusion may stem from the fact that they're "passing in" (x^2) as the value in the polynomial. The "x" in A[1] and A[0] are different from the x in the (x^2) expression. You'll see how that must be, as while the original polynomial A goes up to exponent N, A[1] and A[0] both only go up to exponent (N/2).
I'm not going to answer your question because I feel that previous people have answered it. What I will do is try to explain the purpose of the FFT.
First, the FFT is a way to compute the convolution between two vectors. That is, suppose x = and y= are 1xn vectors then the convolution of x and y is
\sum_{i=0} ^n {xi y{n-i}}.
You will have to accept the fact that computing that value is EXTREMELY useful in a wide range of applications.
Now consider the following.
Suppose we construct two polynomials
A(z) = x0 + x1*z + x2 *z^2 + .. + xn^z^n
B(z) = y0 + y1*z + y2 *z^2 + .. + yn^z^n
then the multiplication is
AB(z) = A(z)B(z) = \sum_{i=0} ^ n (\sum_{k=0} ^ i xk*y{i-k}) z^i
where the inside sum is clearly a convolution of different size for different values of k.
Now we can clearly compute the coefficients (convolutions) of AB in n^2 time by a brute force method.
However, we can also be much more clever. Consider the fact that any polynomial of degree n can be described uniquely by n+1 points. That is given n+1 points we can construct the unique polynomial of degree n that goes through all n+1 points. Further more consider 2 polynomials in the form of n+1 points. You can compute their product by simply multiplying the n+1 y-values and keeping the x-values to result in their product in point-form. Now given a polynomial in n+1 point-form you can find the unique polynomial that describes it in O(n) time (actually Im not sure about this, it may be O(nlogn) time but certainly not more.)
This is exactly what the FFT does. However, the points that it picks to get the n+1 points to described the polynomials A and B are VERY carefully chosen. Some of the points are indeed complex because it just so happens that you can save time in evaluating a Polynomial by considering such points. That is if you were to choose just real points instead of the carefully chosen points that the FFT uses you would need O(n^2) time to evaluate the n+1 points. If you choose the FFT you only need O(nlogn) time. And thats all there is to the FFT. Oh and there is a unique side effect to the way that the FFT chooses points. Given an n-th degree polynomial, you must choose 2^m points where m is chosen such that 2^m is the smallest power of 2 greater than or equal to n.
A(x) is broken in to even x^2, and odd x parts,
for example if A(x) = 21 x^5 + 17 x^4 + 33 x^3 + 4 x^2 + 8 x + 7
then A0 = 17 y^2 + 4 y + 7
so that A0(x^2) = 17 x^4 + 4 x^2 + 7
and A1 = 21 y^2 + 33 y + 8
so that A1(x^2) = 21 x^4 + 33 x^2 + 8
or x * A1(x^2) = 21 x^5 + 33 x^3 + 8 x
clearly, in this case, A(x) = A0(x^2) + x A1(x^2) = even + odd parts

Resources