Boundary condition Problem solving using bvp4c

9 views (last 30 days)
Khoa Ngo
Khoa Ngo on 15 Apr 2015
Commented: Torsten on 16 Apr 2015
I was given this ODE problem:
g" + (1/2a) g' n = 0, where n = x/t^1/2, g(n) = T (x,t) BC1: g(0) = Ts = 100; BC2: g(infinity) = Ti = 10; Find g(n) and plot
I created 2 m.file
1)
function [ eqn ] = eqn1( n,g )
%Material Iron
rho = 7897;
Cp = 452;
k = 73;
alpha = k/(rho*Cp);
eqn =[g(2);(-n*g(2))/(2*alpha)];
end
2) function [ BCs ] = BC(g_0,g_inf)
Ts = 100;
Ti = 10;
BCs =[g_0(1)-Ts,g_inf(1)-Ti];
end
Then solution I tried to use bvp4c to solve for the equation
sol=bvpinit(linspace(0,1,25),[0 1]);
sol=bvp4c(@eqn1,@BC,sol)
I got this : Undefined function 'eqn1' for input arguments of type 'double'.
Error in bvparguments (line 106) testODE = ode(x1,y1,odeExtras{:});
Error in bvp4c (line 130) [n,npar,nregions,atol,rtol,Nmax,xyVectorized,printstats] = ...
Please Point out where did i do wrong and how can i fix it. THanks in advance.

Answers (2)

Torsten
Torsten on 15 Apr 2015
You arranged your code as
function main
solinit=bvpinit(linspace(0,1,25),[0 1]);
sol=bvp4c(@eqn1,@BC,solinit)
function [ eqn ] = eqn1( n,g )
%Material Iron
rho = 7897;
Cp = 452;
k = 73;
alpha = k/(rho*Cp);
eqn =[g(2);(-n*g(2))/(2*alpha)];
function [ BCs ] = BC(g_0,g_inf)
Ts = 100;
Ti = 10;
BCs =[g_0(1)-Ts ; g_inf(1)-Ti];
?
Best wishes
Torsten.

Khoa Ngo
Khoa Ngo on 16 Apr 2015
For the same problem, now I solve using dsolve('D2g+t*Dg/(2*a)=0') and it gave me some crazy equation: g(t)=((2^(3/4)*exp(t^2/(4*a))*(t^2/a)^(1/4)*(C44 + C45*pi^(1/2) - C45*pi^(1/2)*erf(((2^(1/2)*(t^2/a)^(1/2) ))/2))))/(2*t^(1/2)*exp(t^2/(2*a))^(1/2) )
Basically, I cant input the boundary condition g(0) and g(inf) to solver for C44 and C45.
Please help.
  1 Comment
Torsten
Torsten on 16 Apr 2015
I get as solution
g(x)=Ts+(Ti-Ts)*erf(x/(2*sqrt(a))).
where erf is the error function.
Best wishes
Torsten.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!