07-02-2013, 07:19 PM
Ok, I think there is a bug in Marv's code.
We are going to focus in page 20 of the article.
In the article the mandrel size hinges on the value of k.
Based on the graph on page 20, the y axis of the graph is k and it is labeled k = Dm / D where Dm is the diameter of the mandrel and D is the diameter of the spring. The x axis of the chart is the Spring Index, D / d where D is the diameter of the spring and d is the diameter of the wire.
There are two lines on the graph which represent the relationship between the Spring Index and k for Music and Stainless Steel wire and for Phosphor Bronze wire. We know the desired diameter of the spring and the wire size so the calculation of the Spring Index is straight forward.
Regretfully the only source for the value of k is the graph ... no formula is given. Given that we can not teach the computer to look at the graph to determine k we will try to do something reasonable.
If we take the information that we see on the graph it appears to be a straight line. If we put the values of k that we see for each type of wire for the Spring Index values of 5 thru 15 that are on graph into Excel and then do a least squares regression on it we see that it is a reasonably straight line ... a coefficient of determination of .98 is really, really good ... and therefore we can calculate k with a simple equation
k = mx + b
where m = -0.0124727272727273 and b = 0.980818181818182 for music and stainless steel wire
and m = -0.0109727272727273 and b = 0.984909090909091 for phosphor bronze wire.
and x is the Spring Index.
Now that we have all the numbers we need, we simply put them into the formula at the bottom of the page
Dm = (k * D) - d and come up with the mandrel size.
If we look at the code, we see the following bits ...
Variables defined
and the following calculations after the user is asked to provide wire type ... a number of 0 for music and stainless steel wire and 1 for phosphor bronze wire, the wire diameter and the spring inside diameter
The first line simply calculated D, the average spring diameter in our previous analysis and the article, by adding the desired inside spring diameter to the wire size.
The second line calculates k based on the type of wire the user entered. It gets the value of b from c0 then adds it to the value of m from c1 divided by the spring index. Given that there are no parenthesis used in the formula the author is counting on the operator hierarchy in C to make sure the multiplication and division happens first followed by the addition. [side note ... I am not a big fan of this practice but ...]
If the wire type entered by the user was 0 for music and stainless steel wire then the first value ... the value before the comma ... in c0 and c1 are used in the calculation of k.
If the wire type entered by the user was 1 for phosphor bronze wire the the second value ... the value after the comma ... in c0 and c1 are used in the calculation of k.
Finally the last line does the same calculation that we discussed in our analysis where we take k and multiply is by the spring diameter and then add the wire size.
I do believe the bug is in the second value of c0.
If you look at the first values of c0 and c1 they are very close to the values we discovered for m and b with Excel ... certainly close enough for this type of work.
However, if you look at the second values of c0 and c1 the m values again are very close but the b value is way off. This would explain why the phosphor bronze calculations seem to be so far off.
I can not explain where that value might have come from but it certainly seems out of place.
Comments? Thoughts? Concerns?
Arvid
We are going to focus in page 20 of the article.
In the article the mandrel size hinges on the value of k.
Based on the graph on page 20, the y axis of the graph is k and it is labeled k = Dm / D where Dm is the diameter of the mandrel and D is the diameter of the spring. The x axis of the chart is the Spring Index, D / d where D is the diameter of the spring and d is the diameter of the wire.
There are two lines on the graph which represent the relationship between the Spring Index and k for Music and Stainless Steel wire and for Phosphor Bronze wire. We know the desired diameter of the spring and the wire size so the calculation of the Spring Index is straight forward.
Regretfully the only source for the value of k is the graph ... no formula is given. Given that we can not teach the computer to look at the graph to determine k we will try to do something reasonable.
If we take the information that we see on the graph it appears to be a straight line. If we put the values of k that we see for each type of wire for the Spring Index values of 5 thru 15 that are on graph into Excel and then do a least squares regression on it we see that it is a reasonably straight line ... a coefficient of determination of .98 is really, really good ... and therefore we can calculate k with a simple equation
k = mx + b
where m = -0.0124727272727273 and b = 0.980818181818182 for music and stainless steel wire
and m = -0.0109727272727273 and b = 0.984909090909091 for phosphor bronze wire.
and x is the Spring Index.
Now that we have all the numbers we need, we simply put them into the formula at the bottom of the page
Dm = (k * D) - d and come up with the mandrel size.
If we look at the code, we see the following bits ...
Variables defined
Code:
dbl c0[]={0.980364,0.012436}; //constant coefficient
dbl c1[]={-0.012436,-0.11018}; //first order coefficient
dbl id; //spring internal diameter (in)
dbl ds; //average spring diameter (in)
dbl dw; //wire diameter (in)
dbl fact; //empirical factor (nd)
dbl dm; //mandrel diameter (in)
and the following calculations after the user is asked to provide wire type ... a number of 0 for music and stainless steel wire and 1 for phosphor bronze wire, the wire diameter and the spring inside diameter
Code:
ds=id+dw; //spring average diameter
fact=c0[wt]+c1[wt]*ds/dw; //empirical factor
dm=fact*ds-dw; //mandrel diameter
The first line simply calculated D, the average spring diameter in our previous analysis and the article, by adding the desired inside spring diameter to the wire size.
The second line calculates k based on the type of wire the user entered. It gets the value of b from c0 then adds it to the value of m from c1 divided by the spring index. Given that there are no parenthesis used in the formula the author is counting on the operator hierarchy in C to make sure the multiplication and division happens first followed by the addition. [side note ... I am not a big fan of this practice but ...]
If the wire type entered by the user was 0 for music and stainless steel wire then the first value ... the value before the comma ... in c0 and c1 are used in the calculation of k.
If the wire type entered by the user was 1 for phosphor bronze wire the the second value ... the value after the comma ... in c0 and c1 are used in the calculation of k.
Finally the last line does the same calculation that we discussed in our analysis where we take k and multiply is by the spring diameter and then add the wire size.
I do believe the bug is in the second value of c0.
If you look at the first values of c0 and c1 they are very close to the values we discovered for m and b with Excel ... certainly close enough for this type of work.
However, if you look at the second values of c0 and c1 the m values again are very close but the b value is way off. This would explain why the phosphor bronze calculations seem to be so far off.
I can not explain where that value might have come from but it certainly seems out of place.
Comments? Thoughts? Concerns?
Arvid