Hi everybody!
I wrote a code that solves the following problem:
This is a 2nd order ode and the dependant variable here is rho (tilde) and the independant variable is x (tilde). K (tilde) and B (tilde) are both parameters. The boundary conditions are:
The code is:
clear allclc%Shooting Method for Non-Linear ODE
k=3.25e8; %Debye length - needs to be calculated.
D=4e-9; %separation distance
y0=1; %i.c
ICguess_on_target=fzero(@(x) bar_res(x), 0.25);[x,y]=ode45(@bar_density,[0,k.*D],[y0 ICguess_on_target]);plot(x,y(:,1));xlabel('\kappaD');ylabel('$\tilde{\rho}$','Interpreter','latex')title('$\tilde{\kappa}=\tilde{B}=1$','Interpreter','latex'); function dydx=bar_density(x,y)kdim=1;Bdim=1;dydx=[y(2);2.*Bdim./kdim.*y(1)+kdim.^(-1).*log(y(1))-Bdim];endfunction r=bar_res(IC_guess)y0=1;yf=1;k=3.25e8;D=4e-9;[x,y]=ode45(@bar_density,[0,k.*D],[y0 IC_guess]);r=y(end,1)-yfend
This works just fine and I'm getting great results and plots of rho(tilde) as a function of x(tilde). Now I want to run the code in a loop and vary the parameters K (tilde) and B (tilde). For instance I would like to get 6 plots of rho(tilde) as a function of x(tilde) for 6 different sets of K (tilde) and B (tilde). I have been trying to insert a for loop inside the code but I'm obviously doing it wrong.
I would appreciate some help guys.
Thanks,
Roi
Best Answer