What's wrong with my distribution function?

조회 수: 1 (최근 30일)
Shing Ho Lin
Shing Ho Lin 2022년 5월 21일
댓글: VBBV 2022년 5월 21일
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
Shing Ho Lin
Shing Ho Lin 2022년 5월 21일
It is most probably a silly question, but I just get stuck into this. Very much appreciated for any possible answer:)

댓글을 달려면 로그인하십시오.

답변 (1개)

VBBV
VBBV 2022년 5월 21일
X = -100 : 1 : 100;
Y = -100 : 1 : 100;
k = 4;
G = gamma(k/2)
G = 1
[ 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
Shing Ho Lin
Shing Ho Lin 2022년 5월 21일
Thank you so much. Apparently I was way to idiot :(
VBBV
VBBV 2022년 5월 21일
Thanks is accpeting answer, :) ,

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by