# Help creating a function file

10 views (last 30 days)
Steven on 17 Mar 2012
Answered: Steve Miller on 21 Dec 2022
For this problem I need to create a function file that computes distance x and use my function to plot x versus W.
Here is the problem:
Figure P20 shows a mass-spring model of the type used to design packaging systems and vehicle suspensions, for example. ('of course I am aware you cannot see this figure').The springs exert a force that is proportional to their compression, and the proportionality constant is the spring constant 'k'. The two side springs provide additional resistance if the weight 'W' is gently placed, it moves through a distance 'x' before coming to rest. From statics, the weight force must balance the spring forces at this new position. Thus
W=(k1)*x [ if x < d ]
W=(k1)*x + 2(k2)*(x-d) [ if x >= d ]
These relations can be used to generate the plot of x versus W.
a) Create a function file that computes the distance x, using the input parameters W, k1, k2, and d. Test your function for the following two cases, using the values k1 = 10^4 N/m; k2 = 1.5 x 10^4 N/m; d = 0.1 m.
b) Use your function to plot x versus W for 0 <= W <= 3000 N for the values of k1,k2,and d given in part a.
Thank you..
##### 2 CommentsShowHide 1 older comment
Joseph Areeda on 17 Mar 2012
Steven,
It sounds a lot like you're asking us to do your homework for you.
If your question is how to write a Matlab function see http://www.mathworks.com/help/techdoc/ref/function.html
If your question is how to plot the results see: http://www.mathworks.com/help/techdoc/ref/plot.html
In general, I've had good luck googling Matlab <what programming tool I want to use>.

Steve Miller on 21 Dec 2022