2011-03-30 104 views
-5
dT/dt=(1.344-1.025T)/h (1) 

dh/dt=0.025-(3.5*10^-4)*sqrt(h) (2) 

h(0)=1 

T(0)=1 

我必须在fortran中求解这个方程组。我解决了matlab中的问题,但我不知道fortran编程,所以如果有人可以帮助我或某人有fortran代码,请帮助我,请请 多谢runge kutta四阶求解微分方程组

+7

尝试租用编码器。这不是一个“做我的家庭作业”网站。阅读足够的Fortran以尝试某些内容并在出现问题时发布。你会进一步采用这种方法。 – duffymo 2011-03-30 09:34:51

回答

3

尝试与欧拉集成。先做一些简单的事情。你有一个好处:你已经解决了这个问题,所以你知道答案是什么样的。

由于版主们坚持认为由于篇幅有限,这是一个低质量的答案,所以我会在Java中提供一个适用于您的应用程序,以便引发您的一些想法。我使用了Apache Commons数学库;它有几种不同的ODE集成方案,包括Euler和Runge Kutta。

我跑这个使用JDK 8.您可以使用命令行欧拉和龙格 - 库塔之间切换的Windows 7计算机上:

package math.ode; 

import org.apache.commons.math3.exception.DimensionMismatchException; 
import org.apache.commons.math3.exception.MaxCountExceededException; 
import org.apache.commons.math3.ode.FirstOrderDifferentialEquations; 
import org.apache.commons.math3.ode.FirstOrderIntegrator; 
import org.apache.commons.math3.ode.nonstiff.ClassicalRungeKuttaIntegrator; 
import org.apache.commons.math3.ode.nonstiff.EulerIntegrator; 

/** 
* IntegrationExample solves coupled ODEs using Euler and Runge Kutta 
* Created by Michael 
* Creation date 12/20/2015. 
* @link https://stackoverflow.com/questions/20065521/dependencies-for-jama-in-maven 
*/ 
public class IntegrationExample { 

    public static final double DEFAULT_STEP_SIZE = 0.001; 
    private static final double DEFAULT_MAX_TIME = 2.0; 

    public static void main(String[] args) { 
     // Problem set up 
     double step = (args.length > 0) ? Double.valueOf(args[0]) : DEFAULT_STEP_SIZE; 
     double maxTime = (args.length > 1) ? Double.valueOf(args[1]) : DEFAULT_MAX_TIME; 
     String integratorName = (args.length > 2) ? args[2] : "euler"; 
     // Choose different integration schemes here. 
     FirstOrderIntegrator firstOrderIntegrator = getFirstOrderIntegrator(step, integratorName); 
     // Equations to solve here; see class below 
     FirstOrderDifferentialEquations odes = new CoupledOdes(); 
     double [] y = ((CoupledOdes) odes).getInitialConditions(); 
     double t = 0.0; 
     int i = 0; 
     while (t <= maxTime) { 
      System.out.println(String.format("%5d %10.6f %10.6f %10.6f", i, t, y[0], y[1])); 
      firstOrderIntegrator.integrate(odes, t, y, t+step, y); 
      t += step; 
      ++i; 
     } 
    } 

    private static FirstOrderIntegrator getFirstOrderIntegrator(double step, String integratorName) { 
     FirstOrderIntegrator firstOrderIntegrator; 
     if ("runge-kutta".equalsIgnoreCase(integratorName)) { 
      firstOrderIntegrator = new ClassicalRungeKuttaIntegrator(step); 
     } else { 
      firstOrderIntegrator = new EulerIntegrator(step); 
     } 
     return firstOrderIntegrator; 
    } 
} 

class CoupledOdes implements FirstOrderDifferentialEquations { 

    public double [] getInitialConditions() { 
     return new double [] { 1.0, 1.0 }; 
    } 

    @Override 
    public int getDimension() { 
     return 2; 
    } 

    @Override 
    public void computeDerivatives(double t, double[] y, double[] yDot) throws MaxCountExceededException, DimensionMismatchException { 
     yDot[0] = (1.344-1.025*y[0])/y[1]; 
     yDot[1] = 0.025-3.5e-4*Math.sqrt(y[1]); 
    } 
} 

你没有说出来,你需要多远整合时间,所以我认为2.0是最长时间。你也可以在命令行上改变它。

下面是Excel中结果与时间的关系图。正如你所看到的,反应平稳而且表现良好。欧拉方程式这样的系统没有问题。

enter image description here

+0

@duffymo:我可以推荐你多解释一下你的答案吗?例如:提供欧拉算法,也许是提供问题的一个例子? (目前您的答案由于其长度较低而被标记为低质量) – 2015-12-20 18:21:19

+0

任何使用Matlab和Runge-Kutta的人都可以切换到欧拉 - 无需任何解释。求解耦合ODE的问题也应该是已知的。这与被要求解决排序问题并在泡沫和快速排序之间进行选择类似。我假设OP对他们的问题有最低限度的了解,即使你没有。低质量?比较什么?没有其他答案。 – duffymo 2015-12-20 21:17:31

+0

即使最无知的评论巨魔也应该满足。 – duffymo 2015-12-20 22:12:47