- the full copy-pasted error message
- all relevant code that defines the function and it's inputs
MATLAB function help, input arguments errror
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm using matlab, and I'm trying to make a function that gives me the probabilities in a geometric distribution when I enter the values of p, q, and no. of attempts(x) as the inputs.
My function:
function Probability = Geometric(p, q, x)
Probability = p*q^x-1
Now whenever I try to calculate the probability by typing in the values of p, q, and x, such as:
geometric(0.5, 0.5, 1),
it gives me an error about "invalid function for input arguments of type double" sort. Can anyone please help me?
I've tried changing functions, and reducing them to one input and one output.
Please help me someone, and if possible, give me a recommendation on how to make a better function. I thought on making one on the binomial distribution, but it would be difficult to get factorials, and get the probabilities to sum up if I need probabilties for multiple succesess.
9 commentaires
Adam Danz
le 29 Avr 2019
As Steven Lord wrote 30 minuts ago, you're not calling Geometric(); you're calling geometric() which is not the same function. At least that's what you've told us in your question. Maybe it was a typo but we can only work with the info that was given to us.
Réponse acceptée
Adam Danz
le 29 Avr 2019
After saving your function, add it's path to matlab.
Suppose you saved your function in C:\Users\name\Documents\MATLAB\
addpath('C:\Users\name\Documents\MATLAB\')
Then you should have access to your function.
2 commentaires
Adam Danz
le 29 Avr 2019
Modifié(e) : Adam Danz
le 29 Avr 2019
I'd need to look under the hood to speculated. If you want to copy-paste the entire function here I can look at it.
Is this the entire function?
function Probability = Geometric(p, q, x)
Probability = p*q^x-1;
When I run that function, with inputs of [0.5, 0.5, 1], I get an output of -0.75.
Furthermore, when you just type 'Geometric', you should get an error "Not enough input arguments".
Clear your workspace and try again.
Plus de réponses (1)
Steven Lord
le 29 Avr 2019
function Probability = Geometric(p, q, x)
This suggests the name of the function file containing this function is Geometric.m.
geometric(0.5, 0.5, 1),
The function named geometric is not the same as the function named Geometric. Function names in MATLAB are case sensitive.
If changing the case of your call does not resolve the problem, please provide the information Adam Danz requested. Don't paraphrase the error message, copy all the red text directly from the Command Window into the MATLAB Answers comment box.
7 commentaires
Adam Danz
le 29 Avr 2019
I thought you mentioned that it was a nested function earlier but I may have misread your comment. So you have a file named 'Geometric.m' and the file is saved and the function within that file has the same name. In that case, it sounds like you just need to add the path to matlab. I've provided an answer to show you how to do that.
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
