![]() |
[求助]关于解微分方程参数传递
一般来说,要求解微分方程,首先定义一个方程,然后调用ode(例如ode45)就可以了。例如,我要求解Duffing方程,首先定义微分方程:
function du=duffin(t,x) f=1; alpha=1; beta=10; gama=100; omiga=3.5; epsilon=0.1; du=[ x(2);... epsilon-alpha*x(2)+beta*x(1)-gama*x(1)*x(1)*x(1)+f*cos(x(3));... omiga]; 然后调用 [t,x]=ode45('duffin',[0,10],[0.1,0.1,2]) 就可以得到不同时刻t对应的x的解。 现在我的问题是:在Duffing方程定义中,我需要epsilon是一个变量,而不是常量,那么应该如何传递参数epsilon呢?也就是说,我在另一段程序中调用ode45解方程,而epsilon的值是在这段程序中动态给出的,如果传递这个epsilon的值呢? 谢谢解答啊~ |
回复: 求助各位:关于解微分方程参数传递
solver(odefun,tspan,y0,options,p1,p2。。。。)
p1 p2就是可以参递给odefun的参数 |
回复: 求助各位:关于解微分方程参数传递
感谢版主啊~
我还是不知道怎么用:ft: ,是不是传递参数epsilon给duffin方程,我先这样定义duffin方程: function du=duffin(t,x,epsilon) ... 解方程的时候使用[t,x]=ode45('duffin',tspan,init,Options,0.1)? 但是不行啊,是不是问题出在用odeset设置options上,但从帮助手册没看出什么啊 :cry: |
回复: 求助各位:关于解微分方程参数传递
回复1楼问题:
function du=duffin(t,x) 变成 function du=duffin(t,x,epsilon) 然后把“epsilon=0.1;”去掉,就可以了 |
回复: 求助各位:关于解微分方程参数传递
[QUOTE=fanxing39;14655]回复1楼问题:
function du=duffin(t,x) 变成 function du=duffin(t,x,epsilon) 然后把“epsilon=0.1;”去掉,就可以了[/QUOTE] 这样好像不行啊 调用solver的时候怎么做? 我用 [t,x]=ode45('duffin',[0,10],[0.1,0.1,2],options,0.1) 给出错误提示 ??? Error using ==> duffin Too many input arguments. Error in ==> D:\MATLAB6p5\toolbox\matlab\funfun\private\odearguments.m On line 104 ==> f0 = feval(ode,t0,y0,args{:}); Error in ==> D:\MATLAB6p5\toolbox\matlab\funfun\ode45.m On line 155 ==> [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, args, ... 其中,duffin的定义如你所说:ft: |
回复: 求助各位:关于解微分方程参数传递
[t,x]=ode45('duffin',[0,10],[0.1,0.1,2],[options,0.1])
这样可以不? |
所有时间均为北京时间。现在的时间是 05:01。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.