当前位置:网站首页>【Runge-Kutta】龙格-库塔法求解微分方程matlab仿真
【Runge-Kutta】龙格-库塔法求解微分方程matlab仿真
2022-07-19 03:07:00 【fpga和matlab】
1.软件版本
MATLAB2013b
2.算法理论
龙格-库塔法(Runge-Kutta)是用于模拟常微分方程的解的重要的一类隐式或显式迭代法。龙格库塔法的家族中的一个成员如此常用,以至于经常被称为“RK4”或者就是“龙格库塔法”。令初值问题表述如下。
这样,下一个值(yn+1)由现在的值(yn)加上时间间隔(h)和一个估算的斜率的乘积决定。该斜率是以下斜率的加权平均:
k1是时间段开始时的斜率;
k2是时间段中点的斜率,通过欧拉法采用斜率k1来决定y在点tn + h/2的值;
k3也是中点的斜率,但是这次采用斜率k2决定y值;
k4是时间段终点的斜率,其y值用k3决定。
3.部分matlab程序
clc;
clear;
close all;
warning off;
%The parameter
g = 9.81;
L = 0.1;
m = 0.5;
es = 2;
%the range of t
t0 = 0;
tf = 10;
x0 = 0.25;
x0dot = 0;
Step = 1000;
%The method of RK4
Y1 = func_4RGKT(t0,tf,x0,x0dot,Step);
figure(1);
subplot(121);
plot([t0:(tf-t0)/Step:tf],Y1,'b');
xlabel('t');
ylabel('x');
axis square;
grid on;
title('the method of RK4');
%The method of Euler
Y2 = func_Euler(t0,tf,x0,x0dot,Step);
figure(1);
subplot(122);
plot([t0:(tf-t0)/Step:tf],Y2,'r');
xlabel('t');
ylabel('x');
axis square;
grid on;
title('the method of Euler');
function Y1 = func_4RGKT(t0,tf,x0,x0dot,STEPS);
%t0, tf, upper and lower, respectively,
%x0 the initial value of y,
%STEPS steps times
h = (tf - t0)/STEPS;
T = zeros(1,STEPS+1);
Y = zeros(1,STEPS+1);
T(1) = t0;
Y(1) = x0;
Y0dot(1) = x0dot;
for j=1:STEPS
tj = T(j);
yj = Y(j);
yjd = Y0dot(j);
k1 = h*func_function(tj ,[yj,yjd]);
k2 = h*func_function(tj+h/2 ,[yj+h*k1(1)/2,yjd+h*k1(2)/2]);
k3 = h*func_function(tj+h/2 ,[yj+h*k2(1)/2,yjd+h*k2(2)/2]);
k4 = h*func_function(tj+h ,[yj+h*k3(1) ,yjd+h*k3(2)]);
Y(j+1) = yj + (k1(1) + 2*k2(1) + 2*k3(1) + k4(1))/6;
Y0dot(j+1) = yjd + (k1(2) + 2*k2(2) + 2*k3(2) + k4(2))/6;
T(j+1) = t0 + h*j;
end
Y1=Y';
4.仿真结论
从图的仿真结果可知,当算法迭代1000次的时候,算法经过几个周期抖动之后收敛,但是其收敛时间较短。 因此,从整体而言,采用RK4算法,比Euler算法收敛更快,且较快的达到一定精度之内A28-20。
边栏推荐
- 股票开户免费办理佣金最低的券商,网上开户安全吗
- DDD领域驱动设计如何进行工程化落地
- Silicon Valley class lesson 8 - Tencent cloud on demand management module (3)
- G. Count the Trains(思维set + 二分)
- 11.3 排列和组合的产生(无重集元素)
- How to carry out engineering implementation of DDD Domain Driven Design
- Oracle嵌套多层,找不到表的别名问题
- MySQL MHA高可用集群部署
- 哪个证券公司开户股票手续费低,哪个证券开户安全
- 18_ filter
猜你喜欢
浅谈:Web3创造者经济
P3166数三角形(容斥+gcd)
MySQL详细知识点总结 可以收藏啦
LeetCode 0749. Isolate virus - big simulation
Silicon Valley class lesson 9 - integration gateway and order and marketing module
Video 24 alexnet
01.有效的括号
Memory forensics WP of 2022 network security national game
Reasons for errors in installing wfuzz under win10 CDM
硅谷课堂第十课-营销模块和公众号菜单管理
随机推荐
Metasploit of penetration test artifact
D - Dire Wolf(区间dp)
回归分析模型
【微信小程序】课程表案例--0基础版
分享搭建脚手架的一些经验
NAOMI: Non-Autoregressive MultiresolutionSequence Imputation(非自回归多分辨率序列填补)论文详解
哪个证券公司开户股票手续费低,哪个证券开户安全
18_ filter
硅谷课堂第十课-营销模块和公众号菜单管理
数据库压力测试方法概述
NFT 市场也开始走向多元化
C语言枚举类型和联合体
由pyproject.toml引发的讨论
11.3 排列和组合的产生(无重集元素)
11.3 generation of permutations and combinations (no re set elements)
Silicon Valley class lesson 9 - integration gateway and order and marketing module
powerdisgner模型生成的sql脚本运行错误
D. Rating Compression(思维 + 双指针)
PAT乙级-B1007 素数对猜想(20)
NFT访问工具PREMINT遭黑 损失超37万美元