I need help on small code
2 次查看(过去 30 天)
显示 更早的评论
My code
function q=perfectbinomial(n,p)
i=0:floor(sqrt(n));
x=i.^2;
q=sum(binomialpmf(n,p,x));
Output supposed to be the below -
>> perfectbinomial(100,0.5)
ans =
0.0811
The message I am getting is -
>> perfectbinomial(100,0.5)
Unrecognized function or variable 'binomialpmf'.
Error in perfectbinomial (line 4)
q=sum(binomialpmf(n,p,x));
回答(1 个)
Image Analyst
2020-2-16
Your binomialpmf() function is not in your current folder or one your search path. Did you mean binomialpdf - perhaps you misspelled your function. Is it a toolbox function? If so, it's not in any toolbox that I've bought.
Did you mean
BinomialDistribution
A BinomialDistribution object consists of parameters, a model description, and sample data for a binomial probability distribution
The binomial distribution models the total number of successes in repeated trials from an infinite population under the following conditions:
- Only two outcomes are possible for each of n trials.
- The probability of success for each trial is constant.
- All trials are independent of each other.
Creation
There are several ways to create a BinomialDistribution probability distribution object.
- Create a distribution with specified parameter values using makedist.
- Fit a distribution to data using fitdist.
- Interactively fit a distribution to data using the Distribution Fitter app.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!