How to obtain the derivative analytically of a complicated function and evaluate it at 0
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi all,
I am new to the symbolic math toolbox. I am trying to differentiate a function and evaluate it at 0 (stable equilibrium). I got some sort of derivative from diff function, but if I try to evaluate at 0,I get NaN. I wish to do stability analysis around the equilibrium at 0. It is a discrete time model of a population. What I think I should do is to take the derivative with respect to F (the state variable, population density) and evaluate it at F = 0. And see if this derivative evaluated at 0 is less than 1, which indicates that the equilibrium is stable. I wish to derive an expression for the threshold value of D beyond which the extinction equilibrium is stable.
F(t) = (1-s0)*a*(1-exp(-r*F(t-1)/N))*N*(1-D)*(1-D/(D+s0*(a*(1-exp(-r*F(t-1)/N))*N/F(t-1))))
a = 0.62, r = 26, s0 = 0.5, N = 1.
This is what I did in Matlab
syms s0 a r F N D b
fun = @(s0,D,a,r,F,N) (1-s0)*a*(1-exp(-r*F/N))*N*(1-D)*(1-D/(D+s0*(a*(1-exp(-r*F/N))*N/F)))
diff(fun,F)
ans = - a*r*exp(-(F*r)/N)*(D - 1)*(D/(D - (N*a*s0*(exp(-(F*r)/N) - 1))/F) - 1)*(s0 - 1) - (D*N*a*((a*r*s0*exp(-(F*r)/N))/F + (N*a*s0*(exp(-(F*r)/N) - 1))/F^2)*(exp(-(F*r)/N) - 1)*(D - 1)*(s0 - 1))/(D - (N*a*s0*(exp(-(F*r)/N) - 1))/F)^2
myfun =@(s0,D,a,r,F,N) - a*r*exp(-(F*r)/N)*(D - 1)*(D/(D - (N*a*s0*(exp(-(F*r)/N) - 1))/F) - 1)*(s0 - 1) - (D*N*a*((a*r*s0*exp(-(F*r)/N))/F + (N*a*s0*(exp(-(F*r)/N) - 1))/F^2)*(exp(-(F*r)/N) - 1)*(D - 1)*(s0 - 1))/(D - (N*a*s0*(exp(-(F*r)/N) - 1))/F)^2 - 1
F_ = 0; N_ = 1; s0_ = 0.5; a_ = 0.62; r_ = 26;
myfun2 = @(D) myfun(s0_,D,a_,r_,F_,N_)
D = fzero(myfun2,0.8)
Then I got
Error using fzero (line 307)
Function value at starting guess must be finite and real.
Thank you very much for your help in advance!!
Etsuko
0 Kommentare
Antworten (1)
Mahesh Pai
am 29 Mär. 2017
It is my understanding that you are receiving an error when you are trying to execute the above script. You are receiving the error because you are substituting "F" as "0" in "myfun", and "myfun" has expressions that are divided by "F" which leads to an infinite value upon evaluation. Upon changing "F" to a very small value (close to zero) you will not receive this error.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!