下面是一份使用四阶龙格库塔法求解三阶暂态电机模型的Matlab代码:
function [t,x]=rk4(f,tspan,x0,h)
% Fourth-order Runge-Kutta method to solve x' = f(t,x) with x(t0) = x0
% Inputs:
% f - function handle for f(t,x)
% tspan - [t0,tf]
% x0 - initial condition
% h - step size
% Output:
% t - t values at each