How do you make an initial guess in bvp4c?
9 次查看(过去 30 天)
显示 更早的评论
I am trying to sovle the following differential equation using bvp4c:

There are issues at the origin... I need to solve here though!
In certain limits you can say
, so I would like to guess this as an initial solution. I tried something like this (xl=0, xr=100 or so):

function [Sxint, xint] =bvp4c_mathworks_Abrikosov_guess(xl,xr)
N = 5000;
xint = linspace(xl,xr,N);
solinit = bvpinit(xint,@guess);
sol4c = bvp4c(@myode,@mybc,solinit);
Sxint = deval(sol4c,xint);
end
function dy = myode(r,y)
k = 5/sqrt(2);
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
function g = guess(x)
k = 5/sqrt(2);
g = tanh(x/k);
end
Is there a way to do this? What do I need to change?
0 个评论
采纳的回答
Torsten
2024-2-5
编辑:Torsten
2024-2-5
xl = 1e-8;
xr = 5;
[Sxint, xint]=bvp4c_mathworks_Abrikosov_guess(xl,xr);
plot(xint,Sxint(1,:))
hold on
M = cell2mat(arrayfun(@(x)guess(x),xint,'UniformOutput',0));
plot(xint,M(1,:))
hold off
function [Sxint, xint] =bvp4c_mathworks_Abrikosov_guess(xl,xr)
N = 500;
xint = linspace(xl,xr,N);
solinit = bvpinit(xint,@guess);
sol4c = bvp4c(@myode,@mybc,solinit);
Sxint = deval(sol4c,xint);
end
function dy = myode(r,y)
k = 5/sqrt(2);
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
function g = guess(x)
k = 5/sqrt(2);
g = [tanh(x/k);1/k*(1-tanh(x/k)^2)];
end
3 个评论
Torsten
2024-2-5
Yes, you solve for f and f', and you have to specify initial profiles for both of them.
So if you specify f0 = tanh(x/k) as initial guess for f, it's natural to use f0' = 1/k*(1-tanh(x/k)^2) as initial guess for f'.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Boundary Value Problems 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!