Ask Your Question

# Generating functions and plotting them with different colors

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 close merge delete

## 1 answer

Sort by ยป oldest newest most voted
a=1.
b=0.2
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

a=1.
b=0.2
f(c,d)=a/(1+b*e^(-(x-c)/d))
curves=[f(c,d) for c in srange(0.2,1.3,.2) for d in srange(0.2,1.3,.2)]
l=len(curves)
colors=rainbow(l)
sum(plot(curves[k],[x,0,5],color=colors[k]) for k in range(l)).show()

more

## Comments

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

( 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

## Stats

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

Seen: 236 times

Last updated: Sep 15 '12