MATLAB Answers

0

Plot a my own created function

Matthias Bossenbroek さんによって質問されました 2019 年 5 月 17 日
最新アクティビティ Rik
さんによって 回答されました 2019 年 5 月 17 日
Hi,
I would like to plot my function over the interval [0,2] however i keep on getting an empty graph.
So far i have used:
fplot(@(Lambda)Steady_State(Lambda))
ylim([0 200])
My function itself has the following code.
Cheers,
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

  2 件のコメント

KSSV
2019 年 5 月 17 日
What is Lambda value?
Matthias Bossenbroek 2019 年 5 月 17 日
i would like to have a graph with lambda on the x-axis and Beta on the y-axis.
And Lambda should run from 0 to 2

サインイン to comment.

1 件の回答

Rik
回答者: Rik
2019 年 5 月 17 日
 採用された回答

Your output is sometimes complex. You should fix this in your function, but you can also apply a quick fix here:
fplot(@(Lambda)abs(Steady_State(Lambda)))
ylim([0 200])
Ideally you should also make your function support vectorized inputs and deal with all the warnings (and suppress outputs by adding semicolons).

  0 件のコメント

サインイン to comment.



Translated by