I need help on small code

조회 수: 2 (최근 30일)
PATWANT SINGH
PATWANT SINGH 2020년 2월 16일
답변: Image Analyst 2020년 2월 16일
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
darova
darova 2020년 2월 16일
What is this binomialpmf?

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

답변 (1개)

Image Analyst
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.

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by