How do I write a spring program?
8 次查看(过去 30 天)
显示 更早的评论
I have a spring program:
x=((m*g+a*(a+1)*k*d))/((2*a+1)*k)
where m = mass, g = gravity, k = spring constant, d = equals the distance in height between each pair of springs, a = the number of pairs of springs the user inputs, and x = the distance the mass compresses the springs.
This equation works great on one spring and one pair of springs, however, if I used (for example: 10kg, 9.8m/s^2, 200N*m, .2m and 5 pairs of springs) it compresses more than if I used just one spring and one pair.
How do I adjust this to account for an infinite amount of springs where no matter what the user requests it would only engage the 3 total springs?
1 个评论
Cedric
2013-3-12
It is difficult to understand your statement without at least a better explanation about your setup (if not a schematics). I don't understand how these pairs are setup, why d is not a vector if there are multiple pairs, why there would even be a difference in the height between pairs, and why you mention 3 total springs in the end when you seem to say that you are dealing with pairs of springs.
采纳的回答
Cedric
2013-3-13
编辑:Cedric
2013-3-14
Without having more information from you, the best answer that I can say is that you wait 8 more days and then whatever program you'll write, it will be a "spring program" ;-)
More seriously, if we assume that you have n pairs of springs that support some mass m, and that they all have the same spring constant k, we can write
F = sum(-(2*k) * delta_x) = -(2*k) * sum(delta_x) = mg
where F is the resultant force applied by all springs to the mass (when the mass is steady), and delta_x is a vector of displacements (one component per pair of springs). Now if the mass is homogeneously distributed over all pairs of springs, all delta_x are equal and we can compute a delta_x_m that represents the displacement of the center of mass of m
sum(delta_x) = n * delta_x_m
delta_x_m = - m*g / (2*k*n)
Here we see that n lies in the denominator, so the more pairs of springs you have, the closer to 0 the displacement (negative) of the center of mass is.
Now if the mass is not homogeneously distributed, there is little that you can say unless you know the distribution. The only thing that you know is that delta_x_m will lie between two limit cases:
1. What we've just seen with the homogeneous distribution.
2. All the mass lies on one unique pair of springs, in which case we have
delta_x_m = - m*g / (2*k)
To be more specific to your setup, I would need to know what I mentioned in my comment above.
9 个评论
Cedric
2013-3-17
编辑:Cedric
2013-3-17
Ok, it's a simpler setup than what I though interpreting the "pairs of springs" that you mentioned.
In the same time, I still don't understand what you model with your d and what you mean when you output
fprintf('You used %.0f springs to support the weight. \n',ns)
In any case, all springs are used to support the weight in the sense that they will all be compress and they will hence all exert a vertical force supporting part of the weight of m.
It is easy to write an analytical expression for the variation of height of each level:
delta_h(ii) = F / (ii*k) = -m*g / (ii*k)
where k is the spring constant and ii is the level ID (starting at 1 at the top). If the mass is not too heavy, all variations are smaller (in absolute value) than the nominal length of springs L0. In such case, you can write an analytical expression for the total variation of height over all levels (which is the distance the center of mass of m will move after being released) for a system with n levels:
delta_h_total = F/k + F/(3*k) + F/(5*k) + .. + F/((2*n-1)*k)
= -m*g/k * (1 + 1/3 + 1/5 + .. + 1/(2*n-1)
Here, you can compute a partial sum of the series 1/ii and obtain a simple expression. This expression fails, however, if any level (especially the top one) bottoms out, and it would be difficult to obtain an analytical expression that includes the fact that springs/levels can bottom out.
Now it is not too complicated to manage such situation numerically. I define a vector of variation in height for e.g.
>> F = -50*9.81 ;
>> k = 100 ;
>> lIds = 1:4 ; % Corresponds to your illustration wiht 4 levels.
>> delta_h = F/k * 1./(2*lIds-1)
delta_h =
-4.9050 -1.6350 -0.9810 -0.7007
Now these are values assuming that the nominal length of springs is greater than 4.905. So if the nominal length is 10, the total variation in height will just be the sum of these variations per level:
>> delta_h_total = sum(delta_h)
delta_h_total =
-8.2217
If the nominal length of springs is L0=3 however, the first spring will bottom out. This can be easily managed; first we detect and count elements of delta_h that are greater than L0 in absolute value:
>> L0 = 3 ;
>> isBottomOut = abs(delta_h)> L0 % Flag indicating "bottom out".
isBottomOut =
1 0 0 0
>> nBottomOut = sum(isBottomOut )
nBottomOut =
1
Then we set these elements to -L0, which is the variation that will happen in practice:
>> delta_h(isBottomOut) = -L0
delta_h =
-3.0000 -1.6350 -0.9810 -0.7007
Now you see the variation in height of the 1st/top level limited to the nominal length of the spring. You can then compute the real total variation in height:
>> delta_h_total = sum(delta_h)
delta_h_total =
-6.3167
and print something, e.g.
>> fprintf('Total var. in height = %.2fm (%d spring(s) bottom out).\n', ...
delta_h_total, nBottomOut) ;
Total var. in height = -6.32m (1 spring(s) bottom out).
Finally, what happens if the user enters 6 for the number of springs? There is no regular pyramid that can be built using 6 springs with the structure that you indicated. Wouldn't it be better if the user would enter the number of levels?
PS: the error that you indicate involves limitofSprings that doesn't appear in your code.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Argument Definitions 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!