Lesson goal: For loops to plot sin and cos

Previous: Plot a star | Home | Next: Test the famous sin/cos identity

The sine and cos functions are wonderful functions to plot. They have three key parameters that are worth looking into: their amplitude, frequency, and phase. The amplitude is how tall the function are. The frequency is how fast they go up and down, and their phase is how far left or right they appear to be pushed. The general formula for a good sine function is $y=A\sin(2\pi f x+B)$, where $A$ is the amplitude, $f$ is the frequency, and $B$ is the phase. Let's plot some of these sine functions (or sin waves) here and see how they look. We'll use a for-loop to cycle through the free variable, $x$.

Make some plots here should help yo to understand the sine function and how the three parameters affect its behavior.

Now you try. Try fixing the A=, f= and B= statements.

Type your code here:

See your results here:

This code will not run. You have to choose a value for $A$, $f$, and $B$. We'd recommend starting with $A=10$, $f=0.05$, and $B=0$. Can you do it? Dismiss.
Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.