bvp4c solution doesn't follow the initial guess?
Show older comments
Hi everyone, thank you for your time.
In my code below (also attached) a differential equation with physical meaning is solved by bvp4c solver.
However, the solution bvp4c finds doesn't follow the initial guess I propose at all, which loses all the physics.
If you run my code you can get the result from bvp4c and a plot of my guess, showing the difference.
clf;
xb=5;
xa=0;
xmesh=linspace(xa,xb,100);
N0=1;
D = 11.32*1E14;
rt = 2.058;
E = 0.01*1E-3*1.6E-19; %eV=J
delta = 9.1E-3*1.6E-19; %eV=J
p=[D rt E delta];
solinit = bvpinit(xmesh,@guess);
options = bvpset('RelTol',1e-3);
sol = bvp4c(@(x,T)bvpfun(x,T,p),@(Ta,Tb)bcfun(Ta,Tb,p),solinit,options);
sxint = deval(sol,xmesh);
T = sxint(1,:);
figure(1); plot(xmesh,imag(T),'-o'); xlabel('x'); ylabel('Imagine part');
hold on
x3=linspace(0,5,50);
y3=((pi*1i/2-atan((0.5*1i)*exp(-(-4i)^(1/2)*x3))));
figure(2); plot(x3,imag((y3)),'-o'); xlabel('x'); ylabel('My guess');
function y = guess(x) % initial guess for y and y'
y=[pi*1i/2-atan((0.5*1i)*exp(-(-4i)^(1/2)*x))
-((2.82843 + 2.82843*1i)*exp(2*(-1)^(3/4)*x))./(-4 + exp(4*(-1)^(3/4)*x))];
end
function dydx = bvpfun(x,T,p)
D=p(1); % nm^2/s
E=p(3); %eV=J
h=1.054E-34; %J*s
A=E/(h*D/2);
dydx = zeros(2,1);
dydx = [T(2);-A*cosh(T(1))]; %dont put constants like A in the first term
end
function res = bcfun(Ta,Tb,p)
E=p(3); %eV=J
delta=p(4); %eV=J
rt = p(2); %tunnel barrier
res = [%-rt*Ta(2)-sinh(1i*pi/2-Ta(1)-atanh(delta/(E+1i*10^(-26))))
Ta(1)-1i
Tb(1)-(pi*1i/2)];
end
6 Comments
Torsten
on 18 Oct 2022
A guess is a guess - it only helps bvp4c to converge. There is no reason to believe that bvp4c will stick to it.
Gary He
on 18 Oct 2022
Torsten
on 18 Oct 2022
Is there a way in matlab to find a solution closer to the guess?
No.
So you think the guess already satisfies your differential equation ? Can you include the paper ?
John D'Errico
on 18 Oct 2022
Edited: John D'Errico
on 18 Oct 2022
The obvious answer is either the initial guess was poor, or you entered the BVP incorrectly in some way. Perhaps one of your constants is wrongly entered. Of course, the code could be wrong too, but it has by now been extensively field tested, making the first two possibilities far more likely.
Gary He
on 18 Oct 2022
Gary He
on 18 Oct 2022
Answers (0)
Categories
Find more on Boundary Value Problems 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!


