Message Boards Message Boards

Problem with using AllReplace at equation solutions

Posted 10 months ago

I had a problem with the last two lines of instructions. But do not know why the error

Clear[t, x]

L[t_, x_] = x''''[t] + 5 x''[t] + 4 x[t]

CharPoly[m_] = Coefficient[L[t, Exp[m #] &], Exp[m  t]]

roots = m /. Solve[CharPoly[m] == 0, m]

Solns = Map[Exp[# t] &, roots]

AllSolns[t_] = Solns /. {c1, c2, c3, c4}

Simplify[L[t, AllSolns] == 0]

Can someone help me, please?

POSTED BY: P. Marrone
8 Replies

The issue in your code arises from how you're using AllSolns. Let's address it:

  1. Define the Characteristic Polynomial:

    Clear[t, x]
    L[t_, x_] := x''''[t] + 5 x''[t] + 4 x[t]
    CharPoly[m_] := Coefficient[L[t, Exp[m #] &], Exp[m t]]
    
  2. Find the Roots of the Characteristic Polynomial:

    roots = m /. Solve[CharPoly[m] == 0, m]
    
  3. Define the Solutions:

    Solns = Map[Exp[# t] &, roots]
    
  4. Define the General Solution Function:

    AllSolns[t_] := {c1, c2, c3, c4}.Solns
    

Here, AllSolns[t_] should take t_ as an argument and return a linear combination of the solutions, but you're using it as if it's a list of functions.

  1. Check if the Solutions Satisfy the Differential Equation:

    Simplify[L[t, AllSolns[t]] == 0]
    

This line tests if the solutions satisfy the given differential equation.

Make sure to define c1, c2, c3, and c4 appropriately. This setup should resolve the issue you're facing with AllSolns.

POSTED BY: Ankit Kantheti
Posted 10 months ago

Before we can even get to whatever semantic problem there might be, we need to fix up your code problems.

L[t, x] = x''''[t] + 5  x''[t] + 4  x[t]

The above is probably not what you want. What that did is define a replacement rule for the exact expression L[t, x], which means it won't evaluate as you expect when you pass in any other arguments. For example:

L[t, x]
(* 4*x[t] + 5*Derivative[2][x][t] + Derivative[4][x][t] *)

L[t, Exp[m  #] &]
(* L[t, Exp[m #1] &] *)

So, you need to use patterns:

L[t_, x_] = x''''[t] + 5  x''[t] + 4  x[t];
L[t, Exp[m  #] &]
(* 4*E^(m*t) + 5*E^(m*t)*m^2 + E^(m*t)*m^4 *)

And to avoid symbol collisions, you should probably use SetDelayed:

L[t_, x_] := x''''[t] + 5  x''[t] + 4  x[t]

Probably safest to do what with CharPoly as well:

CharPoly[m_] := Coefficient[L[t, Exp[m  #] &], Exp[m  t]]

Next is just a simplification. Instead of

roots = m /. Solve[CharPoly[m] == 0, m]

you can just do

roots = SolveValues[CharPoly[m] == 0, m]

Now, when we get to

AllSolns[t_] = Solns /. {c1, c2, c3, c4}

we've really jumped the rails. This doesn't make any sense. You have an argument t_ that isn't used anywhere. I'll assume that the suggestion from Denis Ivanov is what you actually intended. And we can just replace that in directly to get

Simplify[L[t, Solns . {c1, c2, c3, c4}] == 0]

which gives

4*((c3 + c1*E^(I*t) + c2*E^((3*I)*t) + c4*E^((4*I)*t))/E^((2*I)*t))[t] + 
  5*Derivative[2][(c3 + c1*E^(I*t) + c2*E^((3*I)*t) + c4*E^((4*I)*t))/E^((2*I)*t)][t] + 
  Derivative[4][(c3 + c1*E^(I*t) + c2*E^((3*I)*t) + c4*E^((4*I)*t))/E^((2*I)*t)][t] == 0

Is that what you wanted?

POSTED BY: Eric Rimbey
Posted 10 months ago

It seems TS wants to make a manual solution of ODE, but with Mathematica.
DSolve produces close form trigonometric solution of L==0 directly,
but sure it's instructive to get it semi-manually and then compare solutions.
I really hope TS now could do it on their own, but if not, we could do it (some time later)
and compare results. It'll be useful for other users!

POSTED BY: Denis Ivanov
Posted 10 months ago

Thanks. Instructive.

POSTED BY: Updating Name
Posted 10 months ago

POSTED BY: Denis Ivanov
Posted 10 months ago

Your main mistake is

Solns /. {c1, c2, c3, c4}
(*/. means AllReplace, but you don't need it!*)

Instead should be

Solns.{c1,c2,c3,c4}
(*x.y  means dot product, or linear combination*)
POSTED BY: Denis Ivanov

Thank you. Best regards. I will take a look later on.

POSTED BY: P. Marrone
Posted 10 months ago

Of course, and there are some other ideas =)

POSTED BY: Denis Ivanov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract