声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2983|回复: 7

[编程技巧] matlab问题requires an initial condition vector of length 4

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

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

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

x
function du=CQ(t,u)
global delta1 delta2 alpha1 xi1 alpha2 xi2  beta2 f omega
    du=[u(2);
        -delta1*u(1)-alpha1*u(1)^3-xi1*u(2)+alpha2*u(3)+alpha2/2*u(1)*cos(2*omega*t)-beta2*u(4)+1/2*beta2*u(2)-1/2*beta2*u(2)*cos(2*omega*t)+f*sin(omega*t);
        u(4);
        -delta2*u(3)-xi2*u(4)+delta2*u(1)*sin(omega*t)+xi2*u(2)*sin(omega*t)];
u0=[0,0,0,0];
  [t,u]=ode45(@CQ,tspan,u0,[])
  plot(t,u(:,1))
报错是
??? Error using ==> odearguments at 117
Solving CQ requires an initial condition vector of length 4.如何纠正呀。敝人草鸟,望大虾指导!!
回复
分享到:

使用道具 举报

发表于 2011-5-4 22:10 | 显示全部楼层
  1. u0=[0;0;0;0];
复制代码
要把你的初始条件写成4行的列向量
 楼主| 发表于 2011-5-4 22:25 | 显示全部楼层
改过u0=[0;0;0;0];之后,报错还是??? Error using ==> odearguments at 117
Solving CQ requires an initial condition vector of length 4.
发表于 2011-5-4 22:58 | 显示全部楼层
回复 4 # lihaitao123 的帖子
  1. >> u0=[0.00 0 0 0]';
  2. >> tspan=[0 1];
  3. >> [t,u]=ode45(@CQ,tspan,u0,[])
复制代码
这样没问题了,我试过了已经!
 楼主| 发表于 2011-5-5 09:29 | 显示全部楼层
回复 5 # meiyongyuandeze 的帖子

谢谢了,但是
>> u0=[0.00 0 0 0];
>> tspan=[0 1];
>> [t,u]=ode45(@CQ,tspan,u0,[])
??? Error using ==> odearguments at 117
Solving CQ requires an initial condition vector of length 4.

发表于 2011-5-5 09:35 | 显示全部楼层
不知道怎么回事,我自己运行的没问题!
发表于 2011-9-20 08:48 | 显示全部楼层
我也有同样的问题,知道怎么回事吗?
发表于 2011-9-21 00:31 | 显示全部楼层
也不知道LZ是否解决了! 好奇试了下!
问题不在u0'或u0! 问题在主程序global的宣告
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-6-20 19:27 , Processed in 0.048448 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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