Question

(10 pts) Write a single .py file program to plot the following functions on the same...

  1. (10 pts) Write a single .py file program to plot the following functions on the same graph for x values from –π to π :

y1 = cos(x)

y2 = cos(2x)

y3 = cos(3x)

Plot specifications:

  1. Choose an appropriate increment to generate smooth curves and add a comment in the code as to the rationale for that increment to receive full credit
  2. y1 is red and dashed
  3. y2 is blue and solid
  4. y3 is black and dotted
  5. Add a legend encompassing all three plots
  6. Add an appropriate X-axis label
  7. Add an appropriate Y-axis label
  8. Add an appropriate Title
  9. To receive full credit, header and code comments are required
  10. (10 pts) Write a single .py file program to plot the following functions on the same graph for x values from –π to π :
  11. y1 = cos(x)

    y2 = cos(2x)

    y3 = cos(3x)

    Plot specifications:

  12. Choose an appropriate increment to generate smooth curves and add a comment in the code as to the rationale for that increment to receive full credit
  13. y1 is red and dashed
  14. y2 is blue and solid
  15. y3 is black and dotted
  16. Add a legend encompassing all three plots
  17. Add an appropriate X-axis label
  18. Add an appropriate Y-axis label
  19. Add an appropriate Title
  20. To receive full credit, header and code comments are required
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

x = np.arange(-np.pi, np.pi+0.1,0.1) #0.1 will make enough points
# so that curve looks smooth
y1 = np.cos(x)
y2 = np.cos(2*x)
y3 = np.cos(3*x)

fig=plt.figure(figsize=(16, 6 ))
fig.suptitle('3 cosine variations', fontsize=16)

fig.add_subplot(1,3 , 1)
plt.plot(x ,y1, 'r--', linewidth= 2, label = "cos(x)")
plt.xlabel('x')
plt.ylabel('cos(x)')
plt.legend()

fig.add_subplot(1,3 , 2)
plt.plot(x ,y2, 'b-', linewidth= 2, label = "cos(2x)")
plt.xlabel('x')
plt.ylabel('cos(2x)')
plt.legend()


fig.add_subplot(1,3 , 3)
plt.plot(x ,y2, 'k-.', linewidth= 2, label = "cos(3x)")
plt.xlabel('x')
plt.ylabel('cos(3x)')
plt.legend()



Output:

cos(x) cos(2x) - cos(3x)

Add a comment
Know the answer?
Add Answer to:
(10 pts) Write a single .py file program to plot the following functions on the same...
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
  • Given y1, y2, and y3 as a function of x. In the same graph plot the...

    Given y1, y2, and y3 as a function of x. In the same graph plot the three functions for x ?[-3,3] . Follow the form given below. function y1 Line style: solid, color: blue function y2 Line style: dashed, color: black function y3 Line style: dotted, color: red Label the x and y axis; x axis as (x), and the y axis as (y1,y2,y3), title the graph as (problem5), add a legend on the plot. y1=x^4-e^(-x) y2=x^2-x^3+25 y3=30-12x,

  • Problem 31: (34 points) 1. (10 points) A pulse width modulated (PWM) signal fPwM(t) in Figure...

    Problem 31: (34 points) 1. (10 points) A pulse width modulated (PWM) signal fPwM(t) in Figure 2. The symbol D represents a duty cycle, a number between zero and one. Determine the compact trigonometric Fourier series coefficients (Co C,11 %) of the signal f(t). 2. (10 points) One use of PWM is to generate variable DC voltages. While the PWM signal is not DC, you should be able to see from your results in part 1 that it hss a...

  • A group of physics students collected data from a test of the projectile motion problem that...

    A group of physics students collected data from a test of the projectile motion problem that was analyzed in a previous lab exercise (L5). In their test, the students varied the angle and initial velocity Vo at which the projectile was launched, and then measured the resulting time of flight (tright). Note that tright was the dependent variable, while and Vo were independent variables. The results are listed below. (degrees) Time of Flight (s) Initial Velocity V. (m/s) 15 20...

  • Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate...

    Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...

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