Search This Blog

Wednesday, February 13, 2008

classical mechanics problem: box on an incline

for some reason i'm in a physics mood so i thought i'd share a classic problem that anyone that took elementary mechanics would come across at some point and how to solve it .

Q: a box of mass m sits motionless on an incline. what is the maximum angle Θ of the incline before the box begins to slide down?

A: all good little physics students know the first step is to draw a diagram and then add forces:


where Θ is the angle of the incline, μ is the coefficient of friction and N is the normal force

now lets disect the horizontal and vertical forces on the box:

ΣFx = horizontal component of gravity - friction = mgsin(Θ) - μN = 0 (box is stationary)

-> mgsin(Θ) = μN

ΣFy = vertical component of gravity - normal force = mgcos(Θ) - N = 0 (box is stationary)

-> mgcos(Θ) = N

we have two equations and three unknowns (Θ, μ, and N). the second equation gives us a N in terms of Θ, so let's plug it into the first equation and then solve for Θ:

mgsin(Θ) = μ(mgcos(Θ))

cancel out mg on both sides and get μ by itself:

μ = sin(Θ)/cos(Θ) = tan(Θ)

bring tan to the other side and we are done:

Θ = arctan(μ)

the solution tells us that the largest angle of incline before the box moves is dependent on the coefficient of friction of the incline.

mercy i loves me some classic mechanics :)

bubu made the rock band hall of fame

on a personal note, i would like to congratulate bubu on their induction into the rock band hall of fame. most of the credit goes to my singer, YEAHYEAH (who also happens to be the computing services/IT/network guy where i work) and, or course, me, who is most proficient with the axe (both lead and bass) but is also more than competent with the sticks (drums) and has had to take that role when friends with no rhythm whatsoever come over and want to play. a special thanks goes to maneet and good sir thomas playing bass and lead guitar respectively for assisting YEAHYEAH and i on that fateful night. i'd also like to thank diiiiiiiiiidddtttyy, good sir thomas, lonlon and YEAHYEAH for helping the band regain several hundred thousand fans that we lost when i had too much to drink and repeatedly played and failed the song 'gimme shelter' by the stones (alcohol gives me sausage fingers). i'd also like to thank alex (who is a phenom with the sticks), tha dream (who really isn't that good with the sticks), superman, and winnie (who recently became tha dream's wife), for their help along the way.

come to think of it, all the above mentioned people with the exception of good sir and winnie work with YEAHYEAH and i. i think this is one of the reasons that i love where i work - i like to hang out with my coworkers, be it going out boating, going out to a bar, hanging out late at work late and discussing business over a beer or just having everyone come over for some rock band jam'ins. at least half of tha dream's wedding last week was composed of coworkers. i genuinely consider these people friends and am eternally grateful that i work for a company that encourages this kind of environment.

the effects of changing a machine's name on sql server

i decided to post about this because, i shit you not, every single member of our solution delivery department (aka our consultants) and a good number of our developers have approached me with issues after renaming their machine. one may be wondering why so many people are renaming their computer in the first place. simple - in my neck of the woods, we have several baseline virtual machine images built up for anyone to use. when someone begins using it, they typically give the 'computer' a new name (especially if they want to join it to the domain). the problem is that sql server doesn't pick up on this and programs that try to connect to the server by referencing it by the new name (or new name\instance name) will get errors along the lines of 'the server could not be found in the sysservers list. try adding the server using sp_addlinkedserver'. don't do that; it won't work. try running this command against the master database instead:

SELECT @@servername

it will probably return the name of the machine (\instance name) before you renamed it. the fix is this:

sp_dropserver '{oldname}'

where {oldname} is whatever was returned by your first query. after that, run this:

sp_addserver '{newname}(\instancename)', 'LOCAL'

obviously only include (\instancename) if it is a named instance of sql server. restart the sql server service, then re-run your original query and it should return the correct name (you will have to either open a new query editor or re-connect the query editor screen you originally used as restarting the service will cause a disconnect).

Tuesday, February 12, 2008

damned system named constraints

problem: you need to write a script to alter or drop a column as part of a hotfix for your clients. this column was created with a default constraint, but this default constraint was not explicitly named, thus a system-generated name was given (which looks something like 'DF__(partialtablename)__(partialcolumnname)__(random numbers and letters)' in SQL Server 2005). since the name of the constraint will be different on every client, you can't write a straight forward 'ALTER TABLE DROP CONSTRAINT ' statement.

solution: system tables aaaaaaaand ...

dynamic sql!!! weeeeeeeeeeeeeeeee

(i don't know why i got excited about something i genearlly preach against, but, as i've said before, dynamic sql is a necessary evil and can be very useful)

/*1. i think it is good practice to validate that something exists before dropping it (or does not exist before adding it). that way if a sql query that is part of a hotfix is accidentally run more than once, no errors should occur. this script simply checks to see if there is a constraint on a column named 'col_a' in table_a:*/

IF EXISTS (SELECT OBJECT_NAME(constid) FROM sysconstraints CN
INNER JOIN syscolumns CO
ON CN.id = OBJECT_ID('table_a') AND CO.id = CN.id AND
CO.name = 'col_a' AND CN.colid = CO.colorder)
BEGIN

/*2. the following sample then removes the constraint from the column:*/

DECLARE @Sql AS NVARCHAR(2000)

SELECT @Sql = 'ALTER TABLE table_a DROP CONSTRAINT ' + OBJECT_NAME(constid)
FROM sysconstraints CN
INNER JOIN syscolumns CO
ON CN.id = OBJECT_ID('table_a') AND CO.id = CN.id AND
CO.name = 'col_a' AND CN.coldid = CO.colorder

EXEC(@Sql)

END

/* to be extra safe, you may want to include the type of constraint you are dropping as part of the join. the type of constraint is contained in the pseudo-bit-mask value of the sysconstraints 'status' column. as an example, a default constraint will have a status value of '133141' */