0
|
5735 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
GROUPS:

# How do I create a parameter-driven piece-wise function?

Posted 10 years ago
 Assuming in a physic system, an object move from one point to anther point. During the movement, the acceleration changes with time t. In the first t1 seconds, a=t; In the following t2 seconds, a = 0.5t. Then I wrote the code as follows: t1 = 1; t2 = 3; acceleration = Piecewise[{{ t, 0 <= t < t1}, {0.5 t, t1 < t <= t1 + t2}}] velocity = Integrate[acceleration, t] Plot[acceleration, {t, 0, t1 + t2}] Plot[velocity, {t, 0, t1 + t2}]  And the result looks nice: How ever, if in another application, I want to set t1 and t2 as adjustable parameter using the following code: t1 =.; t2 =.; acceleration = Piecewise[{{ t, 0 <= t < t1}, {0.5 t, t1 < t <= t1 + t2}}] velocity = Integrate[acceleration, t]  Then set t1=1, t2=3 and plot? t1 = 1; t2 = 3; Plot[acceleration, {t, 0, t1 + t2},] Plot[velocity, {t, 0, t1 + t2}]  The result is totally different: The reason why I want to set it parameter-driven is I want to get a function like v=f[t,t1,t2] which can be used in Excel calculation. Any one could point out why in the second part of the codes doesn't the result seem reasonable? And who can suggest a way to realize the parameter-driven system?
3 Replies
Sort By:
Posted 10 years ago
 Hi,I meant that if you run t1 = 1; t2 = 3;acceleration = Piecewise[{{t, 0 <= t < t1}, {0.5 t, t1 < t <= t1 + t2}}]; velocity = Integrate[acceleration, t] you get the right result and can plot it:Regarding the integration see final remark in:https://pantherfile.uwm.edu/sorbello/www/classes/mathematica_badintegral.pdfCheers, Marco
Posted 10 years ago
 Dear Seasong,this is indeed not what you would expect at first. When you execute: t1 =.; t2 =.; acceleration = Piecewise[{{t, 0 <= t < t1}, {0.5 t, t1 < t <= t1 + t2}}] velocity = Integrate[acceleration, t] you getYou see that the integral was evaluated for the three conditions individually. If you calculate D[velocity, t] you get the correct function of the acceleration, so that is ok. At the discontinuities there is obviously a problem with the derivative. Now if you run t1 = 1; t2 = 3; Plot[NIntegrate[acceleration, {t, 0., tu}], {tu, 0, 4}] you getI guess that the problem is that when you execute the Integrate you have t1 and t2 not set to fixed values. If you run: t1 = 1; t2 = 3; acceleration = Piecewise[{{t, 0 <= t < t1}, {0.5 t, t1 < t <= t1 + t2}}] velocity = Integrate[acceleration, t] you get which gives the correct continuous plot.Cheers, Marco
Posted 10 years ago
 Dear Marco, Thanks a lot for your time and reply.At the end of your reply, you mentioned if we set t1 and t2 to fixed values, the problem will be solved. However, what I try to do is to get the result when t1 and t2 are not fixed, which means in the output "4.25" will be a function of t1 and t2. And I want to use that function in Excel to calculate the velocity when t1 and t2 have different values. For example, in this system, I want mathematica to give me a result like this: If mathematica gives such result, then I can use the formula "0.5t1^2+0.5t1 t2 + 0.25t2^2" in Excel to calculate the final velocity after two periods of acceleration without the help of mathematica any more.Can you help? Looking forward to your reply.