Fitting exponential using derivatives

Hello everyone!
I have a question regarding fitting data. I have an example data set
time=linspace(0,200,20);
r=linspace(0,1,20);
where r is a function of time.
And i have to fit the data set to the model equation
y=a*1.5^(c+d)*(5-r)^c*(3-r)^d
however, i do not have the y values, so I have no idea how to solve it.
I started with calculating derivatives and then linearizing it with logarithms
dt = diff(time);
dr = diff(r);
dr_dt = dr ./ dt;
ln(dr_dt) = ln(a) + (c+d)*ln(1.5) + c*ln(5−r) + d*ln(3−r)
However, I have no how to calculate a, c and d values. Any ideas?

7 commentaires

Walter Roberson
Walter Roberson le 14 Mai 2025
where t is a function of x.
Before and after that statement, you never refer to x or t again, so it is difficult to understand the relevance of that statement.
Walter Roberson
Walter Roberson le 14 Mai 2025
What exactly do you have? You have time, and what else?
CherryLady
CherryLady le 14 Mai 2025
Yes, you are right, I have changed the notation already, thanks!
CherryLady
CherryLady le 14 Mai 2025
r is the concentration of a reagent, y would be reaction kinetic expression
Matt J
Matt J le 14 Mai 2025
Modifié(e) : Matt J le 14 Mai 2025
ln(dr_dt) = ln(a) + (c+d)*ln(1.5) + c*ln(5−r) + d*ln(3−r)
This only follows mathematically if y=dr_dt, which you haven't expressly mentioned.
Walter Roberson
Walter Roberson le 14 Mai 2025
y would be reaction kinetic expression
But you do not have measured reaction kinetic expressions values ? What do you have measured? You have measured time; you have implied r values based on time... what else?
Actually, I'm scared of seeing the power operator in differential equations. If one is not careful, improper computations can yield complex values. Even for attentive individuals, if the exponent parameters 'c' or 'd' are not integers but floating-point numbers, a negative real base can also produce complex values.
I also noticed that you intend to perform numerical differentiation using the operation diff(r)./diff(t) and then attempt to fit the model to the ​ data. Please note that there may be a discrepancy between the analytical and numerical results at high slopes.
You can also use this toy problem to test whether you can estimate the parameters using the fit() or lsqcurvefit() commands.
%% differential equation with "unknown" parameters
a = 1; % parameter 1
c = 2; % parameter 2
d = 3; % parameter 3
dr = @(t, r) a*1.5^(c + d)*(5 - r).^c.*(3 - r).^d;
%% artificially generate data (about 50 points)
numpts = 50;
tspan = linspace(0, 10, numpts+1);
r0 = 4; % initial value
[t, r] = ode45(dr, tspan, r0);
%% create finer sampling points via Akima-styled interpolation
tq = linspace(0, 10, 10*numpts+1); % 10 times finer
rq = interp1(t, r, tq, 'makima');
%% compare actual data and interpolated data
figure
plot(t, r, ':o', tq, rq), grid on
legend('Actual data', 'Interpolated data')
xlabel('t'), ylabel('r(t)')
%% perform numerical differentiation
drq = gradient(rq)./gradient(tq);
figure
hold on
plot(t, dr(t, r), ':o')
plot(tq, drq), grid on
hold off
legend('analytical dr', 'numerical dr', 'location', 'east')
xlabel('t'), ylabel('dr(t)')
axis([-2, 10, -8, 1])

Connectez-vous pour commenter.

Réponses (2)

Matt J
Matt J le 14 Mai 2025
Modifié(e) : Matt J le 14 Mai 2025
however, i do not have the y values
If y=dr_dt, then you can approximate y numerically,
y=gradient(r,t)
However, it be advisable to instead fit r(t) with a smoothing spline, and differentiate it analytically, e.g., with fnder.
Torsten
Torsten le 15 Mai 2025

0 votes

As far as I understand, your model is a differential equation
dr/dt = a*1.5^(c+d)*(5-r)^c*(3-r)^d, r(0) = r0
with unknown parameters a, c and d.
Further, you have measurements for r over time: (t0,r0),(t1,r1),...,(tn,rn).
In order to determine a, c and d, you will have to couple a parameter fitting tool (e.g. lsqcurvefit) with an integrator for ordinary differential equations (e.g. ode15s).
Take a look at the example
and StarStrider's answer code to learn how to proceed.

Catégories

Produits

Version

R2023b

Commenté :

le 15 Mai 2025

Community Treasure Hunt

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

Start Hunting!

Translated by