You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Boundary value problem-bvp4c
2 views (last 30 days)
Show older comments
Hello
I am working on a paper by Di Federico et al 2012, they solved this by Mathematica@. I need to reproduce it in MATLAB and extend it for radial geometry.
Here is the problem :
I am trying to solve an ODE ( has been derived from an PDE by scaling and similarity solution process) which I have two values of it at the end of the interval [0,1] .
I know that as , the function tends to zero .
Also I know that as the derivative equals to .
as "bvp4c" needs the values in two different point, how should I write the residual function "bcfun" for this problem as I do not have two points ?
instead I have information about one end point and the slope near that point
This is the system of first order ODE :
also there is singularity near this point which they handle it by studying the problem in the neighborhood
the solution should have an answer like this :
Accepted Answer
Torsten
on 3 Jul 2023
Use ode45 and integrate backwards:
22 Comments
sepideh
on 4 Jul 2023
Thank you
I saw the link. but there is a problem
in the example to sent to me the end points are known (y0=1) (y0=2.7)
in my case I only know that in y(1)=0 and I dont have any information about the starting point
I just know the slop which is y'= -2/3
Torsten
on 4 Jul 2023
Edited: Torsten
on 4 Jul 2023
Y1 = 0 and Y2 = -2/3 are your initial conditions at x=1 for your system of ODEs. What's the problem ?
And be careful: there is an error in your vector of derivatives: x*Y2 instead of x*Y1 in the numerator of the second component.
sepideh
on 6 Jul 2023
Edited: sepideh
on 6 Jul 2023
clc
clear
xspan= [0,1]
y0=1
[xf,yf]= ode45(@bvpfun,xspan,y0)
xsapn= [1,0]
y0=1e-10
[xr,yr]= ode45(@bvpfun,xspan,y0)
plot(xf,yf,xr,yr)
function dydx=bvpfun(x,y)
dydx= [y(2)
-(3*y(2)^2+x*y(2)+y(1))/(3*y(1))];
end
sepideh
on 6 Jul 2023
eps= 1e-10;
xmesh= linspace(0,1-eps,10);
solinit= bvpinit(xmesh,[1,0]);
sol=bvp4c(@bvpfun,@bcfun,solinit);
plot(sol.x,sol.y,'o')
function dydx=bvpfun(x,y)
dydx= [y(2),-(3*y(2)^2+x*y(2)+y(1))/(3*y(1))];
end
function res=bcfun(~,yb)
res=[yb(2)+2/3
yb(1)-(2/3*eps)];
end
sepideh
on 6 Jul 2023
Edited: sepideh
on 6 Jul 2023
xspan = [1 0];
y0 = [1e-8 -1/3];
fun = @(x,y)[y(2);-(3*y(2)^2+x*y(2)+y(1))/(3*y(1))];
[X,Y] = ode45(fun,xspan,y0);
plot(X,Y(:,1))
hold on
syms F(Y) %analytical solution
F(Y)= 1/6*(1-Y^2);
fplot(F,[0 1],'o')
axis([0 1 0 1])
hold off
thank you very much
now the analytical and numerical results are perfectly match. you helped me a lot
sepideh
on 6 Jul 2023
Edited: sepideh
on 6 Jul 2023
I am working on Gravity Currents and the ensuing ODE has a analytical solution for the shape function as : (see Huppert 1982, Di Federico 2012)
this is the case for sudden or instantaneous release (
for the ODE can not solved analytically
here I made a mistake, actually the slope for this situation is -1/3 not -2/3 because now I am trying to solve the ODE for instantaneous release. the code that you gave me was perfectly match with the analytical solution (I correctted the slope) in this situation
when (constant injection) the ODE becomes :
with the sloe tends to -2/3
this can not solved analytically.
I am going to test the code for this equation now.
sepideh
on 6 Jul 2023
Edited: sepideh
on 6 Jul 2023
xspan = [1 0];
y0 = [1e-8 -1/3];
fun = @(x,y)[y(2);-(3*y(2)^2+x*y(2)+y(1))/(3*y(1))];
[X,Y] = ode45(fun,xspan,y0);
plot(X,Y(:,1))
hold on
syms F(Y)
F(Y)= 1/6*(1-Y^2);
fplot(F,[0 1],'o')
axis([0 1 0 1])
hold on
xspan = [1 0];
y0 = [1e-8 -2/3];
fun = @(x,y)[y(2);-(3*y(2)^2+2*x*y(2)-y(1))/(3*y(1))];
[X,Y] = ode45(fun,xspan,y0);
plot(X,Y(:,1),'--')
hold off
as you can see the constant injection affect the height of shape function (match with our governing equation) , this is what I expected based on literature.
thank you
sepideh
on 9 Sep 2023
Dear Torsten
I am trying to use the code for radial geometry but the numerical solution doesnot match the analytical one.
Would you please take a look at this and help me find out what is the problem? somehow in the mid interval its deviated
the ODE reads:
analytical solution is : (dots)
I used the base that you sent to me for backward method :
% plot analytical solution.
syms F(Y)
F(Y)= 1/8*(1-Y^2);
fplot(F,[0 1],'o')
axis([0 1 0 1])
hold on
% numerical solution for alpha=0
xspan = [1 0];
y0 = [1e-8 -1/4];
fun = @(x,y)[y(2);-(4*y(2)^2+(x)*y(2)+2*y(1))/(4*y(1))];
[X,Y] = ode45(fun,xspan,y0);
plot(X,Y(:,1))
ylabel('\Phi(\zeta)')
xlabel('\zeta')
hold off
sepideh
on 11 Sep 2023
yes you are right. I made a mistake in my modeling.
the correct ODE is:
now there is no residual.
but still there is a problem in the pragh.
xspan = [1 0];
y0 = [1e-10 -1/4];
fun = @(x,y)[y(2);-(2*x*y(1)+x^2*y(2)+4*x*y(2)^2+4*y(1)*y(2))/(4*x*y(1))];
[X,Y] = ode45(fun,xspan,y0);
plot(X,Y(:,1))
Torsten
on 11 Sep 2023
Yo divide by x and y(1). Thus you have to start with something small and different from 0 for y(1) in the y0-vector and you must integrate up to something small and different from 0 for xspan(2) in the xspan-vector.
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)