Unable to use ODE45 to model data, error with "Unable to meet integration tolerances without reducing the step size below the smallest value allowed (4.708773e-14) at time t."

1 visualizzazione (ultimi 30 giorni)
Hello!
I am using a function with ODE45 within it as a modelfun for nlinfit to fit my data to using parameters "beta", but it gives nonsensical answers or ust gives up, any ideas?
CODE:
clear all; clc; clf;
c0=[0.0188,0];
A=readmatrix('1020_Conc.txt'); % loading data
for n=2:length(A) %fixing any wierd points on data..
if A(n)<0.001 || A(n)>0.02
A(n)=A(n-1);
end
end
A(1)=A(2); %fixing any wierd points on data..
temp=1000;
tspan=linspace(1,length(A),length(A))*0.6; %time of data
beta0=[1,2,0.5,0.5]; %initial guess
plot(tspan,A)
hold on
c0= [0.0188,0];
beta=nlinfit(tspan,A,@fun1,beta0);
CA=fun1(beta0,tspan);
plot(tspan,CA)
function CA = fun1(beta,tspan)
c0=[0.0188,0];
[~,C]=ode23t(@(t,C)odefun(t,C,beta),tspan,c0);
ylim([0,0.02])
CA=C(:,1);
CA=CA';
end
function dcdt=odefun(tspan,c,beta)
A=beta(3)*c(1)^beta(1);
B=beta(4)*c(2)^beta(2);
dcdt(1)=B-A;
dcdt(2)=A-B;
dcdt=dcdt';
end
Concentration data to be fitted to the rate law solved by ODE45: attached.

Risposte (1)

Walter Roberson
Walter Roberson il 3 Giu 2023
c0=[0.0188,0];
A=beta(3)*c(1)^beta(1);
B=beta(4)*c(2)^beta(2);

I would think it is highly likely that that ode23t is going to probe into c(2) being negative, which is going to lead to complex results from the ^

There is an option for nonnegative constraints if I recall correctly.

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by