필터 지우기
필터 지우기

how to solve a higher order boundary conditioned differential equation with matlab function

조회 수: 2 (최근 30일)
I'm trying to solve a boundary value condition problem with matlab bvp4c function. But I get warning and it doesn't give correct solution.
my equation is d4y/dx4=C/(ax^2 -y)^2 ,C and a are constant , my warning content is following below
Warning: Unable to meet the tolerance without using more than 2500 mesh points.
The last mesh of 2152 points and the solution are available in the output argument.
The maximum residual is 9.25647e+11, while requested accuracy is 0.001.
my code:
clc;clear
solinit = bvpinit([0,200],[1,1,1,1]);
sol = bvp4c(@deriv,@bcs,solinit);
plot(sol.x,sol.y)
function dydx = deriv(x,y)
c=1;a=1;
dydx = [y(2)
y(3)
y(4)
(c/(a*x.^2 -y(1)).^2)];
end
function res = bcs(ya,yb)
res = [ ya(1)
ya(2)
yb(3)
yb(4)];
end
I don't know what is its reason?!
thanks in advance for your helping

답변 (1개)

Star Strider
Star Strider 2021년 11월 14일
This now runs.
One problem was that ‘deriv’ is actually a reserved name, so I changed it. Also the ‘guess’ function was incorrectly coded, and ‘xmesh’ needs to be a vector of more than two elements.
Try this —
xmesh = linspace(0, 200, 5000);
guess = @(x) [(x+1); -(x+1); (2-x); (2+x)];
solinit = bvpinit(xmesh,guess);
sol = bvp4c(@bvpderiv, @bcs,solinit);
Warning: Unable to meet the tolerance without using more than 2500 mesh points.
The last mesh of 5000 points and the solution are available in the output argument.
The maximum residual is 343.374, while requested accuracy is 0.001.
figure
plot(sol.x,sol.y)
grid
legend(string(Subs), 'Location','best')
function dydx = bvpderiv(x,y)
c=1;a=1;
dydx = [y(2)
y(3)
y(4)
(c/(a*x.^2 -y(1)).^2)];
end
function res = bcs(ya,yb)
res = [ ya(1)
ya(2)
yb(3)
yb(4)];
end
If the eventual desire is to have ‘a’ and ‘C’ as arguments to ‘bvpderiv’, rather than hard-coding them, code it as —
function dydx = bvpderiv(x,y,a,c)
dydx = [y(2)
y(3)
y(4)
(c/(a*x.^2 -y(1)).^2)];
end
and then call it as —
@(x,y)bvpderiv(x,y,a,c)
with the parameters previously defined in the workspace.
.

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by