matlab ode45修改,matlab ode45增加输入值

不好意思再请教一下

我在网路上找到rk4的程式,但执行的时候发生错误

Error using rk4_systems (line 24)

Not enough input arguments.

我看不懂输入的东西要加在哪里

以及如何更改成我的式子?

function rk4_systems(a, b, N, alpha)

%function rk4_systems() approximates the solutions of systems of m

%differential equations that are written in the form

%dy1/dt = f1(t,y1,y2,...,ym)

%dy2/dt = f2(t,y1,y2,...,ym)

%.

%dym/dt = fm(t,y1,y2,...,ym)

%with t in the interval [a; b] and the initial conditions are in the

%m-dimensional vector alpha

%as with function runge_kutta4(), the inputs are the endpoints a and b, the

%number of subdivisions N in the interval [a; b], and the initial

%conditions - but this time, the initial condition is a vector

m = size(alpha,1);

if m == 1

alpha = alpha';

end

h = (b-a)/N;        %the step size

t(1) = a;

w(:,1) = alpha;     %initial conditions

for i = 1:N

k1 = h*f(t(i), w(:,i));

k2 = h*f(t(i)+h/2, w(:,i)+0.5*k1);

k3 = h*f(t(i)+h/2, w(:,i)+0.5*k2);

k4 = h*f(t(i)+h, w(:,i)+k3);

w(:,i+1) = w(:,i) + (k1 + 2*k2 + 2*k3 + k4)/6;

t(i+1) = a + i*h;

end

[t' w']

%function relating the right-hand side of the differential equation

%it has to be changed accordingly to the problem at hand

%in this case, the system of differential equations is:

%dy1/dt = y2

%dy2/dt = -y1 - 2exp(t) + 1

%dy3/dt = -y1 - exp(t) + 1

%change it before proceeding to the command line

function dy = f(t, y)

dy = [y(2);

-y(1) - 2*exp(t) + 1;

-y(1) - exp(t) + 1];

谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值