Thread: 1D-oscillationg w. energy-loss

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    13

    Unhappy 1D-oscillationg w. energy-loss

    Help,
    the particle should go forth and back and each time he's reaching the wall (+1;-1), he should loss velocity, hence energy! But this results in incomensurability = the new dx doesn't fit into the intervall [-1;1]; here's the code:
    Code:
    double x=0.0;
    	double  vx=0.43; 
    	int i , frac=7 ;
    	double tx=fabs(1/vx);
    	double dx=vx*tx/frac;
    
    	
    	for (i=0 ; i<=N ; x+=dx , i++)
    	{
    	printf("%i	%.4f\n",i,x);
    	fprintf(f_ptr,"%i %.4f\n",i,x);
    	
    	if(x<-0.99 || x>0.99)
    	dx*=-1.0;

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > dx*=-1.0;
    How about
    dx*=-0.99;

    > if(x<-0.99 || x>0.99)
    Or maybe make the limits a variable as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alternate energy sources
    By Govtcheez in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 02-02-2005, 07:07 PM
  2. AI Invader
    By Jeremy G in forum Game Programming
    Replies: 2
    Last Post: 03-17-2004, 08:56 AM
  3. Configurations give different results
    By Hubas in forum Windows Programming
    Replies: 2
    Last Post: 04-11-2003, 11:43 AM
  4. energy and life on earth
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 40
    Last Post: 01-20-2003, 11:39 AM
  5. Is this really true or it's just science fiction?
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 145
    Last Post: 04-09-2002, 06:17 PM