# How can I find coefficients of quadratic and cubic terms?

I have this code:

Gtt = gtt[rb] + (gtt')[rb]*(ζ*nr[l]) + (1/2)*(gtt'')[rb]*
(ζ*nr[l])^2 + (1/6)*(gtt''')[rb]*(ζ*nr[l])^3;
G11 = g11[rb] + (g11')[rb]*(ζ*nr[l]) + (1/2)*(g11'')[rb]*
(ζ*nr[l])^2 + (1/6)*(g11''')[rb]*(ζ*nr[l])^3;
Grr = grr[rb] + (grr')[rb]*(ζ*nr[l]) + (1/2)*(grr'')[rb]*
(ζ*nr[l])^2 + (1/6)*(grr''')[rb]*(ζ*nr[l])^3;
gtt[r_] = (-r^2)*Exp[2*A[r]]*g[r];
g11[r_] = r^2*Exp[2*A[r]];
grr[r_] = Exp[2*A[r]]/(r^2*g[r]);
X = {t, r[t, l], x1[t, l], x2, x3};
χ = {t, l};
r[t_, l_] = rb[l] + ζ[t, l]*nr[l];
x1[t_, l_] = xb[l] + ζ[t, l]*nx[l];
rl = D[r[t, l], l];
rt = D[r[t, l], t];
x1l = D[x1[t, l], l];
x1t = D[x1[t, l], t];
rb'[l] = Sqrt[1 - (g11[r0]*gtt[r0])/(g11[rb[l]]*gtt[rb[l]])]/
Sqrt[grr[rb[l]]];
xb'[l] = (Sqrt[-gtt[rb[l]]]*Sqrt[(-g11[r0])*gtt[r0]])/
(g11[rb[l]]*gtt[rb[l]]);
nx[l_] = (Sqrt[grr[rb[l]]]*(rb')[l])/Sqrt[g11[rb[l]]];
nr[l_] = -((Sqrt[g11[rb[l]]]*(xb')[l])/Sqrt[grr[rb[l]]]);
Huv = {{Gtt + Grr*rt^2 + G11*x1t^2, Grr*rt*rl + G11*x1t*x1l},
{Grr*rt*rl + G11*x1t*x1l, Grr*rl^2 + G11*x1l^2}};
S = Sqrt[-Det[Huv]] /. Derivative[1, 0][ζ][t, l] -> OverDot[ζ, 1] /.
Derivative[0, 1][ζ][t, l] -> Derivative[1][ζ] /. rb[l] -> rb /. ζ[t, l] -> ζ


I am having trouble finding the coefficients of quadratic and cubic terms of ζ and its derivatives. Can somebody please help me find the coefficients?

In the code, I am figuring out the action of a string after it is perturbed slightly by ζ. The action is given by S at the end of the code. I must isolate the quadratic and the cubic terms separately from the S itself.

• Commented Sep 22, 2023 at 16:03
• Thank you. I'll try to do better. Commented Sep 22, 2023 at 16:07
• Go ahead and format the existing code according to the suggestions in that post. At the moment your code is unreadable. It is unlikely you will get help in this form. Commented Sep 22, 2023 at 18:12
• Thanks for the help. It's much better now. Commented Sep 22, 2023 at 20:14

We can use a trick here: Instead of writing just

r[t_, l_] = rb[l] + 𝜁[t, l]*nr[l];
x1[t_, l_] = xb[l] + 𝜁[t, l]*nx[l];


I used

r[t_, l_] = rb[l] + 𝛼*𝜁[t, l]*nr[l];
x1[t_, l_] = xb[l] + 𝛼*𝜁[t, l]*nx[l];


I introduced a new constant term $$\alpha$$.

Now I can easily distinguish all the quadratic and cubic terms using

action = Cancel[PowerExpand[
-Collect[Coefficient[Normal[Series[S, {𝛼, 0, 3}]] /. Derivative[1, 0][𝜁][t, l] ->
OverDot[𝜁, 1] /.𝜁'[t, l] -> 𝜁' /.
𝜁[t, l] -> 𝜁, 𝛼^2], {(𝜁')^2, 𝜁^2, OverDot[𝜁, 1]^2}]]]