4th order ODE, boundary conditions problem

21 Ansichten (letzte 30 Tage)
Gualtiero
Gualtiero am 4 Feb. 2011
Kommentiert: MINATI am 12 Mai 2019
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);

Akzeptierte Antwort

Andrew Newell
Andrew Newell am 4 Feb. 2011
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)];

Weitere Antworten (3)

Gualtiero
Gualtiero am 4 Feb. 2011
The solution seem to be extremely sensitive to the form that I give to solinit. Is there any general method to impose a suitable solinit?

Gualtiero
Gualtiero am 4 Feb. 2011
in particular, my 4th order ode is
y'''' -2*(pi^2)*y''-(1/eps)*y'+(pi^4)*y=0
b.c.: y(0)=y(1)=0; y''(1)=0; y'''(1)=0
it is not trivial to me to pose an initial guess that would give me the right answer...

Gualtiero
Gualtiero am 4 Feb. 2011
edit: an initial guess that satisfy the b.c. is
y=sin(x*pi)*cos(x*pi)+2*(pi^3)*(-(1./3)*(x^3)+(x^2)+(2./3)*x)
However, changing the number of meshpoints in linspace changes drastically the shape of the solution...
  1 Kommentar
MINATI
MINATI am 12 Mai 2019
How do you know the initial guess as mentioned

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Numerical Integration and Differential Equations finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by