What's wrong with my distribution function?
Afficher commentaires plus anciens
I'm trying to draw a chi-square distribution in XYZ space. Chi-square distribution in Geogebra is supposed to be (with different index k):

That means, it is supposed to be a central-symmetric, volcano-shaped figure.
Here comes the code:
X = -100 : 1 : 100;
Y = -100 : 1 : 100;
k = 4;
G = gamma(k/2);
[ XX, YY ] = meshgrid( X, Y );
A = ( XX ).^2 + ( YY ).^2;
A = sqrt (A);
Z = (A^(k/2 - 1) * exp(-A / 2)) / ( 2^(k/2) * G );
figure, mesh(X, Y, Z);
Very unfortunately, the figure I generated is:

What exactly is wrong with my code?
1 commentaire
Shing Ho Lin
le 21 Mai 2022
Réponses (1)
X = -100 : 1 : 100;
Y = -100 : 1 : 100;
k = 4;
G = gamma(k/2)
[ XX, YY ] = meshgrid( X, Y );
A = ( XX ).^2 + ( YY ).^2;
A = sqrt (A);
Z = (A.^(k/2-1).*exp(-A / 2))./(2^(k/2)* G); % use element wise operator
mesh(X, Y, Z);
axis([-20 20 -100 100 0 0.2])
3 commentaires
VBBV
le 21 Mai 2022
use element wise operator .* in the expression
Shing Ho Lin
le 21 Mai 2022
VBBV
le 21 Mai 2022
Thanks is accpeting answer, :) ,
Catégories
En savoir plus sur Exploration and Visualization dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
