How can I adjust the range and scaling for a cos function in Python?

Click For Summary

Discussion Overview

The discussion revolves around adjusting the range and scaling of a cosine function in Python for graphical representation. Participants explore how to modify the amplitude and range of the cosine function to achieve desired visual outcomes in plots.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant suggests modifying the equation to change the range of the cosine function, proposing alternatives like t = np.cos(r) + 1 or t = 12*(np.cos(r) + 1) to adjust the lower extreme to the y=0 axis.
  • Another participant expresses confusion about the syntax and the meaning of "np." and "plt.", indicating a lack of familiarity with Python libraries.
  • Concerns are raised about the potential for negative values in the output due to the initial addition of +10 in the function.
  • A participant questions the wavelength of the cosine function and how to adjust the input array r to match the desired wavelength in the graph.
  • Discussion includes a reference to the general formula for cosine functions, y = A cos(ωt + φ), emphasizing the importance of amplitude and angular frequency.
  • A later reply shares a successful modification of the function, using r = np.arange(0,400,0.4) and t = (11*np.cos(r/28.7)) + 11, indicating satisfaction with the results.

Areas of Agreement / Disagreement

Participants express varying levels of understanding and familiarity with Python, leading to some confusion and disagreement about the implementation details. Multiple approaches to adjusting the cosine function are proposed, but no consensus is reached on a single method.

Contextual Notes

Some participants highlight the need for clarity on the definitions of terms and functions used in Python, as well as the mathematical properties of the cosine function, which may affect the adjustments being discussed.

Arman777
Insights Author
Gold Member
Messages
2,163
Reaction score
191
Python:
r = np.arange(0,400,0.1)
t = np.cos(r)+10
plt.plot(r,t)

How can I use the range of the cos function to look like this
 

Attachments

  • Adsız.png
    Adsız.png
    16 KB · Views: 441
Technology news on Phys.org
Do you mean
change t = np.cos(r)+10
to t = np.(cos(r) + 1) edit: or t = 12*(np.cos(r) + 1) ; if np. is not the amplitude
so that the lower extreme is on the y=0 axis?
 
Merlin3189 said:
Do you mean
change t = np.cos(r)+10
to t = np.(cos(r) + 1) edit: or t = 12*(np.cos(r) + 1) ; if np. is not the amplitude
so that the lower extreme is on the y=0 axis?
there's a syntax error in your code. Also no, I mean that I need to write a cos function that will look like my graph. Or cos^2x function. Both are okay for me
 
Sorry. I'm not a Python person, so I don't know "np." nor "plt." . They look like references to objects defined elsewhere, but there's no way I can see of knowing what those objects are like.

I just noticed that +10 would leave some negative values.

I'm not sure what you want that's different from the graph you're getting? I can't see where it gets the y-axis values, but that's probably just how you've labelled the axis.
 
  • Like
Likes   Reactions: Arman777
What's the wavelength of ##\cos(x)##? What's the wavelength of your graph? What do you need to do to your array ##r## so that the wavelength matches?

What are the minimum and maximum values of ##\cos(x)##? What are the minimum and maximum values of your graph? What do you need to do to make them match?
 
  • Like
Likes   Reactions: Arman777
Have you seen this formula before: ##y = A \cos(\omega t + \phi)##? A is the amplitude, ##\omega## is the angular frequency in radians per second and ##\phi## is the phase angle in radians. You need ##\omega## so that it has completed two revolutions for t = 360 degrees.
 
  • Like
Likes   Reactions: Arman777
Python:
r = np.arange(0,400,0.4)
t = (11*np.cos(r/28.7))+11
plt.plot(r,t)
I guess I find it :) , This works well
 
Last edited:

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 21 ·
Replies
21
Views
6K
Replies
55
Views
7K
  • · Replies 3 ·
Replies
3
Views
2K