# File:    ex5matlab1.m
# Purpose: solves task 1.a) on exercise sheet 5: domain wall for small kappa
# Author:  Sarah B. Etter, 22 October 2014


function [sol]= nofield_solver(h,gval)


%set up plotter
hold on
grid on


%SOLVER

%options
options = bvpset('NMax',1000,'RelTol',1e-3,'AbsTol',1e-6,'Stats','on');

%different choice of guess
if (gval==1)
    solguess = bvpinit(linspace(0,h,100), @guess1);
    fplot(@guess1,[0,5],'r-') %plotting the phase
elseif (gval==2)
    solguess = bvpinit(linspace(0,h,100), @guess2);
	fplot(@guess2,[0,5],'r-') %plotting the phase
else
    fprintf('Not a valid guess')
end

%solver
sol = bvp4c(@sinegordon,@bvcurrent,solguess,options) %bvp solver

%plotting the solution
plot(sol.x,sol.y(1,:),'g.') %plotting the order parameter
plot(sol.x,sol.y(2,:),'c.') %plotting the order parameter


%BOUNDARY VALUE PROBLEM

%setting up the equations
function dfdx = sinegordon(x,f)
global k;

dfdx(1)=f(2);
dfdx(2)=-f(1)+f(1)*f(1)*f(1);

%setting up the boundary conditions
function bv = bvcurrent(ya,yb)

bv(1)=ya(1);
bv(2)= yb(1)-1;


%GUESS

%setting up the guess, using the known solution
function g=guess1(x)

g(1)=tanh(x/sqrt(2));
g(2)=1/cosh(x/sqrt(2))^2/sqrt(2);

%setting up the guess, using just a constant guess
function g=guess2(x)

g(1)=1;
g(2)=0;


