Graphing a differential equation in mathematica?

In summary, the conversation discusses the process of graphing a first order differential equation in Mathematica and troubleshooting discrepancies between the graph and a textbook. Suggestions for correcting the issue include checking initial conditions, units, and the equation itself. The importance of troubleshooting in the scientific process is also emphasized.
  • #1
dangsy
15
0

Homework Statement



I'm trying to graph a first order differential equation in Mathematica but the graph doesn't seem right when compared to my txt book. I'm using NDSolve.

The first order diff-eq is...

dy/dt' = -cy-sin(x)+fcos(z)

where z = omega t'

c = 0.05
f = 0.4
omega = 0.7

Time t' is the x-axis
and dx/dt' is the y-axis

The Attempt at a Solution



I have...

s = NDSolve[{\[Omega] x'[z] ==
y[z], \[Omega] y'[z] == -c y[z] - Sin[x[z]] + f Cos[z],
y[0] == -1, x[0] == 0}, {x, y}, {z, 0, 30}]

Plot[Evaluate[y[z] /. s], {z, 0, 30}, PlotRange -> All]

the graph should look akin to a cos function but the peaks are off compared to what's in my txt book.

Any ideas?
 
Physics news on Phys.org
  • #2


Hi there, it looks like you are on the right track with your attempt at a solution. However, there are a few things that could be causing the discrepancy between your graph and the one in your textbook.

First, make sure that your initial conditions (y[0] == -1, x[0] == 0) are the same as the ones given in your textbook. Even a small difference in initial conditions can result in a significantly different graph.

Second, check your units. Are you using the same units for time and omega as in your textbook? If not, make sure to convert them to the same units before inputting them into your equation.

Third, try adjusting the range of your plot to match the range in your textbook. For example, if your textbook graph spans from 0 to 10, try plotting your graph from 0 to 10 as well.

If none of these suggestions solve the issue, it's possible that there may be a small error in your equation or in the way you are inputting it into Mathematica. Double check your equation and make sure all variables and operators are entered correctly.

I hope this helps! Let me know if you still have trouble and we can work through it together. Remember, troubleshooting is an important part of the scientific process, so don't get discouraged. Keep trying and you will eventually find the solution.
 

1. How do I input a differential equation into Mathematica?

To input a differential equation into Mathematica, use the syntax eqn = f[x, y] where x is the independent variable and y is the dependent variable. Make sure to use proper mathematical notation for the derivative, such as y'[x] for dy/dx.

2. How do I plot a differential equation in Mathematica?

To plot a differential equation in Mathematica, first use the DSolve function to find the general solution. Then, use the Plot function to plot the solution over a desired range of values for the independent variable.

3. How do I add initial conditions to a differential equation plot in Mathematica?

To add initial conditions to a differential equation plot in Mathematica, use the syntax DSolve[{eqn, y[x0] == y0}, y[x], x] where x0 and y0 are the initial values for the independent and dependent variables, respectively.

4. Can I plot a system of differential equations in Mathematica?

Yes, you can plot a system of differential equations in Mathematica using the NDSolve function. This function can handle multiple equations and initial conditions, and will return a list of solutions that can be plotted using the Plot function.

5. How can I customize the appearance of a differential equation plot in Mathematica?

To customize the appearance of a differential equation plot in Mathematica, you can use various options with the Plot function, such as changing the color, line style, or adding labels and legends. You can also use the Show function to combine multiple plots on one graph.

Similar threads

  • Advanced Physics Homework Help
Replies
3
Views
937
  • Advanced Physics Homework Help
Replies
12
Views
1K
  • Advanced Physics Homework Help
Replies
1
Views
955
Replies
2
Views
1K
  • Advanced Physics Homework Help
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
127
  • Advanced Physics Homework Help
Replies
5
Views
2K
  • Calculus and Beyond Homework Help
Replies
7
Views
678
  • Advanced Physics Homework Help
Replies
3
Views
1K
  • Advanced Physics Homework Help
Replies
3
Views
1K
Back
Top