Ask Your Question

Generating functions and plotting them with different colors

asked 2012-09-15 00:58:01 -0500

Flavius gravatar image

updated 2012-09-15 01:02:15 -0500

Let's say I have the logistic function

f(x) = a / (1 + b*e^(-(x-c)/d))

For a, the value will likely not change, it stays fixed at 1. b will remain in the meanwhile at 0.2, but I would like to plot all other variants of the function for x in the interval 0, 21 for different values of c and d in different colors (like color lerp).

Like, for all combinations of c,d in [0.2,0.4,0.6,0.8,1.0,1.2]

How to achieve this in sage 5.2 and python? I've tried simply using a python function that returns a "sage function" but it doesn't work.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-09-15 02:32:23 -0500

achrzesz gravatar image

updated 2012-09-15 21:56:14 -0500

f(c,d)= a / (1 + b*e^(-(x-c)/d))  
sum([plot(f(c,d),[x,0,5],color=hue((c+10*d)/3)) for c in srange(0.2,1.3,.2) for d in srange(0.2,1.3,.2)]).show()

#It seems that 36 curves is too many but I hope it can help to experiment

Or using the suggestion by kcrisman

curves=[f(c,d) for c in srange(0.2,1.3,.2) for d in srange(0.2,1.3,.2)]
sum(plot(curves[k],[x,0,5],color=colors[k]) for k in range(l)).show()
edit flag offensive delete link more


The `rainbow(n)` function may also be useful here, depending on what your goal is.

kcrisman gravatar imagekcrisman ( 2012-09-15 16:56:55 -0500 )edit

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: 2012-09-15 00:58:01 -0500

Seen: 289 times

Last updated: Sep 15 '12