Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
4218 views
%md Here we have some data: Syracuse weather data (month, max temp): (1, 32),(2,34),(3,43),(4,57),(5,69),(6,78),(7,82),(8,80),(9,72),(10,60),(11,48),(12,36) We'll make a scatter plot of the data first and call the plot 'p'.

Syracuse weather data (month, max temp): (1, 32),(2,34),(3,43),(4,57),(5,69),(6,78),(7,82),(8,80),(9,72),(10,60),(11,48),(12,36)

data=[(1, 32),(2,34),(3,43),(4,57),(5,69),(6,78),(7,82),(8,80),(9,72),(10,60),(11,48),(12,36)] p=scatter_plot(data) p
%md Next, we determine the parameters for amplitude, period, phase shift and midline. This gets a little tedious. Take careful note of the lines that you would actually edit!!!!!!!!
data=[(1, 32),(2,34),(3,43),(4,57),(5,69),(6,78),(7,82),(8,80),(9,72),(10,60),(11,48),(12,36)]#you will edit this with new data a,b,c,d=var('a,b,c,d') model(x)=a * sin(b*(x - c))+d values=find_fit(data,model,initial_guess=(25,pi/6,7,60))#you will edit the guess values based on the scatterplot params=[a,b,c,d] for i in range(4): params[i]=values[i].rhs() model(x)=params[0] * sin(params[1]*(x - params[2]))+params[3] model(x) p=scatter_plot(data,xmin=-2,xmax=14,ymin=-10,ymax=100) p+=plot(model(x),xmin=-2,xmax=14,ymin=-10,ymax=100) p
25.61099628075631*sin(0.5089522520223427*x - 2.068485038219847) + 56.87966137474419
find_fit(data,model,initial_guess=(25,pi/6,7,60))
[a == 25.61099628075631, b == 0.5089522520223427, c == 4.064202545524923, d == 56.87966137474419]
a = 25.61099628075631; b = 0.5089522520223427; c = 4.064202545524923; d = 56.87966137474419
y=a * sin(b*(x - c))+d show(y)
25.6109962807563sin(0.508952252022343x2.06848503821985)+56.8796613747442\displaystyle 25.6109962807563 \, \sin\left(0.508952252022343 \, x - 2.06848503821985\right) + 56.8796613747442
p=plot(y,0,12) p+s

Your turn!

  1. Follow the link http://mathbits.com/MathBits/TISection/Statistics2/sinusoidal.html to find data for the two other cities. Type in the data and create separate scatter plots. Then find the sinusoidal model for each.

  2. Plot the function: f(x)=sin(2x-π)-2, g(x)=-3sec(πx); h(x)=tan(x-π/2) in a single graphing window from [-2π,2π]. Use different colors for each graph!

Plot the function: f(x)=sin(2x-pi)-2,g(x)=-3sec(pix);h(x)=tan(x-pi/2)