声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1136|回复: 4

[编程技巧] 请教一个关于解二阶常系数非齐次方程的问题

[复制链接]
发表于 2010-3-31 16:07 | 显示全部楼层 |阅读模式

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

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

x
以下是我编的一个程序:
function LinearResponse
m0=0.46; r=13.5; w=200*2*3.14;m=3.76; f=578;k=10;
tspan=linspace(0,30,6000); sampint=tspan(2);
options=odeset('RelTol',1e-8,'AbsTol',[1e-8,1e-8]);
[t,x]=ode45(@ForcedOscillatorl,tspan,[0 0]',options,m0,r,w,m,f,k);
figure(1); plot(t,x(:,1)); axis([0 30,-1,1]); xlabel('\tau'); ylabel('x(\tau)');
yy=x(:,1);

funtion xdot=ForcedOscillatorl(t,x,m0,r,w,m,f,k)
xdot=[x(2);-f*x(2)/(m0+m)-k*x(1)/(m0+m)+m0*r*cos(w*t)*w^2/(m0+m)];

可是运行不了结果,总提示错误,不知道为什么:
Warning: feval on script names will not work, or may work differently,
in a future version of MATLAB.  To make your code insensitive to any change
and to suppress this warning message:
- Either change the script to a function.
- Or use eval instead of feval.
The script file in question is ForcedOscillatorl.
> In funfun\private\odearguments at 110
  In ode45 at 173
  In LinearResponse at 8
??? Attempt to execute SCRIPT ForcedOscillatorl as a function:
D:\我的文档\MATLAB\ForcedOscillatorl.m

Error in ==> funfun\private\odearguments at 110
f0 = feval(ode,t0,y0,args{:});   % ODE15I sets args{1} to yp0.

Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...

Error in ==> LinearResponse at 8
[t,x]=ode45(@ForcedOscillatorl,tspan,[0 0]',options,m0,r,w,m,f,k);

请多多指教,谢谢!

[ 本帖最后由 ChaChing 于 2010-4-7 00:02 编辑 ]
回复
分享到:

使用道具 举报

发表于 2010-3-31 16:35 | 显示全部楼层
将函数文件里的“funtion”改为“function”
将主程序里的“function LinearResponse”去掉
 楼主| 发表于 2010-3-31 16:52 | 显示全部楼层

回复 板凳 maigicku 的帖子

还是不对
??? Error: File: LinearResponse.m Line: 1 Column: 9
Expression or statement is incomplete or incorrect.
发表于 2010-4-6 16:35 | 显示全部楼层
程序如下:
function xdot=ForcedOscillatorl(t,x,m0,r,w,m,f1,k)
xdot=[x(2);-f1*x(2)/(m0+m)-k*x(1)/(m0+m)+m0*r*cos(w*t)*w^2/(m0+m)];
end

clear;clc
m0=0.46;
r=13.5;
w=200*2*3.14;
m=3.76;
f1=578;
k=10;
tspan=linspace(0,30,100);
sampint=tspan(2);
options=odeset('RelTol',1e-8,'AbsTol',[1e-8,1e-8]);
[t,x]=ode45(@ForcedOscillatorl,tspan,[0 0],options,m0,r,w,m,f1,k);
figure(1);
plot(t,x(:,1));
axis([0 30,-1,1]);
xlabel('\tau');
ylabel('x(\tau)');
yy=x(:,1);


建议将tapan的取值个数减小一些,要不运行时间太长。。。还有将ode45中的“[0 0]'”改为“[0 0]”

[ 本帖最后由 maigicku 于 2010-4-6 16:54 编辑 ]

评分

1

查看全部评分

 楼主| 发表于 2010-4-8 17:52 | 显示全部楼层

回复 地板 maigicku 的帖子

非常感谢!
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-9-21 22:43 , Processed in 0.060918 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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