while fitting my model data to experimental data the resultant curve is shooting very high and is not matching with experimental time points, even on changing ub and lb

조회 수: 3 (최근 30일)
% Experimental data
t1=[0 6 12 18 36 48]; % time points
nfe2=[0.9 1.57 2.87 3.9 5.16 4.25]; %level of protein
t=1:1:48; %simulation time
% ODE equation
ode_eqn = @(x, t)integrate_a(x, t); %ODE equation to fit
x0 = [0.04 0.055]; % Initial guess for the parameters
% Least squares curve fitting using lsqcurvefit
x_fit = lsqcurvefit(ode_eqn, x0, t1, nfe2);
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
disp("Fitted parameters using lsqcurvefit:")
Fitted parameters using lsqcurvefit:
disp(x_fit)
1.1792 0.0282
% Nonlinear programming using fmincon
options = optimoptions('fmincon', 'Algorithm', 'interior-point');
x_fit_constrained = fmincon(@(x) sum((ode_eqn(x, t1) - nfe2).^2), x0,[],[],[],[],[0 0],[10 10],[],options);
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
disp("Fitted parameters using fmincon:")
Fitted parameters using fmincon:
disp(x_fit_constrained)
1.1792 0.0282
% Plotting results
t_fit = linspace(1, max(t1),49); % Time points for plotting fitted curve
figure;
plot(t1, nfe2, 'bo', 'MarkerSize', 8, 'LineWidth', 1.5); % Plot experimental data
hold on;
plot(t_fit, ode_eqn(x_fit, t_fit), 'r-', 'LineWidth', 2); % Plot fitted curve using lsqcurvefit
plot(t_fit, ode_eqn(x_fit_constrained, t_fit), 'g--', 'LineWidth', 2); % Plot fitted curve using fmincon
hold off;
legend('Experimental Data', 'lsqcurvefit', 'fmincon');
xlabel('Time');
ylabel('Data');
title('Fitting Experimental Data to ODE Equation');
%%
function ifn = integrate_a(x, t)
%nf=[0.9 3.3 6.8 5.7 4.02 ];
%f=[100 98.31 35.5 12.85 4.68];
ifn=zeros(size(t));
for i=1:numel(t)
if t(i)<6.48
cd(i)=1;
else
cd(i)=(1- 0.0683)*exp(-0.0240*(t(i) - 6.48)) + 0.0683;
end
c=cd;
if t(i)<4
inf(i)=0.9;
else
inf(i) = inf(i-1)+ (cd(i).*x(1)- inf(i-1).*x(2));
end
ifn=inf;
end
end
  댓글 수: 1
Matt J
Matt J 2023년 6월 16일
the resultant curve is shooting very high and is not matching with experimental time points
That's nothing we can diagnose for you. It's possible your model is just unsuitable to the data.

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

답변 (1개)

Image Analyst
Image Analyst 2023년 6월 16일
Are you just trying to fit this equation:
cd(i) = (1- 0.0683) * exp(-0.0240*(t(i) - 6.48)) + 0.0683;
If so use fitnlm. I'm attaching some demos. Adjust the equation/formula as needed.
  댓글 수: 3
Image Analyst
Image Analyst 2023년 6월 17일
I don't know what a "waty" is.
Also inf is a contant in MATLAB. It means "infinity". So I'm not sure what your equation means. Usually operations using infinity end up giving infinity again. For example inf(5) will give a 5x5 array of infinity values
i = 5;
a = inf(i)
a = 5×5
Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
So you can't have inf(i) on the left hand side of the equation.
SWAPNAVA
SWAPNAVA 2023년 6월 17일
no "inf" is a variable. i have changed to "infron" still I am getting the model output curve but it is reaching till 25 along y xis where experimental data is till 5 only maximum along y axis.

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

카테고리

Help CenterFile Exchange에서 Nonlinear Least Squares (Curve Fitting)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by