Ask Your Question

how to plot a fit line

asked 2015-05-06 09:51:25 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

how do I add a fit line to my graph? Here is my coding:

initial_val = [100,100,100]
memo = {}
def lizardsquad(n):
    if n not in memo:
        memo[n] = initial_val if n == 0 else [1*lizardsquad(n-1)[0]-1*lizardsquad(n-1)[1]+2*lizardsquad(n-1)[2], 2*lizardsquad(n-1)[0]+1*lizardsquad(n-1)[1]-1*lizardsquad(n-1)[2],-1*lizardsquad(n-1)[0]+2*lizardsquad(n-1)[1]+1*lizardsquad(n-1)[2]]
    return memo[n]

show(list_plot([lizardsquad(i)[0] for i in range(25)], plotjoined=True, color='blue') + (list_plot([lizardsquad(i)[1] for i in range(25)], plotjoined=True, color='orange')) + list_plot([lizardsquad(i)[2] for i in range(25)], plotjoined=True, color='yellow'))
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-05-06 21:05:22 -0500

calc314 gravatar image

You can use find_fit to fit an exponential function to this data. (You could also fit a line but it is not a very good fit.) Here is an example:

var('a b c')
model(x) = a*exp(b*x)
data=[[i,lizardsquad(i)[0]] for i in range(25) ]
print fit[a],fit[b]
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2015-05-06 09:51:25 -0500

Seen: 90 times

Last updated: May 06 '15