M文件:
function xprime=test(a,t,x)
global a
xprime=a*cos(t)/(2*x-2);
当前窗口:
>> a=3;
>> [t,x]=ode45('test',[0,2*pi],3)
Warning: The value of local variables may have been changed to match the
globals. Future versions of MATLAB will require that you declare
a variable to be global before you use that variable.
> In C:\MATLAB6p5\work\test.m at line 2
In C:\MATLAB6p5\toolbox\matlab\funfun\private\odearguments.m at line 104
In C:\MATLAB6p5\toolbox\matlab\funfun\ode45.m at line 155
??? Error using ==> /
Matrix dimensions must agree.
Error in ==> C:\MATLAB6p5\work\test.m
On line 3 ==> xprime=a*cos(t)/(2*x-2);
Error in ==> C:\MATLAB6p5\toolbox\matlab\funfun\private\odearguments.m
On line 104 ==> f0 = feval(ode,t0,y0,args{:});
Error in ==> C:\MATLAB6p5\toolbox\matlab\funfun\ode45.m
On line 155 ==> [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, args, ...
我的想法,是定义一个全局变量a,然后在每次调用m文件即函数test时,可以取不同的值a,然后调用ode45来解,当然如果
只取少量的不同的a值,那可以多写几个m文件,问题是如果需要很多个不同的a值,然后继续调用solver ode45来解函数test呢??希望大家能提点意见,谢谢!!