Solving derivative in point takes to long

1 view (last 30 days)
Edlan Ih
Edlan Ih on 20 May 2019
Answered: Walter Roberson on 20 May 2019
Hi,
I have complex function which includes diagonalization on which i want to compute the derivative.
However if i try this using inline(diff()) command it gets stuck on busy. But if i try this on a simple function (x^2) it works.
How can i make i work for my complex function?
my derivative:
syms Lambda
derivitive = inline(diff(Steady_State(Lambda), Lambda),'Lambda')
derivitive(0.23)
my complex function:
function Beta = Steady_State(Lambda)
P0 = exp(-Lambda)
P1 = Lambda*exp(-Lambda)
P2 = (Lambda^(2)*exp(-Lambda)/2)
P3 = (Lambda^(3)*exp(-Lambda)/6)
b_NN = [100; 85; 75; 65; 55; 50; 45; 40; 35; 33; 31; 29; 27; 25; 23; 21.5; 20; 18.5; 17; 16; 15]
bonusmalus_NN = [1-P0,P0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,;
1-P0,0,P0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;
1-P0,0,0,P0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;
1-P0,0,0,0,P0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;
1-P0,0,0,0,0,P0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;
1-P0,0,0,0,0,0,P0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;
1-P0-P1,P1,0,0,0,0,0,P0,0,0,0,0,0,0,0,0,0,0,0,0,0;
1-P0-P1,0,P1,0,0,0,0,0,P0,0,0,0,0,0,0,0,0,0,0,0,0;
1-P0-P1,0,0,P1,0,0,0,0,0,P0,0,0,0,0,0,0,0,0,0,0,0;
1-P0-P1,0,0,0,P1,0,0,0,0,0,P0,0,0,0,0,0,0,0,0,0,0;
1-P0-P1,0,0,0,0,P1,0,0,0,0,0,P0,0,0,0,0,0,0,0,0,0;
1-P0-P1-P2,P2,0,0,0,0,P1,0,0,0,0,0,P0,0,0,0,0,0,0,0,0;
1-P0-P1-P2,0,P2,0,0,0,0,P1,0,0,0,0,0,P0,0,0,0,0,0,0,0;
1-P0-P1-P2,0,0,P2,0,0,0,0,P1,0,0,0,0,0,P0,0,0,0,0,0,0;
1-P0-P1-P2,0,0,0,P2,0,0,0,0,P1,0,0,0,0,0,P0,0,0,0,0,0;
1-P0-P1-P2,0,0,0,0,P2,0,0,0,0,P1,0,0,0,0,0,P0,0,0,0,0;
1-P0-P1-P2-P3,P3,0,0,0,0,P2,0,0,0,0,P1,0,0,0,0,0,P0,0,0,0;
1-P0-P1-P2-P3,0,P3,0,0,0,0,P2,0,0,0,0,P1,0,0,0,0,0,P0,0,0;
1-P0-P1-P2-P3,0,0,P3,0,0,0,0,P2,0,0,0,0,P1,0,0,0,0,0,P0,0;
1-P0-P1-P2-P3,0,0,0,P3,0,0,0,0,P2,0,0,0,0,P1,0,0,0,0,0,P0;
1-P0-P1-P2-P3,0,0,0,0,P3,0,0,0,0,P2,0,0,0,0,P1,0,0,0,0,P0]
[V,A] = eig(bonusmalus_NN)
V_inv = inv(V)
p_lim = V*A^10000000*V_inv
p_lim = p_lim(1,:)
Beta = p_lim * b_NN
end
Can someone help me out?
Kind Regards
Edlan
  1 Comment
Walter Roberson
Walter Roberson on 20 May 2019
Is it correct that you are using MATLAB 5.2 or earlier, with the Maple based Symbolic Toolbox? That is only reason that I can think of to try to use inline() with symbolic expressions.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 20 May 2019
The language used by the symbolic toolbox has never been compatible with execution by taking the character version of a symbolic expression and executing it as matlab code. What you are doing has always had undefined results.
You should be using matlabFunction instead of inline.
Unless you are using MATLAB 5.2 or earlier you should stop using inline except as a novelty.

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!