# Math Help - Taylor polynomial in mathematica

1. ## Taylor polynomial in mathematica

x^3 + by + c = 0, x and y are functions, b is a variable and c is a constant. which means that when b = 0, x(b) = -c

How can I make a program which calculates the taylor polynomial for x(b) of order n, with c and n as inputs?

Would appreciate any help! =))

2. Not sure this is what you want. I'd first solve for x, then use Series to compute the Taylor series for the function x(b) with parameters y and c. Note Solve returns three functions so would have three series. Below, I just compute the first five terms of the "normal" form for the first one at b=0

myx = x /. Solve[x^3 + b y + c == 0, x]
Normal[Series[myx[[1]], {b, 0, 5}]]

3. Thanks for replying, but I should have elaborated some more I think.

What I have is two unknown functions of b, x(b) and y(b). I do know their values in b=0, their first derivative and the value of their first derivatives in b=0.

x(0) = -c

x(0) = -d

x'(b) = (b*x(b) - 3*((y(b))^3) / (9(x(b))^2(y(b))^2 - b^2)

y'(b) = (b*y(b) - 3*((x(b))^3) / (9(x(b))^2(y(b))^2 - b^2)

it follows that:

x'(0) = c / 3d^2

y'(0) = d / 3x^2

Now I don't now how to find x''(b) or y''(b), which would be needed for a second ordered taylor polynomial, but mathematica knows (and perhaps does this automatically when setting up taylor polynomials?). Problem is, I don't know how to use mathematica very well.

Any help? =))

4. So if you have $x(0), y(0)$ and $x'(0), y'(0)$ and you have the expressions for the first derivatives:

$x'(b)=b x-\frac{3 y^3}{9x^2 y^2-b^2}$

$y'(b)=b y-\frac{3 x^3}{9x^2 y^2-b^2}$

Then just start taking derivatives of the expressions for $x'(b), y'(b)$.

I set up one to take the n'th derivative of x(b) as the function myNXdev[n] using the D operator in Mathematica which has the syntax D[f(x),{x,n}] for the n'th derivative. Note the n-1 parameter since we're starting with the first derivative. The construct takes the n'th derivative, then substitutes b->0 (b goes to zero).

Code:
In[29]:=
x[0] = -c;
y[0] = -d;
Derivative[1][x][b_] := b*x[b] -
(3*y[b]^3)/(9*x[b]^2*y[b]^2 - b^2);
Derivative[1][y][b_] := b*y[b] -
(3*x[b]^3)/(9*x[b]^2*y[b]^2 - b^2);
myNXdev[n_] := FullSimplify[
D[b*x[b] - (3*y[b]^3)/
(9*x[b]^2*y[b]^2 - b^2),
{b, n - 1}] /. b -> 0]
myNXdev[2]
myNXdev[3]

Out[34]=
-c - 1/(9*c*d^2) + (2*d^2)/(9*c^5)

Out[35]=
(-2*c^8 - 3*c^4*d^4 + 9*c^6*d^6 + 10*d^8)/
(27*c^8*d^5)
I can't say I'm 100% on this. I have some problems with Mathematica as well. If it were mine, I'd check the code with simple function like sines and cosines, get that working, then I'd be confident this is ok.

5. Thanks alot, I will have to mess around a bit with it to see if it works, but it looks good. By the way, you wouldn't happen to know how to actually solve the differential equation

x'(b) = (b*x(b) - 3*((y(b))^3) / (9(x(b))^2(y(b))^2 - b^2)

in mathematica? NDSolve?

Thanks again! =))

6. I assume you mean the coupled system {x'(b),y'(b)}. I can set up NDSolve if I supply values for c and d. Here's an example with c=1 and d=-1:

Code:
c = 1;
d = -1;
mySol = NDSolve[{Derivative[1][x][b] ==
b*x[b] - (3*y[b]^3)/
(9*x[b]^2*y[b]^2 - b^2),
Derivative[1][y][b] ==
b*y[b] - (3*x[b]^3)/
(9*x[b]^2*y[b]^2 - b^2),
x[0] == -c, y[0] == -d}, {x, y},
{b, 0, 2}]
Plot[Evaluate[{x[b], y[b]} /. mySol],
{b, 0, 2}]

7. Yes, I did mean the system {x'(b),y'(b)}! Thanks, but I'm not sure if it worked, I got some error messages. I actually found a very similar task to the first one with the taylor polynomial, with the solution in mathematica. It wasn't even nessesary to find the derivatives manually as I did. It's just one equation, but if I knew how to use the program better, I could imagine it beeing easily moddable to suit my equations:

n = 7;
Ligning = y[b]^3 + b*y[b] - 1 == 0;
deriverte = {y[0] -> 1.0};
For[i = 1, i <= n, i++,
Ligning = D[Ligning, b];
Ligning0 = Ligning /. b -> 0 /. deriverte;
variable = D[y[b], {b, i}] /. b -> 0;
Løsning = Solve[Ligning0, variable][[1]];
deriverte = Append[deriverte, Løsning[[1]]]]
Tn1 = Sum[deriverte[[i + 1]][[2]]/i!*x^i, {i, 0, n}]

Here it's possible to enter the desired order of the taylor polynomial (n). If the equation was y[b]^3 + b*y[b] + d, then this should give the same as the above:

n = 7;
d = -1
Ligning = y[b]^3 + b*y[b] + d == 0;
deriverte = {y[0] -> d};
For[i = 1, i <= n, i++,
Ligning = D[Ligning, b];
Ligning0 = Ligning /. b -> 0 /. deriverte;
variable = D[y[b], {b, i}] /. b -> 0;
Løsning = Solve[Ligning0, variable][[1]];
deriverte = Append[deriverte, Løsning[[1]]]]
Tn1 = Sum[deriverte[[i + 1]][[2]]/i!*x^i, {i, 0, n}]

Any help modding this to also include the second equation?