24小时热门版块排行榜    

查看: 1130  |  回复: 1

wyjjf

新虫 (正式写手)

[交流] MATLAB程序总是出错? 已有1人参与

编辑一MATLAB程序,总是出错,按提示信息改动了很多遍
还是不行
不明白了
麻烦帮帮看看怎么修改

编辑程序:
在Matlab下输入:edit,然后将下面两行百分号之间的内容,复制进去,保存?
CODE:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function dx=myfun(t,x)
syms a e f g a1 a2 e1 e2 f1 f2 g1 g2
dx = zeros(5,1);

dx(1)=x(3)-x(2)+x(4)*x(2)-2*x(5)*x(2)-x(2)*x(2)-x(5)-e-f-g;
dx(2)=x(1)-x(3)+x(4)*x(2)-x(2)*x(2)-x(5)*x(5)-x(5)*x(2)-e*f-g;
dx(3)=x(2)-x(1)+x(5)*x(1)-x(4)*x(3)+x(3)+x(4)+e*g+f;
dx(4)=x(5)*a+x(3)*x(1)+x(3)+e*f*g*x(6);
dx(5)=x(4)*a+x(2)*x(1)-e*f*x(1)-x(2)*x(2)*x(5)-x(2)*x(5)*x(5)-e*f-f*g;

a=a1+a2;
e=e1+e2;
f=f1+f2;
g=g1+g2;

a1=1;
a2=1;
e1=9;
e2=7;
f1=56;
f2=98;
g1=76;
g2=665;

dx=dx(:);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

然后,在Matlab下面输入:
CODE:
clear all
clc

x0=[1,1,1,1,1,1];
t0=0:0.1:2;
[t,x]=ode45('myfun',[0,10],x0); %?%ode45会自动调整步长
plot(t,x)                         % ?
legend('x(1)','x(2)','x(3)','x(4)','x(5)','x(6)')

结果出错信息




第一:
dx(1)=x(3)-x(2)+x(4)*x(2)-2*x(5)*x(2)-x(2)*x(2)-x(5)-e-f-g;
有错吗?

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

即:
f0 = feval(ode,t0,y0,args{:});   % ODE15I sets args{1} to yp0.
[m,n] = size(f0);
if n > 1
  error('MATLABdearguments:FoMustReturnCol',...
        [funstring(ode) ' must return a column vector.'])
elseif m ~= neq
  msg = sprintf('an initial condition vector of length %d.',m);
  error('MATLABdearguments:SizeIC', ['Solving ' funstring(ode) ' requires ' msg]);
End

三:
Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, ...
即:
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, ...
options, threshold, rtol, normcontrol, normy, hmax, htry, htspan, ...
dataType] = ...
    odearguments(FcnHandlesUsed, solver_name, odeFcn, tspan, y0, ...
                 options, varargin);
nfevals = nfevals + 1;

MATLAB程序总是出错?
出错信息1.jpg


MATLAB程序总是出错?-1
2.jpg


MATLAB程序总是出错?-2
3.jpg

[ Last edited by xiegangmai on 2015-3-13 at 16:40 ]
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

xiegangmai

版主 (职业作家)

我没头衔

优秀版主优秀版主优秀版主


小木虫: 金币+0.5, 给个红包,谢谢回帖
看了看,程序中有几个问题,供参考:
1. function dx=myfun(t,x)中,应先赋值:
CODE:
a1=1;
a2=1;
e1=9;
e2=7;
f1=56;
f2=98;
g1=76;
g2=665;
a=a1+a2;
e=e1+e2;
f=f1+f2;
g=g1+g2;
% syms a e f g a1 a2 e1 e2 f1 f2 g1 g2

2. dx=myfun(t,x)中,x(1) ~ x(6)有6个变量,只有5个方程?无解!
明德厚学、求是创新
2楼2015-03-13 16:48:49
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 wyjjf 的主题更新
普通表情 高级回复 (可上传附件)
信息提示
请填处理意见