Mathematica differential equation

Click For Summary

Discussion Overview

The discussion revolves around solving a specific second-order differential equation using Mathematica, focusing on numerical solutions and plotting the results. Participants are addressing issues related to syntax errors and code corrections while attempting to implement the solution with given initial conditions.

Discussion Character

  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant presents a differential equation and initial conditions to be solved numerically in Mathematica.
  • Another participant identifies a syntax error regarding the use of "x3'" instead of "x'" in the initial code.
  • A participant mentions encountering a duplicate variable error when modifying the code, suggesting confusion over variable definitions.
  • One participant provides a suggestion to compare the user's notebook with a working version to identify discrepancies.
  • A later reply suggests correcting the expression "x^2[t]" to "x[t]^2" and removing an extra argument to resolve the issues.
  • There is a discussion about the differences between solving for "x" versus "x[t]", with one participant arguing that the former is more flexible for plotting functions and their derivatives.

Areas of Agreement / Disagreement

Participants generally agree on the need for syntax corrections in the Mathematica code, but there is no consensus on the best approach to implement the solution or the implications of different coding styles.

Contextual Notes

Participants express uncertainty regarding specific syntax rules in Mathematica and the implications of different variable definitions on the functionality of the code.

P-Jay1
Messages
32
Reaction score
0
On mathematica:
Solve the differential equation

d^2 x(t)/dt^2 + x(t)(x^2(t) − 1) + t = 0

numerically, subject to the initial conditions that x(0) = 1 and dx(0)/dt = 0. Use
Plot to plot the solution for the domain t 2 [0, 10].
2.

Above is what I'm trying to do. Below is what I've typed in on mathematica:

s = NDSolve[{x''[t] + (x[t]) (x[t]^2 - 1) + t == 0, x[0] == 1,
x3'[0] == 0}, x, {t, 0, 10}]

This is wrong, it says it's not a diff. equation. Where am i going wrong?
 
Physics news on Phys.org
You have x3'[0] instead of x'[0].
That's the only problem...
 
Simon_Tyler said:
You have x3'[0] instead of x'[0].
That's the only problem...

Sorry that was mistake, but it's still wrong, I've tryed everything i can think of.

n = NDSolve[{x''[t] + x[t] (x^2[t] - 1) + t == 0, x[0] == 1,
x'[0] == 0}, x[t], t, {t, 0, 10}]

above is what i got. Says duplicate variable t found, so it's still wrong. I'm not sure what to do, any ideas?
 
I have fought with the obsession of both Mathematica and the forum software to translate characters into what they think are best for your, despite that breaking this going in both directions.

Attached is a tiny working notebook. Do a binary byte-by-byte comparison with what you have in your notebook and see what is different.
 

Attachments

P-Jay: No, making the correction I suggested in your original code worked.
You've changed your code in your second post. It can be corrected by changing
x^2[t] -> x[t]^2
and by removing the extra t argument you had.

n2 = NDSolve[{x''[t] + x[t] (x[t]^2 - 1) + t == 0, x[0] == 1, x'[0] == 0}, x[t], {t, 0, 10}]

Finally, your first version was better, since you solved for x instead of x[t].
The former returns a pure interpolated function, while the latter returns the function evaluated at t, which is not as flexible.

For example, using the former version

n1 = NDSolve[{x''[t] + x[t] (x[t]^2 - 1) + t == 0, x[0] == 1, x'[0] == 0}, x, {t, 0, 10}]

you can plot the function and its derivative easily

Plot[Evaluate[{x[t], x'[t]} /. n1], {t, 0, 10}]

Doing the same with n2 is not as straight forward...
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
Replies
8
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K