Question: 2.18 Piecewise functions are sometimes useful when the relationship between a dependent and an independent variable cannot be adequately represented by a single equation. For

2.18 Piecewise functions are sometimes useful when the relationship between a dependent and an independent variable cannot be adequately represented by a single equation. For example, the velocity of a rocket might be described by y(t) 5 e 11t2 2 5t 0 # t # 10 1100 2 5t 10 # t # 20 50t 1 2(t 2 20)2 20 # t # 30 1520e20.2(t230) t . 30 0 otherwise Develop a well-structured function to compute v as a function of t. Then use this function to generate a table of v versus t for t 5 25 to 50 at increments of 0.5.

import math

import numpy as np

def velocity(t):

v=0

if 0 <= t <= 10:

v = 11*t**2 - 5*t

elif 10 <= t <= 20:

v = 1100 - 5*t

elif 20 <= t <= 30:

v = 50*t + 2*((t-20)**2)

elif t >30:

v = 1520*(math.e**(-0.2*(t-30)))

return v

print("+--------+--------+")

print('| %-6s | %-6s |' %('t','v(t)'))

print("+--------+--------+")

for t in np.arange(-5,50.5,0.5):

print('| %-6.1f | %-6.1f |' %(t,velocity(t)))

print("+--------+--------+")

Can anyone please provide analysis for this code.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!