Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
02_roots_and_optimization/HW2_4.asv
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
57 lines (43 sloc)
1.58 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%Elj = @(x) 4*2.71E-4*((.2934./x).^12-(.2934./x).^6); | |
%Etotal = @(x) Elj*(xo+dx)-F*dx; | |
%epsilon = 2.71e-4; | |
%sigma = .2934; | |
epsilon = 0.039; % kcal/mol | |
epsilon = epsilon*6.9477e-21; % J/atom | |
epsilon = epsilon*1e18; % aJ/J | |
% final units for epsilon are aJ | |
sigma = 2.934; % Angstrom | |
sigma = sigma*0.10; % nm/Angstrom | |
lennard_jones= @(x,sigma,epsilon) 4*epsilon*((sigma./x).^12-(sigma./x).^6); | |
[x,E,ea,its] = goldmin(@(x) lennard_jones(x,sigma,epsilon),.1,.5) | |
epsilon = 0.039; % kcal/mol | |
epsilon = epsilon*6.9477e-21; % J/atom | |
epsilon = epsilon*1e18; % aJ/J | |
% final units for epsilon are aJ | |
sigma = 2.934; % Angstrom | |
sigma = sigma*0.10; % nm/Angstrom | |
x=linspace(2.8,6,200)*0.10; % bond length in um | |
Ex = lennard_jones(x,sigma,epsilon); | |
[xmin,Emin] = goldmin(@(x) lennard_jones(x,sigma,epsilon),0.28,0.6) | |
plot(x,Ex,xmin,Emin,'o') | |
ylabel('Lennard Jones Potential (aJ/atom)') | |
xlabel('bond length (nm)') | |
Etotal = @(dx,F) lennard_jones(xmin+dx,sigma,epsilon)-F.*dx; | |
N=50; | |
warning('off') | |
dx = zeros(1,N); % [in nm] | |
F_applied=linspace(0,0.0022,N); % [in nN] | |
for i=1:N | |
optmin=goldmin(@(dx) Etotal(dx,F_applied(i)),-0.001,0.035); | |
dx(i)=optmin; | |
end | |
plot(dx,F_applied) | |
xlabel('dx (nm)') | |
ylabel('Force (nN)') | |
dx_full=linspace(0,0.06,50); | |
F= @(dx) 4*epsilon*6*(sigma^6./(xmin+dx).^7-2*sigma^12./(xmin+dx).^13) | |
plot(dx_full,F(dx_full),dx,F_applied) | |
[K,SSE_min]=fminsearch(@(K) sse_of_parabola(K,dx,F_applied),[1,1]); | |
fprintf('\nThe nonlinear spring constants are K1=%1.2f nN/nm and K2=%1.2f nN/nm^2\n',K) | |
fprintf('The mininum sum of squares error = %1.2e \n',SSE_min) | |
plot(dx,F_applied,'o',dx,K(1)*dx+1/2*K(2)*dx.^2) |