Last active
February 7, 2019 20:10
-
-
Save ja72/dc14b4aa5f64b442ecafa7325bccdac0 to your computer and use it in GitHub Desktop.
Calculate the table support forces for an irregular polygon table.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program table_support | |
! code to accomapny the follwoing Physics.SE answer | |
! https://physics.stackexchange.com/a/459404/392 | |
implicit none | |
! Variables | |
integer :: i, n | |
real, allocatable :: x(:), y(:), F(:) | |
real :: C_x, C_y, d, W | |
real :: S_x,S_xx,S_y,S_yy,S_xy | |
! Body of program | |
write (*,*) 'Table with n legs of irrgular shape.' | |
write (*,*) 'Find each leg support as a percent of the total weight of the table' | |
write (*,*) 'Enter the number of legs n=' | |
read (*,*) n | |
allocate(x(n),y(n)) | |
write (*,*) 'Enter leg coordinates relative to the center of gravity' | |
do i=1,n | |
write(*,'(1x,a,i2,a)') 'Leg i=', i, ' coordinates (x,y):' | |
read(*,*) x(i),y(i) | |
end do | |
S_x = sum(x) | |
S_y = sum(y) | |
S_xy = sum(x * y) | |
S_xx = sum(x**2) | |
S_yy = sum(y**2) | |
d = (n*S_yy-S_x**2)*(n*S_xx-S_x**2)-(n*S_xy-S_x*S_y)**2 | |
C_x = (S_x*S_xy-S_xx*S_y)/d | |
C_y = (S_x*S_yy-S_y*S_xy)/d | |
allocate(F(n)) | |
do i=1,n | |
F(i) = 1d0/n + (n*y(i)-S_y)*C_x + (S_x-n*x(i))*C_y | |
write(*,'(1x,a,i2,a,g,a,g,a,g)') 'Leg i=', i, ' x=', x(i), ' y=', y(i), ' Force=', F(i) | |
end do | |
W = sum(F) | |
write (*,'(1x,a,g)') 'Sum of forces is W=', W | |
end program table_support |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment