Plot a my own created function

8 Ansichten (letzte 30 Tage)
Matthias Bossenbroek
Matthias Bossenbroek am 17 Mai 2019
Beantwortet: Rik am 17 Mai 2019
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 Kommentare
KSSV
KSSV am 17 Mai 2019
What is Lambda value?
Matthias Bossenbroek
Matthias Bossenbroek am 17 Mai 2019
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Rik
Rik am 17 Mai 2019
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).

Weitere Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by