Plot a my own created function

10 visualizaciones (últimos 30 días)
Matthias Bossenbroek
Matthias Bossenbroek el 17 de Mayo de 2019
Respondida: Rik el 17 de Mayo de 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 comentarios
KSSV
KSSV el 17 de Mayo de 2019
What is Lambda value?
Matthias Bossenbroek
Matthias Bossenbroek el 17 de Mayo de 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

Iniciar sesión para comentar.

Respuesta aceptada

Rik
Rik el 17 de Mayo de 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).

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by