- ya(1) corresponds to the value of the function (u) at the boundary (r1).
- ya(2) corresponds to the derivative of the function (u) with respect to (r) at the boundary (r1).
How to solve a symoblic equation with Robin boundary conditions
8 次查看(过去 30 天)
显示 更早的评论
Hello,
I would like to solve a symbolic equation, of the form

with u the function to determine. K and gamma and their numerical values are known.
Solving this, i would like to specify a Robin boundary condition for one of the boundary, i.e.,

where alpha, beta and r1 which are known.
For the other boundary, the condition is simply:

The code I use is the following:
syms u(r)
r1=250e-6;r2=1e-2;K=1e-5;
ode = K*diff(u,r,2) + (K/r)*diff(u,r,1) == u - 10;
Du = K*diff(u,r,1) + (u-1)/2000;
cond1 = u(r2) == 4.8;
cond2= Du(r1) == 0;
conds = [cond1 cond2];
ySol(r) = dsolve(ode,conds);
The problem is that the solution ySol i get in matlab is a function of u(r1) and is therefore not explicit. I get therefore the warning:
eval_fun = matlabFunction(ySol)
"Warning: Function 'u' not verified to be a valid MATLAB function."
when trying to evaluate the function using matlabFunction(ySol).
It seems that the boundary equation of the type
, is a problem to get an explicit solution here.

I have solved the equation numerically using pde toolbox, and the Robin boundary condition is not a problem there.
My question is : do you know a way to solve symbolic equations with this kind of boundary condition ?
Thanks a lot for your help :)
Hugo
0 个评论
回答(1 个)
Ronit
2025-2-28
编辑:Ronit
2025-2-28
Hi Hugo,
When dealing with differential equations that include complex boundary conditions, such as a Robin condition, symbolic solutions can be difficult to obtain explicitly. In these situations, a numerical approach is often more practical. The process begins by converting the second-order differential equation into a system of first-order equations. Then, you define the boundary conditions.
To solve the problem numerically, use a boundary value problem solver like MATLAB's bvp4c or bvp5c. These solvers are designed to handle complex boundary conditions effectively. Once the solver runs, it iterates to find a solution that satisfies both the differential equation and the boundary conditions.
Please review the following code for your reference:
% Define the differential equation as a system of first-order ODEs
function dydr = odefun(r, y, K, gamma)
dydr = [y(2); (y(1) - gamma - K*y(2)/r)/K];
end
% Define the boundary conditions
function res = bcfun(ya, yb, K, alpha, beta, r1, r2)
res = [K*ya(2) - alpha*ya(1) - beta; yb(1) - 4.8];
end
% Initial guess for the solution
init_guess = @(r) [1; 0]; % Adjust as necessary
% Setup the boundary value problem
solinit = bvpinit(linspace(r1, r2, 10), init_guess);
sol = bvp4c(@(r, y) odefun(r, y, K, 10), @(ya, yb) bcfun(ya, yb, K, 1, 0, r1, r2), solinit);
For reference:
I hope it resolves your query!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Equation Solving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!