Question: The following code is supposed to evaluate the function x = np . linspace ( - 4 , 4 , 3 0 0 ) N

The following code is supposed to evaluate the function
x = np.linspace(-4,4,300)
N = x.size
for j in range(N):
if x[j]>=0 and x[j]<=1:
f = x
elif x[j]>=1 or x[j]<=2:
f =2-x
else:
f =0
Correct the code so that it accomplishes this task. This can be checked by using the command
pylab.plot(x,f) and comparing the figure to what you expect the function to look like. Include a
plot of f(x) vs x with your homework submission.

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!