Formulae problems???

This is a discussion on Formulae problems??? within the Windows Programming forums, part of the Platform Specific Boards category; I am having difficulties with my first real windows program and I don't believe it is with the programming end ...

  1. #1
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Formulae problems???

    I am having difficulties with my first real windows program and I don't believe it is with the programming end of it.
    I believe it may be and error with the formulae I am using.
    Hopefully, someone here can give a look and offer some suggestions because I am seriously stuck!

    I've attached a copy of the formulae I am using. I have checked it numerous times to see if I possibly have coded it
    incorrectly but I don't see any errors.
    Also, if Iyo is correct how can Ixo be wrong?( See the second output list below.)
    Same thing with xbar and ybar, how can 1 be wrong and the other be right?




    Code:
    void CalculateData()
    {
    	int x;
    	for(x=0;x<3;x++)
    	{
    		// Area
    		subsectionData.area = subsectionData.area + (rectangleData.ptY[x+1] - rectangleData.ptY[x])
    			*(rectangleData.ptX[x+1] + rectangleData.ptX[x])/2;
    
    
    		// Ixo  FUBAR...
    		subsectionData.Ixo = subsectionData.Ixo + ((rectangleData.ptX[x+1] - rectangleData.ptX[x]) 
    			* (rectangleData.ptY[x+1] + rectangleData.ptY[x])/24)
    			* ((pow((rectangleData.ptY[x+1] + rectangleData.ptY[x]), 2) 
    			+ pow((rectangleData.ptY[x+1] - rectangleData.ptY[x]), 2)));
    
    		// Iyo  BUT THIS IS CORRECT!
    		subsectionData.Iyo = subsectionData.Iyo + ((rectangleData.ptY[x+1] - rectangleData.ptY[x])
    			* (rectangleData.ptX[x+1] + rectangleData.ptX[x])/24)
    			* ((pow((rectangleData.ptX[x+1] + rectangleData.ptX[x]), 2)
    			+ pow((rectangleData.ptX[x+1] - rectangleData.ptX[x]), 2)));
    	}
    	subsectionData.Iyo = -1 * subsectionData.Iyo;
    	subsectionData.area = -1 * subsectionData.area;
    	
    
    	
    	for(x=0;x<3;x++)
    	{
    		subsectionData.YBAR = subsectionData.YBAR + (((rectangleData.ptX[x+1] - rectangleData.ptX[x])/8)
    			* ((pow((rectangleData.ptY[x+1] + rectangleData.ptY[x]), 2))
    			+ pow((rectangleData.ptY[x+1] - rectangleData.ptY[x]), 2)/3));
    
    		subsectionData.XBAR = subsectionData.XBAR + (((rectangleData.ptY[x+1] - rectangleData.ptY[x])/8)
    			* ((pow((rectangleData.ptX[x+1] + rectangleData.ptX[x]), 2))
    			+ pow((rectangleData.ptX[x+1] - rectangleData.ptX[x]), 2)/3));
    	}
    
    	subsectionData.XBAR = -1 / subsectionData.area * subsectionData.XBAR;
    	subsectionData.YBAR =  1 / subsectionData.area * subsectionData.YBAR;
    	subsectionData.Ixc = subsectionData.Ixo - (subsectionData.area * (pow(subsectionData.YBAR, 2)));
    	subsectionData.Iyc = subsectionData.Iyo - (subsectionData.area * (pow(subsectionData.XBAR, 2)));
    	return;
    }



    First trial.
    Input data:

    Subsection Type = rectangle
    ptX[0] = 0.000000 ptY[0] = 0.000000
    ptX[1] = 0.000000 ptY[1] = 1.000000
    ptX[2] = 1.000000 ptY[2] = 1.000000
    ptX[3] = 1.000000 ptY[3] = 0.000000

    Output data: // All correct!

    Area subsection = 1.000000
    Ixo subsection = 0.333333
    Iyo subsection = 0.333333
    XBAR subsection = 0.500000
    YBAR subsection = 0.500000
    //The following value are based on the values above...
    Ixc subsection = 0.083333
    Iyc subsection = 0.083333




    Second trial.
    Input data:

    Subsection Type = rectangle
    ptX[0] = 1.000000 ptY[0] = 1.000000
    ptX[1] = 1.000000 ptY[1] = 2.000000
    ptX[2] = 2.000000 ptY[2] = 2.000000
    ptX[3] = 2.000000 ptY[3] = 1.000000

    Output Data:

    Area subsection = 1.000000
    Ixo subsection = 2.666667 //Wrong should be 2.333 checked with: Ixo = Ixc +ad^2 where Ixc = bh^3/12
    Iyo subsection = 2.333333
    XBAR subsection = 1.500000
    YBAR subsection = 2.000000 //Wrong should be 1.5
    //The following value are based on the values above...
    Ixc subsection = -1.333333 //Wrong should be .08333
    Iyc subsection = 0.083333
    Attached Images Attached Images  
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    In your loops, you make assignments such as:

    subsectionData.area = subsectionData.area + ...

    However, you don't initialise these values before starting the loop.

    Try:

    Code:
    ...
    int x;
    subsectionData.area = 0;
    subsectionData.Ixo = 0;
    subsectionData.Iyo = 0;
    subsectionData.XBAR = 0;
    subsectionData.YBAR = 0;
    
    for(x = 0; x <3; x++)
    ...

  3. #3
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Davros thanks for the quick reply, but...

    Sorry I forgot to mention that I have actually called a function 'ZeroStructures' at the beginning of my program that initializes all these variables.

    I actually think there may be an error in my formulae. I just got back from the library but it was no use. They don't have much on this subject.

    Code:
    void ZeroStructures()
    {
    	subsectionData.area = 0;
    	subsectionData.Ixc = 0;
    	subsectionData.Ixo = 0;
    	subsectionData.Iyc = 0;
    	subsectionData.Iyo = 0;
    	subsectionData.k = 0;
    	subsectionData.XBAR = 0;
    	subsectionData.YBAR = 0;
    	subsectionData.Ixy = 0;
    	return;
    }
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 05:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 04:48 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 08:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 03:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21