Problem Lotka Volterra Model – Modelling & Plotting in Python

I urgently need your help. Currently I’m conducting a research in regards of the revenue calculation and the dynamics within revenue calculation for my masters. I thought of revenue/profit margin as of a dynamical system – Lotka Volterra differential equations. I thought of a contribution margin calculation as within this simple formula:

https://www.accountingformanagement.org/wp-content/uploads/2012/07/contribution-margin-ratio-img4.png

In consequence my idea was the following, but I receive an error:
enter image description here

enter image description here

enter image description here

  • Can anyone help me?
  • Do you think it’s a bad idea to use Lotka Volterra equations for this nonlinear purpose of Sales/Cost/Margin Simulation?
  • How would you model it and why? Am I missing equations or does the simple system already fit the requirements?
  • How do I generate a valid plot out of these results (Phase Portrait etc.)?

Plotting a well defined function displays nothing for two-thirds of the range required

The plot in question concerns the second derivative of an inverse Laplace transform (ILT) of a function with five parameters. Here is the ILT

ClearAll["Global`*"] prod = (s - cr1) (s - cr2) (s - cr3) (s - cr4); LW = (1 + s)^2/(si prod); Print["symbolic W'=", Wp = D[InverseLaplaceTransform[LW, s, x], x]] 

Four parameters are functions of the fifth parameter "si", defined as the roots of a fourth order equation

cr = {cr1, cr2, cr3, cr4} =     s /. Solve[si s^2 + 107 s/5 + 10 ((1 + s)^(-2) - 1) - 1/10 == 0,       s]; 

Plotting the first derivative of the ILT takes .64

lx = 13; Timing[  pd = Plot[Evaluate[Wp /. si -> 1], {x, 0, lx},     PlotRange -> {{0, lx}, {0.0225, .0275}}]] 

Plotting of the second derivative of the ILT takes 14.84 and displays nothing for two-thirds of the range lx

    Wd = D[Wp, x]; Timing[Plot[(Wd /. si -> 1), {x, 0, lx},   PlotRange -> {{0, lx}, {-0.002, .002}}]] 

Recursively plotting specific elements in a list of lists

I am trying to build band structures and am looking to generate a general code that will work regardless of my list size. Here is what I am trying to do: say I have a list like

list = {{0.0, 1, 2, 3}, {0.1, 4, 5, 6}, {0.2, 7, 8, 9}, {0.3, 10, 11, 12}}; 

and I want to plot the nth element of each list against the first element of each list. How can I tell Mathematica to automatically produce a set of lists to plot like shown below

k = {0.0, 0.1, 0.2, 0.3}; band1 = {1, 4, 7, 10}; band2 = {2, 5, 8, 11}; band3 = {3, 6, 9, 12}; Show[ListLinePlot[k, band1], ListLinePlot[k, band2], ListLinePlot[k, band3]] 

Doing it manually one band at a time is possible but a waste of time when I have n=36+ bands. Any help would be much appreciated!

Plotting data from a list of rules, infer axis titles from the rules with units

I have data, with units, organized as a list of rules; this is so I can slice the data in different ways based on the variables represented.

I’m trying to find the most direct way to plot this and get axis titles with both the variable from the rule and unit from the values. I don’t want to manually label the plots each time, so if Plot doesn’t have a built-in then how can I write a function to do the inference? I’m looking for the most DRY approach possible.

This gives me the units, but not the variable names, in the labels:

data = {    y -> {0, 33.2} (Quantity[1, ("KipsForce")/("Inches")^2]),    x -> {0, 6} 10^-4    }; ListLinePlot[Transpose@({x, y} /. data), AxesLabel -> Automatic] 

On the same example, is it possible to retain units like "in/in"? I’ve done this by manually specifying the labels and using HoldForm to avoid evaluating the cancellation, but I can’t get that to work with automatic labels as above.

Plotting surfaces in 4D

So I am new to Mathematica and I will probably express myself badly, please let me know if I should specify the problem better.

I have the following constraints over the list {a,b,c,d}:

a=f[c,d] b=g[c,d] 

So that effectively I have {f[c,d],g[c,d],c,d} and I would like to plot this in a 3D+Color graph, with possibly one of the functions as color. I tried various combinations of Table and ListDensityPlot3D but I wasn’t able to reach anything (apart from a sparsely colored cube).

Moreover, I have a second surface {f2[c,d], g2[c,d],c,d}, is it possible to plot the two together and possibly find intersection points?

Thanks for the help.

Why are these two histograms plotting so differently?

I have two lists, which are pretty similar. They are given by:

list1=Flatten[Table[#[[1]], #[[2]]] & /@ {{1, 2},{2, 9},{3, 3},{4,73},{5, 38}}] list2=Flatten[Table[#[[1]], #[[2]]] & /@ {{1, 2},{2, 10},{3, 8},{4,65},{5, 22}}] 

ie. list1 is a list of 2 1’s, 9 2’s, 3 3’s, etc.

If I plot a histogram of them next to each other they come out like this:

{Histogram[list1],Histogram[list2]} 

enter image description here

And I can’t figure out why the labelling is different. I would like to have all of my numbers in the centre of the column, so tried using the answer from this question. as so:

{Histogram[list1,    Ticks -> {{# + .5, #} & /@ HistogramList[list1][[1]], Automatic}],   Histogram[list2,    Ticks -> {{# + .5, #} & /@ HistogramList[list2][[1]], Automatic}]} 

But that comes out like this:

enter image description here

Any idea what’s going on?

Problem plotting expression involving Generalized hypergeometric functions $_2F_2 \left(.,.,. \right)$

I’m trying to plot a graph for the following expectation

$ $ \mathbb{E}\left[ a \mathcal{Q} \left( \sqrt{b } \gamma \right) \right]=a 2^{-\frac{\kappa }{2}-1} b^{-\frac{\kappa }{2}} \theta ^{-\kappa } \left(\frac{\, _2F_2\left(\frac{\kappa }{2}+\frac{1}{2},\frac{\kappa }{2};\frac{1}{2},\frac{\kappa }{2}+1;\frac{1}{2 b \theta ^2}\right)}{\Gamma \left(\frac{\kappa }{2}+1\right)}-\frac{\kappa \, _2F_2\left(\frac{\kappa }{2}+\frac{1}{2},\frac{\kappa }{2}+1;\frac{3}{2},\frac{\kappa }{2}+\frac{3}{2};\frac{1}{2 b \theta ^2}\right)}{\sqrt{2} \sqrt{b} \theta \Gamma \left(\frac{\kappa +3}{2}\right)}\right)$ $ where $ a$ and $ b$ are constant values, $ \mathcal{Q}$ is the Gaussian Q-function, which is defined as $ \mathcal{Q}(x) = \frac{1}{\sqrt{2 \pi}}\int_{x}^{\infty} e^{-u^2/2}du$ and $ \gamma$ is a random variable with Gamma distribition, i.e., $ f_{\gamma}(y) \sim \frac{1}{\Gamma(\kappa)\theta^{\kappa}} y^{\kappa-1} e^{-y/\theta} $ with $ \kappa > 0$ and $ \theta > 0$ .

This equation was also found with Mathematica, so it seems to be correct. I’ve got the same plotting issue with Matlab.

Follows some examples, where I have checked the analytical results against the simulated ones.

When $ \kappa = 12.85$ , $ \theta = 0.533397$ , $ a=3$ and $ b = 1/5$ it returns the correct value $ 0.0218116$ .

When $ \kappa = 12.85$ , $ \theta = 0.475391$ , $ a=3$ and $ b = 1/5$ it returns the correct value $ 0.0408816$ .

When $ \kappa = 12.85$ , $ \theta = 0.423692$ , $ a=3$ and $ b = 1/5$ it returns the value $ -1.49831$ , which is negative. However, the correct result should be a value around $ 0.0585$ .

When $ \kappa = 12.85$ , $ \theta = 0.336551$ , $ a=3$ and $ b = 1/5$ it returns the value $ 630902$ . However, the correct result should be a value around $ 0.1277$ .

Therefore, the issue happens as $ \theta$ decreases. For values of $ \theta > 0.423692$ the analytical matches the simulated results. The issue only happens when $ \theta <= 0.423692$ .

I’d like to know if that is an accuracy issue or if I’m missing something here and if there is a way to correctly plot a graph that matches the simulation. Perhaps there is another way to derive the above equation with other functions or there might be a way to simplify it and get more accurate results.

Plotting the Eigenvectors with respect to a parameter

I have a matrix of the form given below with a parameter $ \lambda$ . I would like to plot the quantity <$ \phi_{i}|Q|\phi_{i}>$ for the every Eigenvectors corresponding to ascending order in Eigenvalues of this matrix with respect $ \lambda$ . I am bit trouble to sort the eigenvectors and plot it w.r.t $ \lambda$ . Pl somebody help me to get that. Here {$ \lambda$ ,0,1.0,0.01}. Here $ |\phi_{i}>$ are the eigen vector of the matrix M.

M[\[Lambda]_] =  { {1, 1 + \[Lambda], -2, 5, \[Lambda], 0}, {0, Sqrt[\[Lambda]] + 3, 6, 7, 0, -3}, {1, 4, 6, \[Lambda] + 2, 0, 1}, {0.6, \[Lambda], 6, 4, 8, 0.5}, {Sqrt[2], 3, 11, Sqrt[\[Lambda] + 4], 0, 1}, {4, 0, \[Lambda], 6, 5, 2}} 

Plotting 2 functions at the same time with Manipulate[]

Here is a code that works well:

f1[x_] := Sqrt[25 - x^2] Manipulate[  Plot[f1[x], {x, from, to}, AspectRatio -> Automatic,    PlotRange -> {{-20, 20}, {-20, 20}},    Epilog -> {Text["From y: " <> ToString[f[from]],       Scaled[{1, 1}], {1, 1}],      Text["To y: " <> ToString[f[to]],       Scaled[{1, 0.96}], {1, 1}]}], {{from, -10, "from x"}, -10, 10,    Appearance -> "Labeled"}, {{to, 10, "to x"}, -10, 10,    Appearance -> "Labeled"}] 

output like:

enter image description here

Now I want to plot 2 functions at the same time. I tryied something like this:

f1[x1_] := Sqrt[25 - x1^2] f2[x2_] := -Sqrt[25 - x2^2] Manipulate[  Plot[{f1[x1_], f2[x2_]}, {x1, from1, to1}, {x2, from2, to2},    AspectRatio -> Automatic, PlotRange -> {{-20, 20}, {-20, 20}},   Epilog -> {Text["From y1: " <> ToString[f[from1]],       Scaled[{1, 1}], {1, 1}],      Text["To y1: " <> ToString[f[to1]], Scaled[{1, 0.96}], {1, 1}]},   Epilog -> {Text["From y2: " <> ToString[f[from2]],       Scaled[{1, 1}], {1, 1}],      Text["To y2: " <> ToString[f[to2]], Scaled[{1, 0.96}], {1, 1}]}],  {{from1, -10, "from1 x"}, -10, 10,    Appearance -> "Labeled"}, {{to1, 10, "to x"}, -10, 10,    Appearance -> "Labeled"},   {{from2, -10, "from2 x"}, -10, 10,    Appearance -> "Labeled"}, {{to2, 10, "to2 x"}, -10, 10,    Appearance -> "Labeled"}] 

But it does not plots anything. How to correct my code above?