# Plotting a Probability distribution with varying parameter

Suppose I wish to plot the function

import numpy as np
var('a,y')
A=np.linspace(-1,1,10)
for a in A:
z=a+x-(e^(-y^2/2))/sqrt((2*pi))
plot3d(z,(x,-1,1),(y,-1,1))


That is, I wish to plot the function z over a range of a. Actually the original function was z=a+x. But, in order to introduce randomization, I changed the variable x to x-y', where y' is the standard normal variable. I wish to obtain the plot of z as a kind of variable probability distribution over the grid of x and y with the variation of a (so kind of series of probability distributions overlapping each other). How do I do this? Any hints? Thanks beforehand.

edit retag close merge delete

What ou aim to do is quite unclear. Could you try to explain it algebrically ?

( 2023-07-07 15:12:56 +0200 )edit

@EmmanuelCharpentier The accepted answer is exactly what I wanted to do.

( 2023-07-08 08:46:30 +0200 )edit

Sort by ยป oldest newest most voted

Each plot3d command produces a graphics object.

Such objects can be added together in Sage.

The following might give the desired output.

import numpy as np

G = Graphics()
x, y = SR.var('x, y')
A = np.linspace(-1, 1, 10)
s = (RDF.pi() * 2).sqrt()

for a in A:
z = a + x - exp(-y^2/2) / s
G += plot3d(z, (x, -1, 1), (y, -1, 1))

G.show()

more