Afficher commentaires plus anciens
编一个关于微分方程组拟合的问题,能运行的了,也能出结果,但是得到的三个参数最佳值是错误的,且随着上下限取的不同而不同,能帮忙看看怎么办吗?
这个是我科研立项最后也是最关键一步,但是Matlab用的不熟,希望有大神帮我解决一下问题,真心感谢。
具体的微分方程是
然后求
上面L和下面L不一样,在程序里有区分。最后是得到M矩阵里M、第一个L和tsd的最佳参数值,拟合数据是t和第二个L的值(程序中已经给出了)。
代码贴出来不知道怎么回事会乱码,所以就这么直接贴了
function HH
clear all
clc
T=[502272 762325 1114354 1364122 1706100 1964980 2140916 2313059 2489034 2742752 3001044];
L=[5.65432E+42 1.30331E+43 9.00958E+42 5.3601E+42 3.56514E+42 2.5611E+42 ...
2.27497E+42 1.94825E+42 1.50971E+42 1.22059E+42 1.04568E+42];
x0=[0.1;0.1];
M0=[0,0,0];
%M0=[0.001*1.989*10^33,1,10^42];
lb=[0.1,0.1,0.1];
ub=[0.5*1.989*10^33,1728000,1*10^46];
Lexp=...
[502272 5.65432E+42
762325 1.30331E+43
1114354 9.00958E+42
1364122 5.3601E+42
1706100 3.56514E+42
1964980 2.5611E+42
2140916 2.27497E+42
2313059 1.94825E+42
2489034 1.50971E+42
2742752 1.22059E+42
3001044 1.04568E+42];
%t=0.1:1:402800;
[M,resnorm,residual,exitflag,output,lambda,jacobian] = ...
lsqnonlin(@g,M0,lb,ub,[],T,x0,Lexp);
A=M(1)
B=M(2)
C=M(3)
end
function LL=g(M,T,x0,Lexp)
c=3*10^10;
k=0.5;
[t,Eint]=ode45(@f,T,x0,[],M);
LL=Eint(:,2).*t./(3.*k.*M(:,1)).*(4.*pi.*c.*Eint(:,1))-Lexp(:,2);
end
function dEint=f(t,Eint,M) %目标函数,M(1)=M,M(2)=tsd,M(3)=L,Eint(1)代表v,Eint(2)代表Eint
c=3*10^10;
k=0.5;
dEint(1)=Eint(2)./(M(1).*Eint(1).*t);
dEint(2)=(M(3)./((1+t./M(2)).^2)-4.*pi.*c.*Eint(2).*t.*Eint(1)./(3.*k.*M(1))-Eint(2)./t);
dEint=dEint(:);
end
麻烦哪位大神能帮忙认真看一下吗。这是我科研立项最重要一步,已经卡这里很久了,真心没什么办法了。
Réponses (0)
Catégories
En savoir plus sur 选择求解器 dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!