Project for Faculty (Gaussian distribution and estimation)

I would much appriciate the correct response and the code that works on Matlab R2018a.
I need help generating normally distributed random vector X = [X1, X2]' with independent components that both have expactancy 0 and variances sigma1^2 and sigma2^2 (it is given, like in concrete values, but for the sake of generality to the code I don't need to specify values). Also, there needs to be N = 10^5 of those.
Let me say that I cannot use mvnpdf and those functions that are implemented in matlab, but only randn, rand, histogram, histcount and when it comes to plotting plot, stem, surf.
I have to divide the surface (x1,x2) into 20x20 elementary surfaces and to experimentaly estimate probability density function f^(x1,x2) into dots that are in the centers of these elementar surfaces. I have to also plot this f^.

4 comentarios

Jon
Jon el 16 de Nov. de 2020
This sounds like a homework problem. Once you have tried writing some code if you are still having problems please attach your code and explain what problem you are having with your MATLAB code
The problem I am having is as follows.
This thing below is source code. I have commented on the code. I have emphasised the things I can't use. If somebody knows how to do it I would really appreciate it
clear
close all
clc
%% Generating pdf
% paramaters
m1 = 1; s1 = 0.5;
m2 = 0; s2 = 1;
rho = 0.5;
m = [m1 m2];
sigma = [s1^2 rho*s1*s2; rho*s1*s2 s2^2];
% defining meshgrid for the representation of pdf
x1 = -3:0.2:3;
x2 = -3:0.2:3;
[X1, X2] = meshgrid(x1,x2);
% this in particular I cannot use therego this part must be omitted using somekind of
% very simple examples of randn function
F = mvnpdf([X1(:) X2(:)],m,sigma);
% graphical representation
F = reshape(F,length(x2),length(x1));
surf(x1,x2,F);
xlim([-3 3])
ylim([-3 3])
xlabel('x1'); ylabel('x2'); zlabel('fgv');
view([0 90]) % prikaz 'odozgo'
% view([90 0]) % prikaz po x2 osi
% view([180 0]) % prikaz po x1 osi
%% Generating the instances of random vector
% number of instances
N=1000;
% again I should not use this I have to generate with randn
r = mvnrnd(m,sigma,N);
% graphical representation
figure
plot(r(:,1),r(:,2),'x')
axis([-3 3 -3 3])
xlabel('x1'); ylabel('x2')
@Jon
You might be onto sth.
The "More About" section of the mvnpdf function gives the equation for it.

Iniciar sesión para comentar.

Respuestas (0)

Productos

Versión

R2018a

Preguntada:

el 16 de Nov. de 2020

Comentada:

el 16 de Nov. de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by