Fitting exponential using derivatives

5 ビュー (過去 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 Center および File ExchangeInterpolation についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by