Skip to main content
4 of 4
added 4 characters in body
kglr
  • 400.5k
  • 18
  • 488
  • 929

Marking the points of x-intercept on a plot

OK, I have a nice plot of some oscillating motion. I can read some stuff off the graph, but I thought it would be cool to show a dot where the curve hits the x-axis and a little label showing the coordinates, and thus get a direct measure of the period of oscillation. (I know there are equations for that but that's not quite the point of the exercise).

Anyhow, here's the code I am using

Clear[x1, x2, v1, v2];Clear[x1, x2, v1, v2];
ti = 0; tf = 4.; delta = (1/40);
x1[ti] = -0.04; x2[ti] = -0.04; v1[ti] = 0.0; v2[ti] = 0.0;
m1 = 0.1890; m2 = 0.1898; k = 3.65; kc = 3.5;
Do[ F1[t] = -k*x1[t] - kc*(x1[t] - x2[t]); 
 F2[t] = -k*x2[t] - kc*(x2[t] - x1[t]);
 v1[t + delta] = v1[t] + (F1[t]/m1)*delta; 
 v2[t + delta] = v2[t] + (F2[t]/m2)*delta;
x1[t + delta] = x1[t] + v1[t + delta]*delta;    
 x2[t + delta] = x2[t] + v2[t + delta]*delta,
 {t, ti, tf, delta}] 
x1data = Table[{t, x1[t]}, {t, ti, tf, delta}];
x1plot = ListPlot[x1data, AxesLabel -> {"t", "x1"}, Joined -> True]

and with it I get a nice graph:

enter image description here

I tried using NSolve and didn't get any output at all. So I think NSolve must not be geared to this.

Understand I am a rank beginner with Mathematica. So it's ok to assume I am stupid :-) And I know that there are likely more efficient ways to do the curve and such; this is a lab exercise tho. We're testing a simulation against the real data.

Jesse
  • 215
  • 2
  • 9