Question

Exercise 5.3: Consider the integral Plot of the integral from 0 to x 0.8 e: more hints You need to print E(x) with different

Evaluate the integral for values of x from 0 to 3 in steps of 0.1 AND plot the integral.

The program needs to be written in Python 3. Can only import numpy and matplotlib. CAN NOT use lambda functions or classes of any kind.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
def trapizoidal(x):      #function that will do integration using trapizoidal rule
    a=0
    b=x          #upper limit that will take from the array of x
    h=0.001
    n=int((b-a)/h)
    c=np.linspace(a,b,n+1)
    #print(c)
    d=np.exp(-c*c)
    f=0
    for i in range(1,n):
        f=f+d[i]
    p=2*f+d[0]+d[n]
    u=p*(h/2)
    print(u)    #result of the integration
    return u

m=np.linspace(0,3,(int(3/.1+1)))  #taking x values for plottiing graph
n=np.zeros(len(m))        #initial array where integral values will be stored
for i in range(len(m)):
    n[i]=trapizoidal(m[i])  #storing integration values
plt.plot(m,n,label='integration')             #plotting graph
plt.title('plot of the integration  and function from 0 to 3')
c=np.exp(-m**2)
plt.plot(m,c,label='function')
plt.legend()
plt.show()
Add a comment
Know the answer?
Add Answer to:
Evaluate the integral for values of x from 0 to 3 in steps of 0.1 AND plot the integral. The prog...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT