# Finding the difference in growth rate between graphs

3 views (last 30 days)
Aravind S on 6 Jun 2022
Edited: Jon on 17 Jun 2022
I have two set of graphs as follows:
x=[6,12,24,48,72,96];
control_vals=[126,363,672,1014,1358,1526];
test_vals=[83,43,112,412,714,826];
plot(x,control_vals,'*-','Color','k')
hold on
plot(x,test_vals,'o-','Color','r');title('G1')
ylim([0 2000]);hold off
control_vals2=[101,151,338,892,1142,1341];
test_vals2=[73,176,425,769,1021,1288];
figure;plot(x,control_vals2,'*-','Color','k')
hold on
plot(x,test_vals2,'o-','Color','m');title('G2')
ylim([0 2000]);hold off
I need to find out if the rate of growth is same between G1 control vs G2 control and G1 test vs G2 test.
I have tried out using curve fitting to approximate the above curve and using derivatives to find the answer but I'm getting some errors.
% For G1 Test (Red Curve in G1)
% Eq: y = - 0.003056992404*x^{3} + 0.4690737455*x^{2} - 9.431674809*x +
% 110.8789328 - Obtained using Interactive Fitting in MATLAB
p=[- 0.003056992404 0.4690737455 -9.431674809 110.8789328];
q = polyder(p)
q = 1×3
-0.0092 0.9381 -9.4317
tspan=[0 100];
y0=0;
[t,y]=ode45(@(t,y) (-0.0092*t^2+0.9381*t-9.4317),tspan,y0);
figure;plot(t,y);title('G1 Test- Differentiation')
% For G2 Test (Magenta Curve in G2)
% Eq: y = 0.000966*x^{3} - 0.2096*x^{2} + 25.49*x - 83.89 - Obtained using Interactive Fitting in MATLAB
p1=[0.000966 -0.2096 25.49 -83.89]
p1 = 1×4
0.0010 -0.2096 25.4900 -83.8900
q1=polyder(p1)
q1 = 1×3
0.0029 -0.4192 25.4900
[t,y]=ode45(@(t,y) (0.0029*t^2-0.4192*t+25.49),tspan,y0);
figure;plot(t,y);title('G2 Test- Differentiation')
Can someone guide me on the right method to find the difference in growth rate between these curves?
Aravind S on 15 Jun 2022
@Jon I don't specifically get any error message in MATLAB. By error I meant the graphs which I'm getting as output seems to be incorrect theoretically or I'm not sure how to interpret the results I'm getting.
If you please guide me on how to approach the problem furthur it would be of great help as I'm out of ideas.

Jon on 15 Jun 2022
I'm assuming you want to characterize the growth rates, by the instantaneous rate of change of your control and test values. By definition, the instantaneous rate of change is the first derivative of the function.
If this is what you want then one approach is to fit your data with a smooth curve, for example a polynomial, and then analytically differentiate the resulting polynomials to get the derivatives. The code below illustrates how you could do this.
I'm not understanding why you were using ode45, which is a differential equation solver, but maybe I am missing something about what you were trying to do.
% Parameters
numExp = 2; % number of experiments
polyOrder = 3; % order of polynomial used to fit data
% Assign test and control values for the two tests
x=[6,12,24,48,72,96];
control_vals=[126,363,672,1014,1358,1526];
test_vals=[83,43,112,412,714,826];
control_vals2=[101,151,338,892,1142,1341];
test_vals2=[73,176,425,769,1021,1288];
% Combine data into matrices so we can just loop and not cut and paste code
% (cutting and pasting is bad because if you have an error in one place you
% have to remember to fix it in all the places you pasted to.)
Control = [control_vals;control_vals2]; % rows are experiments G1,G2
Test = [test_vals;test_vals2];
% Fit the data with polynomials and differntiate them
% preallocate arrays to hold polynomial coefficients
Pcntrl = zeros(numExp,polyOrder+1);
Ptest = zeros(numExp,polyOrder+1);
Dcntrl = zeros(numExp,polyOrder);
Dtest = zeros(numExp,polyOrder);
% loop through experiments
for k = 1:numExp
% fit
Pcntrl(k,:) = polyfit(x,Control(k,:),polyOrder);
Ptest(k,:) = polyfit(x,Test(k,:),polyOrder);
% differentiate
Dcntrl(k,:) = polyder(Pcntrl(k,:));
Dtest(k,:) = polyder(Ptest(k,:));
end
% Visualize the curve fits to make sure they look OK
xfit = linspace(x(1),x(end),1000); % x values for fitted data
for k = 1:numExp
figure
plot(x,Control(k,:),'ok',xfit,polyval(Pcntrl(k,:),xfit),'-k',...
x,Test(k,:),'*r',xfit,polyval(Ptest(k,:),xfit),'-r')
legend('Control','Control Fit','Test','Test Fit','Location','northwest')
title("G" + string(k))
end
% Compare test and control rates of change (derivatives) for both experiments
for k = 1:numExp
figure
plot(xfit,polyval(Dcntrl(k,:),xfit),'-k',...
xfit,polyval(Dtest(k,:),xfit),'-r')
legend('Control','Test')
title("Rate of Change G" + string(k))
end
##### 2 CommentsShowHide 1 older comment
Jon on 17 Jun 2022
Edited: Jon on 17 Jun 2022
How you want to analyze the data really requires an understanding of the system you are studying and what is important for your specific situation. I suggest that you talk to your colleagues, mentors, advisors, somebody that is familiar with the type of study you are doing and has experience to advise you.
Once you can express what it is you want to calculate, people on MATLAB answers can help you with your problems transforming those mathematical ideas into code.

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by