Ask Your Question
0

how to plot a fit line

asked 2015-05-06 16:51:25 +0100

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
0

answered 2015-05-07 04:05:22 +0100

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) ]
fit=find_fit(data,model,solution_dict=True)
print fit[a],fit[b]
point(data)+plot(fit[a]*exp(fit[b]*x),(x,0,25))
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

Stats

Asked: 2015-05-06 16:51:25 +0100

Seen: 884 times

Last updated: May 07 '15