看看这个代码错在哪里?
% FUN2.M 带有数据集合的时变微分方程的例子functionxdot = fun2 ( t, x, beta, omega, T, P )
pt = interp1 ( T, P, t );
xdot (2 ) = beta * x (2 ) – omega^2 * x (1) + pt ;
xdot (1 ) = x (2 );
xdot = xdot ( : );% 使得xdot是一列
% fun2.m 结束
在MATLAB中采用如下的形式调用这个函数:
beta = .1 ;
omega = 2 ;
A = .1 ;
w0 = 1.3 ;
theta = pi /4 ;
X0 = [ 0 ;1];
t0 = 0 ;
tf = 20 ;
T = t0 – eps : 0.1 : tf + theta +eps ;
P = A.* sin(w0 .*T –theta );
[ t, y ] = ode23 ( @ fun2 , [ t0, tf ], X0, [ ], theta, omega, T, P );
plot ( t, y (:,1));
hold on;
plot(t,y(:,2),'g');
运行提示错误:
??? T = t0 – eps : .1 : tf + theta +eps ;
|
Error: Missing variable or function. T = t0 – eps : 0.1 : tf + theta +eps ;
xdot (2 ) = beta * x (2 ) – omega^2 * x (1) + pt ;
两个式子的减号不对!
我试了一下,盖了之后就好了 非常感谢,我说怎么老找不到错误呢
页:
[1]