- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试编写一个函数,该函数将使用 4 阶隐式 Runge-Kutta 方法 (IRK) 求解 ODES 系统,但我无法正确定义循环。这里我们定义 IRK
任何建议将不胜感激!
function [tout,yout] = IRK4Solver(f,t,y0)
t = t(:); % ensure that t is a column vector
N = length(t);
h = (t(end)-t(1))/(N-1); % calculate h by assuming t gridpoints are equidistant
d = length(y0); % defines the size of y0
y0 = y0(:); % ensures that y0 is a column vector
y = zeros(d,N);% allocate the output array y
y(:,1) = y0; % assign y0 to the first column of y
% The entries of the following tableau are provided in the lecture notes
c = [1/2-sqrt(3)/6;
1/2+sqrt(3)/6];
A = [1/4, 1/4-sqrt(3)/6;
1/4+sqrt(3)/6, 1/4];
b = [1/2;1/2];
%calculate the loop
for n=1:N
xi_1 = y(:,n)+h.*A(1,1).*f(t(n)+c(1).*h,xi_1)+h.*A(1,2)f(t(n)+c(2).*h,xi_2);
xi_2 = y(:,n)+h.*A(2,1).*f(t(n)+c(1).*h,xi_1)+h.*A(2,2)f(t(n)+c(2).*h,xi_2);
y(:,n+1) = y(:,n)+h.*b(1).*f(t(n)+c(1).*h,xi_1)+h.*b(2)f(t(n)+c(2).*h,xi_2);
end
tout = t;
yout = y;
fsolve
在我的 for 循环中。然而,porgram 仍然不会运行。
for n=1:N
eq=@(xi) [xi(1:3)-(y(:,n)+h.*A(1,1).*f(t(n)+c(1).*h,xi(1:3))+h.*A(1,2)f(t(n)+c(2).*h,xi(1:3)));
xi(1:3)-(y(:,n)+h.*A(2,1).*f(t(n)+c(1).*h,xi(1:3))+h.*A(2,2)f(t(n)+c(2).*h,xi(1:3)))];
xistar=fsolve(eq,[1 1 1;1 1 1]);
y(:,n+1) = y(:,n)+h.*b(1).*f(t(n)+c(1).*h,xistar(1:3))+h.*b(2)f(t(n)+c(2).*h,xistar(1:3));
end
最佳答案
您需要包含命令 fsolve
在你的 for 循环中
关于matlab - 为隐式 Runge-Kutta 方法编写函数(四阶),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61378206/
我正在尝试用python解决系统问题: z &
我在MATLAB中编程了一个自适应步长RK4来求解ODE系统。代码运行时没有错误,但是当我尝试将x与y作图时,它不会产生所需的曲线。我不再是环形形状,而是获得了一条扁平线。从r输出恒定值这一事实可以明
我一直在尝试将 RK4 集成到我正在做的模拟中。下面的函数是我基于第 12 页 this 上的方程式使用 RK4 对 3 维力场进行积分的最佳尝试。网站。 在我的代码中,粒子类主要存储速度和位置列表,
我试图获得一个简单追逐问题的数值解 (动靶+定速模块火箭) 每次迭代我的速度模块都会减少一点,将误差加起来;在几百次迭代之后,错误爆发,速度急剧下降。 但是,使用 Euler 方法(大块下方的代码)时
有人要求我解这个微分方程: (x,y,vx,vy)'=(vx,vy,vy,-vx) 它应该返回周期为 2*pi 的圆周运动。我实现了功能: class FunzioneBase { public:
我一直在研究四阶龙格-库塔求解器,但遇到了一些困难。我已经根据文章 on gafferongames 编写了求解器,但是当我运行一个包含的小例子时,我得到的错误比我用简单的欧拉积分得到的错误要糟糕得多
几乎每个游戏都倾向于使用一些游戏循环。 Gafferongames 有一篇关于如何制作精心设计的游戏循环的好文章:http://gafferongames.com/game-physics/fix-y
我有以下微分方程组: 根据他们告诉我的论文,我可以使用 RK 四阶数值求解它。 如您所见,最后两个方程是耦合的,我构造了一个关联 xn 和 yn 的矩阵(概率),其中 n = 1..(例如,N- 对数
我正在使用 Runge-Kutta 四阶方法数值求解具有四次势的弯曲时空背景标量场的常见运动方程: $\phi^{''}=-3\left(1+\frac{H^{'}}{3H}\right)\phi^{
我有一个耦合方程组:流体静力学平衡方程、质量连续性方程和理想气体的状态方程。这些是,在数学语法中, \frac{dP}{dr}=-\rho*g, 其中 \rho 是密度,g 是重力加速度。 \frac
有人能告诉我,为什么它总是返回相同的“y”值吗?我在 Internet 上搜索了很多,但我仍然不知道为什么它不起作用。 using System; using System.Collections.G
下面是我用于求解一阶 ODE 的四阶 Runge-Kutta 算法。我正在根据找到的维基百科示例检查它 here解决: \frac{dx}{dt} = tan(x) + 1 不幸的是,它有点出局了。我
我正在尝试实现 Runge-Kutta Method for Systems of DEs在 MATLAB 中。我没有收到 correct answers ,我不确定代码或我用来运行它的命令是否有问题
尝试实现自适应步长 Runge-Kutta Cash-Karp 但失败并出现此错误: home/anaconda/lib/python3.6/site-packages/ipykernel_launc
我正在尝试编写一个函数,该函数将使用 4 阶隐式 Runge-Kutta 方法 (IRK) 求解 ODES 系统,但我无法正确定义循环。这里我们定义 IRK 任何建议将不胜感激! function [
Gaffer on Games 有一个 great article关于使用RK4 integration为了更好的游戏物理。实现很简单,但其背后的数学让我感到困惑。我在概念层面上了解导数和积分,但已经
这个公式主要是这个线程的结果:Differential Equations in Java . 基本上,我尝试遵循 Jason S. 的建议,并通过 Runge-Kutta 方法 (RK4) 实现微分
我是Python的新手,我对编程语言的了解还处于起步阶段,所以我复制了所示的Runge-Kutta Python脚本here并根据我的目的对其进行了修改。这是我当前的脚本: import numpy
我一直在将 4 个链接微分方程的欧拉方法实现转换为四阶龙格库塔实现。我相当确信我的一般方法是正确的,并且我已经了解如何应用 RK4,但我可能已经有 6 年没有做过任何半严肃的数学了,所以我可能会错过某
我尝试求解简单的数值方程 - 没有源的线性波动方程:utt = v2 uxx 其中 v - 波速。 我使用初始条件: u(x, 0) = sin(x) ux(x, 0) = -v * sin(x) 对
我是一名优秀的程序员,十分优秀!