我正在使用boost odeint来进化一个微分方程。时间和值是由包装类围绕一个普通数(进行高斯误差传播)给出的。
using Time = Number<double>;
using Value = Number<double>;
状态及其导数由带有声明的自定义类给出。
class State : boost::addable<State>, boost::multipliable<State, Time>, boost::dividable<State>
{
public:
void Add(Group const&
我需要在Scilab上使用Runge 4(5)来求解这个微分方程:
初始条件在以上。间隔和h步骤是:
我不需要执行龙格-库塔。我只需要解决这个问题并在飞机上画出结果:
我试着遵循官方"Scilab帮助“中的以下说明:
建议的守则是:
// Import the diagram and set the ending time
loadScicos();
loadXcosLibs();
importXcosDiagram("SCI/modules/xcos/examples/solvers/ODE_Example.zcos");
s
我感兴趣的是编写一个函数,该函数的输入之一是要使用的模块名称。例如,我写了一个Runge Kutta四阶积分器,用于求解一个常微分方程系统。我更喜欢编写实际的Runge Kutta集成函数,这样就有了定义ODE系统的函数的输入。
下面是一个示例模块,其中包含一个定义ODE系统的函数
MODULE DIFF_EQ
! Description: This module contains the function that defines the
! system of ODEs to be solved.
CONTAINS
FUNCTION YDOT(t, y
我什么都试过了,到处都找遍了,却找不到解决问题的办法。
clc
clear all
%% Solving the Ordinary Differential Equation
G = 6.67408e-11; %Gravitational constant
M = 10; %Mass of the fixed object
r = 1; %Distance between the objects
tspan = [0 100000]; %Time Progression from 0 to 100000s
conditions = [1;0]; %y0= 1m apart,
我得到了一个excel文件,其中包括对函数f(x,y)的引用。该文件不包括宏。我编写了一个具有不同函数的宏,并使用.xlsm扩展保存它。当我运行新的宏时,我会得到堆栈空间错误中的运行时错误'28‘。
这意味着什么,我该如何纠正?有人告诉我,我不需要visual来做这件事。这是一个特别的附加包裹吗?谢谢。
Sub xplusy()
'
' xplusy Macro
' Function f(x,y) f=x+y End Function
'
'
Application.Run "'5_3 Runge-Kutta.xlsm&
下面是我的第四阶Runge算法来求解一阶ODE。我正在对照维基百科中找到的来解决这个问题:
\frac{dx}{dt} = tan(x) + 1
不幸的是,它有点过时了。我已经玩了很久了,但我找不到错误。答案应该是t= 1.1和x= 1.33786352224364362。下面的代码给出t= 1.1和x= 1.42223。
/*
This code is a 1D classical Runge-Kutta method. Compare to the Wikipedia page.
*/
#include <math.h>
#include <iostream>
我现在不明白为什么我的向量在这段代码中的长度是1。当我检查这两个长度时,我的Y向量总是为1。即使我特别把它设为向量t的精确长度,有什么建议吗?
func = @(y,t) y*sin(t);
for i = [1/4,1/8,1/16,1/32,1/64]
[Y,t] = runge_kutta(-1,1,i,func);
disp(length(Y));
disp(length(t));
end
function [Y,t] = runge_kutta(y0,T,dt,f)
t = 0:dt:T;
Y = zeros(1,length(t));
我正在实现一个四阶Runge方法来求解一个三种描述SIR模型的系统。根据其他模拟,我会期待一个不同的解决方案(我的分歧非常快)。下面是runge kutta方法的代码:
def rk4(f, s0, x0, xf, n):
x = np.linspace(x0, xf, n+1) #x grid
s = np.array((n+1)*[s0]) #array of the state of the sytem for each x
h = x[1] - x[0] #stepsize
for i in range(n): #Fourth Order Runge Kut
可能重复:
当我最终释放错位数组时,我的程序就崩溃了。为什么?而且,我不是百分之百的在如何分配它的第一位。不过,该程序的工作方式与预期一样,适用于当我释放指针时的崩溃。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* Approximates a solution to a differential equation on the form:
y'(t) + ay(t) = x(t)
y(0) = b
*/
double* runge_kutta_2nd_
我需要用MATLAB中的数值方法来求解这些特殊的。这些方程实质上模拟了质量为m的物体的下落,它与弹性片相连,弹簧常数k,这些方程的解表示物体在离散位置上的时间位置和速度。
这些颂歌的参数是,
H = 74
D = 31
c = 0.9
m = 80
L = 25
k = 90
g = 9.8
C = c/m
K = k/m
T = 60