Ask Your Question
1

Plotting a Probability distribution with varying parameter

asked 2023-07-07 12:32:51 +0100

vidyarthi gravatar image

updated 2023-07-07 12:35:08 +0100

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

Comments

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

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2023-07-07 15:12:56 +0100 )edit

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

vidyarthi gravatar imagevidyarthi ( 2023-07-08 08:46:30 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-07-07 16:00:00 +0100

slelievre gravatar image

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()
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

1 follower

Stats

Asked: 2023-07-07 12:32:51 +0100

Seen: 210 times

Last updated: Jul 07 '23