![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1631526/image.png)
Singular Jacobian using bvp4c
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I know similar questions have been asked, but I am wondering if there any tricks to help out here. I've tried changing variables, but the divergence just moves around...
I am trying to solve a second order equation, given in the screen shot below, and the associated code is attached:![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1607371/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1607371/image.png)
I did not impose the condition f>=0, so maybe that is my issue? The hyperbolic tanh might also be a good initial guess, but I was relying on the Sxint = deval() to get me started. Any obvious problems? Thanks in advanced for any help!
xl = 0;
xr = 10;
[Sxint, xint] =bvp4c_mathworks_Abrikosov(xl,xr);
plot(xint,Sxint)
function [Sxint, xint] =bvp4c_mathworks_Abrikosov(xl,xr)
N = 500;
xint = linspace(xl,xr,N);
solinit = bvpinit(xint,[0 0]);
sol = bvp4c(@myode,@mybc,solinit);
Sxint = deval(sol,xint);
end
function dy = myode(r,y)
k = 1/sqrt(1.8);
dy(1,1) = y(2);
dy(2,1) = k^2*(y(1)^2-1)*y(1)+y(1)/r^2-y(2)/r;
end
function res = mybc(ya,yb)
res = [ya(1)
yb(1)-1];
end
0 Kommentare
Antworten (1)
Neelanshu
am 29 Feb. 2024
Hello Marcus,
I understand that you're encountering the "Singular Jacobian using bvp4c" error while attempting to solve a boundary value problem.
Upon inspecting the code, it appears that the issue arises when the function 'myode' is called with the value of 'r' being zero, as shown:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1631526/image.png)
This results in the computation of 'dy(2,1)' to be 'NaN' because it involves division of zero by zero, which leads to the error you're experiencing. To rectify this, you should either initialize 'r' with a non-zero value or adjust the formula used to compute 'dy(2,1)' to handle the case when 'r' is zero.
Hope this helps.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Boundary Value Problems finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!