请问大家,C#解龙格库塔该怎么写,刚学一点C#基本语句,只会定义k的四行,不知道完整的该怎么写
2条回答 默认 最新
- NnWinter冬 2022-05-31 16:41关注
float dydx(float x, float y) { return ((x - y) / 2); } float rungeKutta(float x0, float y0, float x, float h) { // Count number of iterations using step size or // step height h int n = (int)((x - x0) / h); float k1, k2, k3, k4, k5; // Iterate for number of iterations float y = y0; for (int i = 1; i <= n; i++) { // Apply Runge Kutta Formulas to find // next value of y k1 = h * dydx(x0, y); k2 = h * dydx(x0 + 0.5f * h, y + 0.5f * k1); k3 = h * dydx(x0 + 0.5f * h, y + 0.5f * k2); k4 = h * dydx(x0 + h, y + k3); // Update next value of y y = y + (1.0f / 6.0f) * (k1 + 2 * k2 + 2 * k3 + k4); ; // Update next value of x x0 = x0 + h; } return y; } //调用: rungeKutta(1, 2, 3, 4); /*函数引用自: https://www.geeksforgeeks.org/runge-kutta-4th-order-method-solve-differential-equation/ */
题主可以试一下。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 報錯:Person is not mapped,如何解決?