Search code examples
plotmaple

Plotting cosine wave samples in Maple


I'm having trouble with Maple.

I have a cosine wave, which I figured out how to plot, but now I have to take samples from that wave and plot those(as dots) over top of the original cosine wave. Here is the question from the assignment:

"Produce the samples from Q1 above and plot the result (plot the points on a plot of the cosine wave - use different colours for both, it will look like a cosine wave with dots on it)"

Problem is, my samples keep being straight lines at different heights

enter image description here

http://i197.photobucket.com/albums/aa221/Haseo_Ame/Maple.png

I'm not sure what I'm doing wrong since I've never used maple before.


Solution

  • Firstly, try not to build up lists using repeated concatenation (which can incur an O(n^2) in resources) if you can use the seq command instead (which can incur an O(n) cost in resources). You should always reconsider, when coding like s:=[op(s),...] in a loop.

    Next, a point-plot needs pairs of x-y values. Your list is just a collection of scalar values, and hence is being interpreted as a collection of constant functions to be plotted.

    The pairs of x-y values can be in a list of (2-element) lists such as [[x1,y1],...,[xn,yn]

    It's not clear how you want your x-axis scaled, but you could start off with something like this,

    s:=[seq([i, 4*cos(2*Pi*i*70/200+Pi/4)],i=0..20)]:
    
    plot(s, style=point);
    

    enter image description here

    #  s:=[seq([2*Pi*i*70/200+Pi/4, 4*cos(2*Pi*i*70/200+Pi/4)],i=0..20)]:
    

    ps. Please post source code as text, not as embedded images, so that anyone trying to help needn't type it all in.