How to fit an integral with data points in Matlab, where the integration limit can vary

How to fit an integral with data points in Matlab, where the integration limit can vary
By varying the integration limit how do I fit some data points in Matlab?

5 Commenti

Can you show the mathematical formulation of your model?
P = P0 + 4RC(T/C)^5 integration (0, (C/T)) (x^5/(exp(x)-1)*(1-exp(-x))) dx
P0, R and C are constants
You are given the values of P and T, and you want to find these constants?
My problem is also similar to this fitting so please help.
I want to fit experimental data with equation:
y = C(1) * 74.826 * (x/T(1))^3 * integration (t^4*exp(t)/(exp(t)-1)^2), 0, T(1)/x) + C(2) * 24.942 * (T(2)/x)^2 * exp(T(2)/x)/(exp(T(2)/x)-1)^2 + C(3) * 24.942 * (T(3)/x)^2 * *exp(T(3)/x)/(exp(T(3)/x)-1)^2
with six unknown parameters: C(1), T(1), C(2), T(2), C(3), T(3).
I have data in x and y and want to find these unknown parameters by fitting.
Thank you

Accedi per commentare.

 Risposta accettata

If I want to add an extra term in the above expression (like -AT^3, where A constant) so the code would be like this or different. can u confirm me?
Tv = linspace(200, 300, 10).'; % vector of T values
Pv = Tv.^2; % vector of P values
P_mdl = @(P0, R, C, A, TT) arrayfun(@(T) P0 - A.*T.^3 + 4*R.*C.*(T/C).^5 * integral(@(x) x.^5./(exp(x)-1).*(1-exp(-x)), 0, (C/T)), TT);
sol = lsqcurvefit(@(param, T) P_mdl(param(1), param(2), param(3), param(4), T), rand(4,1), Tv, Pv);
P0_sol = sol(1);
R_sol = sol(2);
C_sol = sol(3);
A_sol = sol(4);

3 Commenti

One additional information I want to know, in case of my experimantal data I can not fit the integration properly. So how do I deal with the rand(m,n) things. I mean is there any way to choose the initial value to fit the equation with the experimental data ?
Do you have a general guess about the value of each parameter. If yes, use that as the initial point. Something like this
x0 = [P0_guess, R_guess, C_guess, A_guess]
sol = lsqcurvefit(@(param, T) P_mdl(param(1), param(2), param(3), param(4), T), x0, Tv, Pv);

Accedi per commentare.

Più risposte (1)

One method is to use lsqcurvefit() from Optimization toolbox
Tv = rand(10, 1); % vector of T values
Pv = rand(10, 1); % vector of P values
P_mdl = @(P0, R, C, TT) arrayfun(@(T) P0 + 4*R.*C.*(T/C).^5 * integral(@(x) x.^5./(exp(x)-1).*(1-exp(-x)), 0, (C/T)), TT);
sol = lsqcurvefit(@(param, T) P_mdl(param(1), param(2), param(3), T), rand(3,1), Tv, Pv);
P0_sol = sol(1)
R_sol = sol(2)
C_sol = sol(3)

2 Commenti

Is it possible to plot the original data with the fitted one in a same graph?
Yes, it is possible
Tv = linspace(200, 300, 10).'; % vector of T values
Pv = Tv.^2; % vector of P values
P_mdl = @(P0, R, C, TT) arrayfun(@(T) P0 + 4*R.*C.*(T/C).^5 * integral(@(x) x.^5./(exp(x)-1).*(1-exp(-x)), 0, (C/T)), TT);
sol = lsqcurvefit(@(param, T) P_mdl(param(1), param(2), param(3), T), rand(3,1), Tv, Pv);
P0_sol = sol(1);
R_sol = sol(2);
C_sol = sol(3);
figure()
axes();
hold on;
plot(Tv, Pv, 'b+', 'DisplayName', 'Experimental Data');
plot(Tv, P_mdl(P0_sol, R_sol, C_sol, Tv), 'r', 'DisplayName', 'Estimated Model');
legend('FontSize', 16, 'Location', 'best')

Accedi per commentare.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by