得到Runge-Kutta解决的ODE方程的复杂结果

时间:2016-04-19 18:36:21

标签: matlab ode runge-kutta

我已经编写了一个Runge-Kutta代码来解决Matlab中的ODE,但是我得到了不希望的复杂结果。

function dy = fctrl(t,y)
dy = zeros(2,1);
% parameter settings
syms VD rdc
Tt = 300;                         
kB = 8.6173324*10^(-5);          
E = 211;                          
rou = 2;                         
b = 0.148;                        
G = 82;                          
nu = 0.290;                      
R0 = 15;                         
sigmaY = 0.13;                   
n = 0.12;                         
ch = sqrt(2.5*(2-n)/(4+n))*10^9;  
kapa = 2.65;                      
ct = 3.24*10^12;                  
beta0 = 2.5*10^(-14);            
d = 2;                          
hdot = 10;                       
epsilonD = 8*160.2176487*10^(-3)/b;
sigmaP = 1.2;
A = 3.71*10^12;
epsilons = 0.136*0.16021766208;  
% Normalized parameters
sigmaYb = sigmaY/E;
beta0b = beta0*ct;
% ODE functions
a = (0.75*R0*y(2)*(1-nu^2)/E)^(1/3);
rc = a*(0.25*E*a/(R0*sigmaY))^(1/3);
rbm = (0.1*n*kapa*(rc^2)*(sigmaYb^(n-1))/ch)^(1/(3*n-5)); % scaled rm
staomax = abs(-0.5*kapa*(sigmaYb^n)*(rbm^(-3*n))+3*ch*sigmaYb*(rbm^(-5))/rc^2);
N =10000; % Avoid dead loop
E=1.0e-6; %Convergence limit
sigmastar = sigmaP*(1-0.001*Tt)^2;
s = staomax/sigmastar;
if(s<=1)
    solVD = A*sqrt(s/Tt)*exp(-3772*(1-sqrt(s))/Tt);
else
    solVD = 10^9*((s-1)*(1140-2.28*Tt+1.14*10^(-3)*Tt^2)+6.1*Tt-2.8*10^(-2)*Tt^2+4.9*10^(-5)*Tt^3-4.3*10^(-8)*Tt^4+1.9*10^(-11)*Tt^5-3.1*10^(-15)*Tt^6);
end
rdc0 = 100; % Quite important, an approximate value
rdc1 = rdc0-G*b*((2-nu)/(1-nu))*(log(2*rdc0/(rou*b))+1)/(8*pi*staomax);
i = 1;
while(norm(rdc1-rdc0)>=E && i<N)
    rdc0=rdc1;
    g=rdc0-G*b*((2-nu)/(1-nu))*(log(2*rdc0/(rou*b))+1)/(8*pi*staomax);
    g1=1-G*b*((2-nu)/(1-nu))/(8*pi*staomax*rdc0);
    if(g1~=0)
        rdc1=rdc0-g/g1;
    end
    i=i+1;
end
solrdc = rdc1;
dy(1) = (2*pi*ct/(2*d^3))*(2*pi*b*(rc^2-a^2)/solrdc^3)*exp(-6.2415*deltaEc/(kB*Tt))+0.1*b*staomax*solVD*y(1)/epsilonD; 
dy(2) = 1.5*y(2)^(1/3)*(hdot-(rc-a)*b*solVD*y(1)/sqrt(6))/((3/(4*E*sqrt(R0)))^(2/3));

将上面的代码复制到&#39; .m&#39;文件,并将其保存为&#39; fctrl.m&#39;。

function[x,y]=marunge4s(dyfun,xspan,y0,h)
x=xspan(1):h:xspan(2);
y=zeros(length(y0),length(x));
y(:,1)=y0(:);
for n=1:(length(x)-1)
    k1=feval(dyfun,x(n),y(:,n));
    k2=feval(dyfun,x(n)+h/2,y(:,n)+h/2*k1);
    k3=feval(dyfun,x(n)+h/2,y(:,n)+h/2*k2);
    k4=feval(dyfun,x(n+1),y(:,n)+h*k3);
    y(:,n+1)=y(:,n)+(h/6).*(k1+2*k2+3*k3+k4);
end

将上面的代码复制到&#39; .m&#39;文件,并将其保存为&#39; marunge4s.m&#39;。

%%
close all
clear
clc
%%
rouD0 = 0;
F0 = 0.1;
h = 2;
[t,y] = marunge4s(@fctrl,[0 100],[rouD0 F0],h);
plot(t,y(2,:),'--*b')

将上面的代码复制到&#39; .m&#39;文件,并将其保存为&#39; solve.m&#39;。

然后,我得到了复杂的结果。我不知道为什么。你能帮我解决一下吗?

祝你好运, 秋月

0 个答案:

没有答案