4th order ODE, boundary conditions problem
24 次查看(过去 30 天)
显示 更早的评论
I am trying to solve a 4th order linear ODE with boundary conditions. I'm just learning to use bvp4c. The code is the following:
function mat4bvp
solinit = bvpinit(linspace(0,1,5),[1 0 0 0]);
sol = bvp4c(@mat4ode,@mat4bc,solinit);
x = linspace(0,1);
y = deval(sol,x);
plot(x,y(1,:));
function dxdy = mat4ode(x,y);
eps=0.1;
dp=[y(2)
y(3)
y(4)
2.*pi^2.*y(3) +(1./eps).*y(2)-pi^4.*y(1)];
function res = mat4bc(ya,yb);
res=[ya(1)
yb(1)
yb(3)
yb(4)];
But I get the following error message:
??? Error using ==> vertcat?CAT
arguments dimensions are not consistent.
Error in ==> 4odecode>mat4ode at 13
dp=[y(2)
?? Error in ==> bvparguments at 122
testODE = ode(x1,y1,odeExtras{:});
Error in ==> bvp4c at 120
[n,npar,nregions,atol,rtol,Nmax,xyVectorized,printstats] =
...
Error in ==> 4odecode at 4?
sol = bvp4c(@mat4ode,@mat4bc,solinit);
0 个评论
采纳的回答
Andrew Newell
2011-2-4
In the assignment to dp (which, by the way, should be dxdy), the fourth line has a space in it which MATLAB thinks is separating two elements. With a couple more corrections, the code is
function mat4bvp
solinit = bvpinit(linspace(0,1,5),[1 0 0 0]);
sol = bvp4c(@mat4ode,@mat4bc,solinit);
x = linspace(0,1);
y = deval(sol,x);
plot(x,y(1,:));
function dxdy = mat4ode(~,y)
eps=0.1;
dxdy=[y(2)
y(3)
y(4)
2.*pi^2.*y(3)+(1./eps).*y(2)-pi^4.*y(1)];
function res = mat4bc(ya,yb)
res=[ya(1)
yb(1)
yb(3)
yb(4)];
0 个评论
更多回答(3 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!