bvp4c solution doesn't follow the initial guess?

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

A guess is a guess - it only helps bvp4c to converge. There is no reason to believe that bvp4c will stick to it.
Yeah, you're right. Is there a way in matlab to find a solution closer to the guess? That guess is verified in other papers, so I'm thinking matlab should be able to follow it numerically.
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 ?
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.
Without going into too much detail, the solution for theta is found in the first paper:
it should also correspond to the equation below in the second paper, qualitatively:
(cited from papers
In my codes the known solution is used as the guess. I notice that bvp4c seems to use only the left part of the guess, where the value in Y-axis increases from 1 to around 1.6. Maybe the solver can generate another solution, if I input the initial guess in other manner? I see people asking a similar question, wishing to use an array of points as an initial guess:
https://www.mathworks.com/matlabcentral/answers/142088-initial-guess-for-bvp4c?s_tid=srchtitle
Thank you Johm, I'll try to vary the numbers in the initial guess. The boundary conditions are actually deliberately set to matcth the guess.

Sign in to comment.

Answers (0)

Asked:

on 18 Oct 2022

Commented:

on 18 Oct 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!