Create a graph of the position of a damped oscillator as a function of time.

In summary, this is a conversation about creating a graph of the position of a damped oscillator as a function of time. The equation for the graph is x = A*e^((-b/2m)*t)cos(omega*t + phi) where phi = 0 and m = 2. The code for the graph is using a library called "philsplot" and there were some difficulties with debugging. The issue was eventually resolved.
  • #1
Immanuel Can
18
0
This is an assignment for a class titled "Intro to Scientific Programming" and it is a prerequisite for Computational Physics.

Homework Statement



Create a graph of the position of a damped oscillator as a function of time.

Homework Equations



The equation is x = A*e^((-b/2m)*t)cos(omega*t + phi) where phi = 0 and m = 2.

The Attempt at a Solution



I'm having a hard time debugging this. There are no compiler errors, I just can't get it to graph the function. The graph is made using some library called "philsplot". Here is the code,
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "philsplot.h"

double function(double A, double b, double omega, double t);main() {

double position;
double A;
double b;
double t;
double omega;
A = 10;
//asking for input
printf("Enter the dampening term: \n");
scanf("%lf", &b);
printf("Enter the angular frequency: \n");
scanf("%lf", &omega);//converting degrees to radians
omega = (omega/180) * (4.0*atan(1.0)); //plotting & opening

double xmin, xmax, ymin, ymax, tsize;
int color;
double x,y;

open_plot("600x600");

xmin=0;
xmax=50;
ymin=-50;
ymax=50;
color=4;
tsize=1.5;
int icolor2 = 3;
int istyle = 1;
int iwidth = 1;

box_plot(xmin, xmax, ymin, ymax, tsize, color, "X", "T", "", ""); x = 0;
y = 0;

locate_plot(x,y);

int p;
while(p) {
//drawing graph
for (t=0; t<50; t+=.01) {
x = t;
//finding value
y = function(A, b, omega, t);

delay_plot(.5);
flush_plot();
drawto_plot(x,y, icolor2, istyle, iwidth);
flush_plot();

}

}

flush_plot();

}

//equation=> x = Ae^((-b/2m)t)cos(omegat + phi), phi = 0, m = 2
double function(double A, double b, double omega, double t) {

double x;

x = A * exp( (-b/4)*t ) * cos(omega*t);

return x;}
 
Physics news on Phys.org
  • #2
Nevermind! Figured it out.
 

1. What is a damped oscillator?

A damped oscillator is a system that consists of a mass attached to a spring and subjected to a damping force, causing it to oscillate with decreasing amplitude over time.

2. How is the position of a damped oscillator graphed as a function of time?

The position of a damped oscillator can be graphed by plotting its displacement on the y-axis and time on the x-axis. The resulting graph will show the oscillation of the mass over time, with decreasing amplitude due to the damping force.

3. What factors affect the graph of a damped oscillator?

The graph of a damped oscillator is affected by the mass of the object, the stiffness of the spring, and the amount of damping present. Changes in these factors can result in different shapes and patterns in the graph.

4. How does the damping force affect the position of a damped oscillator over time?

The damping force acts to decrease the amplitude of the oscillation over time. As the oscillator moves, the damping force opposes its motion, gradually reducing its energy and causing it to come to rest.

5. What is the significance of the position graph of a damped oscillator?

The position graph of a damped oscillator can provide valuable information about the behavior and characteristics of the system. It can help to determine the strength of the damping force, the natural frequency of the oscillator, and the time it takes for the oscillation to damp out completely.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
Replies
5
Views
946
  • Engineering and Comp Sci Homework Help
Replies
17
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
863
  • Introductory Physics Homework Help
Replies
4
Views
220
  • Engineering and Comp Sci Homework Help
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
3K
Back
Top