How do I change my scalars to fit my normpdf?
1 回表示 (過去 30 日間)
古いコメントを表示
Here's my code (I am not using the normpdf function because the problem specifically asks to write out the whole equation to get the answer)
e = 2.7183;
xq = 0:100;
mu = [25, 50];
sigma = [5, 10];
figure(3)
for ii2 = 1:length(xq)
ndist=(1/(sigma*sqrt(2*pi)))*power(e,-(1/2)*(power(xq-mu)/sigma),2)
subplot (2,1,ii2)
bar(ndist)
end
2 件のコメント
Torsten
2024 年 9 月 9 日
Please explain what you are trying to do. I can't deduce it from your errorneous code.
採用された回答
Torsten
2024 年 9 月 9 日
編集済み: Torsten
2024 年 9 月 9 日
xq = 0:100;
mu = [25, 50].';
sigma = [5, 10].';
ndist = 1./(sigma*sqrt(2*pi)).*exp(-((xq-mu)./sigma).^2);
plot(xq,ndist)
grid on
2 件のコメント
Torsten
2024 年 9 月 9 日
編集済み: Torsten
2024 年 9 月 9 日
Note that "mu" and "sigma" are column vectors and "xq" is a row vector.
Thus "pdist" will come out as a matrix:
xq = [1 2 3];
mu = [3 4].';
sigma = [2 9].';
(xq - mu)./sigma
This is already "advanced" MATLAB. Alternatively, you should try to produce "pdist" using a loop.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Introduction to Installation and Licensing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!