I have this function in python and i need it in Matlab Could someone please help??
Mostrar comentarios más antiguos
d e f Mu_n ( Mu ,n ,N ,M) :
i f ( n< = N ) :
mu_n = n∗Mu
e l s e :
mu_n = N∗Mu
r e t u r n mu_n
d e f P0 ( Lambda , Mu , N , M) :
. . .
p = . . .
r e t u r n p
d e f Pn ( Lambda , Mu , N , M, n ) :
. . .
p = . . .
r e t u r n p
d e f r e j e c t i o n ( Lambda , Mu , N , M) :
p = Pn ( Lambda , Mu , N , M, N + M)
r e t u r n p
Respuestas (1)
Steven Lord
el 3 de Dic. de 2018
These seem like pretty simple functions to write. If after reading that documentation page to which I linked you're still having difficulty, show us what you've tried and explain where you're having difficulty and we may be able to offer some guidance.
Since the version of your code with spaces between e a c h l e t t e r is difficult to read, here's a version without spaces.
def Mu_n(Mu,n,N,M):
if(n<=N):
mu_n=n∗Mu
else:
mu_n=N∗Mu
return mu_n
def P0(Lambda,Mu,N,M):
...
p=...
return p
def Pn(Lambda,Mu,N,M,n):
...
p=...
return p
def rejection(Lambda,Mu,N,M):
p=Pn(Lambda,Mu,N,M,N+M)
return p
2 comentarios
CamMiller
el 3 de Dic. de 2018
Steven Lord
el 3 de Dic. de 2018
Let's see if your function satisfy the requirements given in the Syntax for Function Definition section on the documentation page to which I linked in my first response.
- Your functions each have the function keyword as required.
- Your function each have an output argument. Output arguments aren't required, but you've specified them before the equals sign correctly. However, you have not created the variable each function should return inside that function. In your first function, you need to either return mu_n as the output argument or define the variable Mu_n inside the function. [Case matters.]
- Your functions each have multiple input arguments. Input arguments aren't required either, but you've specified them correctly.
- Your functions do not have function names as required, so they are not valid functions.That's why Code Analyzer is complaining.
Use the first block of code on that documentation page as a model for how to write your own functions. The name of that function is fact. Give your functions names like that.
I'm guessing you're new to MATLAB. If that's the case, I recommend going through the free MATLAB Online tutorial on this page which will teach you the basics of how to work with MATLAB including (I believe) how to write functions.
Categorías
Más información sobre Call Python from MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
