I need help on small code

9 Ansichten (letzte 30 Tage)
PATWANT SINGH
PATWANT SINGH am 16 Feb. 2020
Beantwortet: Image Analyst am 16 Feb. 2020
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 Kommentar
darova
darova am 16 Feb. 2020
What is this binomialpmf?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 16 Feb. 2020
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.

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by