声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1729|回复: 3

[编程技巧] 我在用数值法求解微分方程时老是出错

[复制链接]
发表于 2007-5-23 21:52 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
我要求解微分方程:
dx/dt=-0.15*y(t)
dy/dt=-0.1*x(t)
x0=10000,y0=5000
代码:帮忙看一下
function xdot=a(t,x)
xdot=zeros(2,1);
xdot(1)=-0.15*x(2);
xdot(2)=-0.10*x(1);
存为a.m


>> t0=-10;tf=20;
x0=[10000 5000]
[t,x]=ode23('a',t0,tf,x0);
plot(x(:,1),x(:,2))

x0 =

       10000        5000

Warning: Obsolete syntax.  Use ode23(fun,tspan,y0,...) instead.
(Type "warning off MATLAB:odearguments:ObsoleteSyntax" to suppress this warning.)
> In C:\MATLAB6p5\toolbox\matlab\funfun\private\odearguments.m at line 39
  In C:\MATLAB6p5\toolbox\matlab\funfun\ode23.m at line 154
>>
回复
分享到:

使用道具 举报

发表于 2007-5-23 21:57 | 显示全部楼层
原帖由 夜幽书生 于 2007-5-23 21:52 发表
我要求解微分方程:
dx/dt=-0.15*y(t)
dy/dt=-0.1*x(t)
x0=10000,y0=5000
代码:帮忙看一下
function xdot=a(t,x)
xdot=zeros(2,1);
xdot(1)=-0.15*x(2);
xdot(2)=-0.10*x(1);
存为a.m


>> t0= ...


请看看 matlab 帮助中的例子,或者搜索一下本版,有 n 多讨论
发表于 2007-5-24 17:06 | 显示全部楼层
>> t0=-10;tf=20;
tspan=[t0,tf];
x0=[10000 5000];
[t,x]=ode23('lab',tspan,x0);
plot(x(:,1),x(:,2));
这样就可以啦
 楼主| 发表于 2007-5-25 12:28 | 显示全部楼层
谢谢xun的解答
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-24 09:21 , Processed in 0.050712 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表