Fitting exponential using derivatives

조회 수: 7 (최근 30일)
CherryLady
CherryLady 2025년 5월 14일
댓글: Sam Chak 2025년 5월 15일
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
Walter Roberson
Walter Roberson 2025년 5월 14일
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?
Sam Chak
Sam Chak 2025년 5월 15일
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])

댓글을 달려면 로그인하십시오.

답변 (2개)

Matt J
Matt J 2025년 5월 14일
편집: Matt J 2025년 5월 14일
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 2025년 5월 15일
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.

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by