Why do I receive Jacobian singular error while solving second order differential equation with boundary conditions?
Show older comments
I am trying to solve the following second order differential equation: ηF''-F'+FF'= 0; The boundary conditions being F(0)=0 , F'(0)=0 and F'(inf)=0.
This is my code:
solinit = bvpinit(linspace(0,10,100),@guess);
solve = bvp4c(@f,@bc,solinit);
plot(solve.x,solve.y(1,:))
xlabel('eta')
ylabel('F')
function dydx = f(x,y)
dydx = [y(2); (1/(x)).*(y(2)-(y(1).*y(2)))];
end
function output = bc(ya,yb)
output = [ya(2)-1; yb(2)];
end
function y = guess(x)
y = [cos(x) -sin(x)];
end
Any help regarding this would be greatly appreciated! Thank you!
Accepted Answer
More Answers (1)
I understand that you are receiving Jacobian singular error while solving second order differential equation with boundary conditions. Here is the modified code you can try:
% Set up the initial mesh and initial guess
solinit = bvpinit(linspace(0,10,100), @guess);
% Solve the boundary value problem
solve = bvp4c(@f, @bc, solinit);
% Plot the solution
plot(solve.x, solve.y(1,:))
xlabel('eta')
ylabel('F')
% Define the differential equation as a system of first-order ODEs
function dydx = f(x,y)
dydx = [y(2); (1/(x+eps)).*(y(2)-(y(1).*y(2)))]; % Add eps to avoid division by zero
end
% Define the boundary conditions
function res = bc(ya,yb)
res = [ya(1); yb(2)]; % F(0) = 0, F'(inf) = 0
end
% Initial guess for the solution
function y = guess(x)
% Use a cubic polynomial that satisfies the boundary conditions
y = [(x/10).^3; 3*(x/10).^2/10];
end
Thanks,
Ayush
Categories
Find more on Equation Solving 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!
