Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Untitled

Dejene Chala
2023-09-26

library("plotly")

## Warning: package 'plotly' was built under R version 4.3.1

## Loading required package: ggplot2

## Warning: package 'ggplot2' was built under R version 4.3.1

##
## Attaching package: 'plotly'

## The following object is masked from 'package:ggplot2':


##
## last_plot

## The following object is masked from 'package:stats':


##
## filter

## The following object is masked from 'package:graphics':


##
## layout

#1
mu_x=0 #mean of X_1
mu_y=0 #mean of X_2
sigma_xx=1 #variance of X_1
sigma_yy=1 #variance of X_2
sigma_xy=0.7#covariance of X_1 and X_2

#plot
x1 <- seq(mu_x-3, mu_x+3, length= 200)
x2 <- seq(mu_y-3, mu_y+3, length= 200)
z <- function(x1,x2){ z =exp(-(sigma_yy*(x1-mu_x)^2+sigma_xx*(x2-mu_y)^2-2*sigma_xy*(x1-mu_x)*(x2-mu_y))/(2*(sigm
a_xx*sigma_yy-sigma_xy^2)))/(2*pi*sqrt(sigma_xx*sigma_yy-sigma_xy^2)) }
f <- t(outer(x1,x2,z))

plot_ly(x=x1,y=x2,z=f,type = "contour")

0.2

0.1

0
0

−1

−2

−3
−3 −2 −1 0 1 2 3
#2
x1=seq(-3,3,length=200)
x2=seq(-3,3,length=200)
z1=function(x1,x2){
z1=0.4*(exp(-(1*(x1-0)^2+1*(x2-0)^2-2*0.7*(x1-0)*(x2-0))/(2*(1*1-0.7^2)))/(2*pi*sqrt(1*1-(-0.7)^2)))+0.6*(exp(-
(1*(x1-0)^2+1*(x2-0)^2-2*(-0.5)*(x1-0)*(x2-0))/(2*(1*1-(-0.5)^2)))/(2*pi*sqrt(1*1-(-0.5)^2)))
}
f <- t(outer(x1,x2,z1))

plot_ly(x=x1,y=x2,z=f,type = "contour")

0.16

2
0.12

0.08
1

0.04

−1

−2

−3
−3 −2 −1 0 1 2 3

You might also like