Plotting a derivative function given a set of data points

11 visualizaciones (últimos 30 días)
Luisa Venegas
Luisa Venegas el 25 de Jul. de 2020
Respondida: Walter Roberson el 25 de Jul. de 2020
Problem:The growth of populations of organisms has many engineering and scientific applications. One of the simplest models assumes that the rate of change of the population p is proportional to the existing population at any time t: dp/dt=kg*p
Where, kg = the growth rate. The world population in millions from 1950 through 2000 was t=[ ]; p=[ ]; Assuming that the given Equation, use the data from 1950 through 1970, and estimate kg.
Hi so I've been trying to solve this..plotting dp/dt=kg*p given a table with p and t values, but the p vs dp/dt curve isn't showing, (the trouble is with the last part of the code) this is my code:
t=[1950 1955 1960 1965 1970 1975 1980 1985 1990 1995 2000];
p=[2560 2780 3040 3350 3710 4090 4450 4850 5280 5690 6080];
dt=diff(t)
dp=diff(p)
D=dp./dt
n=length(t)
tm=((1:n-1)+t(2:n))./2
m=length(p)
pm=((1:m-1)+p(2:m))./2
figure
hold on
grid on
subplot(1,2,1)
plot(tm,D,'r-o','linewidth',2)
subplot(1,2,2)
plot(p,D,'b-o','linewidth',2)
  2 comentarios
Walter Roberson
Walter Roberson el 25 de Jul. de 2020
You appear to have omitted some of the p values.
Luisa Venegas
Luisa Venegas el 25 de Jul. de 2020
Thanks! modified it.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 25 de Jul. de 2020
Your p is your original p values, length 11. Your D is your estimated gradient values, length 10.
When you plotted time versus D, you found the midpoints of the times and plotted those against the gradient. You could do something similar here.
Alternately, you could use
D = gradient(t, p);
in which case you get back one value for each t value, and do not need to plot at midpoints.

Community Treasure Hunt

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

Start Hunting!

Translated by