Piecewise MATLAB ode45 problem for Lennard-Jones

In summary, the conversation discusses a program written in MATLAB that deals with collisions between particles and hard boundaries. The program uses the Lennard-Jones equation of motion function and ode45 to integrate over a specific time interval. However, there is an issue with data for T1 and U1 not being produced. The program is also trying to calculate the displacement of two particles after the collision with walls of length 10 units. The conversation also mentions using Microsoft Word files for reference and each particle having a radius of 1 unit. The code is provided but it is recommended to use code tags when posting code. Additionally, there is a discussion about the program's handling of collisions and the condition for the collision never being met, resulting in T
  • #1
Adrian Soo
8
0
I could run the MATLAB codes but the main issue is that data for T1 and U1 could not be produced. I am currently trying to calculate the displacement of two particles after the collision with walls with length of 10 units.

Here are the codes. If you don't understand its context, you can refer to the Microsoft word files I posted. Note that each particle HAS A RADIUS OF 1 UNIT.​
================================================================================
Lennard-Jones's equation of motion function

function du = lennardJones(~,u)

du = zeros(8,1);

du(1) = u(2);
du(2) = -24*( u(1) - u(3) )/( ( u(1) - u(3) )^2 + ( u(5) - u(7) )^2 )^7 + 24*( u(1) - u(3) )/( ( u(1) - u(3) )^2 + ( u(5) - u(7) )^2 )^4;
du(3) = u(4);
du(4) = -24*( -u(1) + u(3) )/( ( u(1) - u(3) )^2 + ( u(5) - u(7) )^2 )^7 + 24*( -u(1) + u(3) )/( ( u(1) - u(3) )^2 + ( u(5) - u(7) )^2 )^4;
du(5) = u(6);
du(6) = -24*( u(5) - u(7) )/( ( u(1) - u(3) )^2 + ( u(5) - u(7) )^2 )^7 + 24*( u(5) - u(7) )/( ( u(1) - u(3) )^2 + ( u(5) - u(7) )^2 )^4;
du(7) = u(8);
du(8) = -24*( -u(5) + u(7) )/( ( u(1) - u(3) )^2 + ( -u(5) + u(7) )^2 )^7 + 24*( -u(5) + u(7) )/( ( u(1) - u(3) )^2 + ( u(5) - u(7) )^2 )^4;================================================================================
clear all

t0 = 0; % Initial time
deltat = 0.1; % Step size of time
tend = 10; % Final time
u = [4,1,6,-1,1,0,1,0]; % Initial conditions for Lennard-Jones Potential
n = (tend - t0)/deltat; % for 'for' loops
t1 = t0; % Initialise t1 to t0
r = 1;

for i = 1 : n - 1

t2 = t1 + deltat; % Increment in time
options = odeset('RelTol',1e-8,'AbsTol',[1e-8 1e-8 1e-8 1e-8 1e-8 1e-8 1e-8 1e-8]);
[T,U] = ode45(@lennardJones,[t1 t2],u,options); % ode45 applied on LennardJones


if U(1) <= 1 && U(3) >= 9 %When particle collides with the wall at the distance of 9 units on the right
% and 1 unit on the left
clear t1 t2 deltat
t1 = 4.1; % t1 indicates the time it collides with the solid wall
deltat = 0.1; % increment in time
t2 = 10;
k = (t2 - t1)/deltat; %for 'for' loops
u1 = [1,1,9,-1,1,0,1,0]; %initial condition changes after colliding with walls
newtime = 0;

for j = 1:k
newtime = newtime + deltat;
[T1,U1] = ode45(@lennardJones,[t1 newtime],u1,options);
end

end

end

plot(T,U,T1,U1,'o')
============================================================================

output :
Undefined function or variable 'T1'.

Error in hardBoundary (line 37)
plot(T,U,T1,U1,'o')
 

Attachments

  • Chapter 5 Lennard Jones Potential.docx
    37.6 KB · Views: 986
  • Chapter 8 Hard Boundary.docx
    22.7 KB · Views: 329
  • #3
Do you mean that the post can't be comprehended?
 
  • #4
Greg Bernhardt said:
This is an automated courtesy bump.
This message is sent automatically to new posts that do not have any replies after one week.

I don't understand how your program is supposed to deal with collisions. It seems to be integrating over a certain time interval, and then come back to an arbitrary point in time (t=4.1) if there is a collision. Could you describe in more details?

Also, please use code tags when posting code: [C O D E] Some code here [/C O D E] (without spaces in CODE).
 
  • #5
Basically, t = 4.1 s means that the particle collides with the hard boundary by using ode45.
 
  • #6
Adrian Soo said:
Basically, t = 4.1 s means that the particle collides with the hard boundary by using ode45.
How do you know?

As for your original problem: the condition
if U(1) <= 1 && U(3) >= 9
is never met, hence T1 is never defined.
 

FAQ: Piecewise MATLAB ode45 problem for Lennard-Jones

1. What is the Lennard-Jones potential in the context of the piecewise MATLAB ode45 problem?

The Lennard-Jones potential is an intermolecular potential that describes the interaction between two particles in a system. In the context of the piecewise MATLAB ode45 problem, it is used to model the forces between particles in a system and is solved using the ode45 function.

2. How is the Lennard-Jones potential implemented in MATLAB for the piecewise ode45 problem?

The Lennard-Jones potential is typically implemented in MATLAB using the following formula: V(r) = 4 * epsilon * [(sigma/r)^12 - (sigma/r)^6], where epsilon and sigma are parameters that depend on the specific system being modeled. This potential function is then used in the ode45 function to solve for the forces between particles in the system.

3. What are the advantages of using a piecewise approach in solving the Lennard-Jones potential in MATLAB?

Using a piecewise approach in solving the Lennard-Jones potential in MATLAB allows for a more accurate and efficient solution, as it takes into account any discontinuities or changes in the potential function. This approach also allows for different parameters to be used in different regions of the system, making it more versatile for modeling complex systems.

4. How can I ensure the accuracy of my results when using the piecewise MATLAB ode45 solver for the Lennard-Jones potential?

To ensure the accuracy of your results, it is important to carefully choose the parameters and step size used in the ode45 function. It is also recommended to check for convergence by comparing results obtained with different step sizes. Additionally, checking the energy conservation of the system can also help to verify the accuracy of the results.

5. Can the piecewise MATLAB ode45 solver be applied to other potential functions besides the Lennard-Jones potential?

Yes, the piecewise ode45 solver can be applied to other potential functions besides the Lennard-Jones potential. This approach is commonly used in solving systems with discontinuous or piecewise-defined potentials, such as the Morse potential or the Buckingham potential. However, the specific implementation may vary depending on the potential function being used.

Similar threads

Replies
10
Views
2K
Replies
8
Views
2K
Replies
10
Views
2K
Replies
2
Views
2K
Replies
1
Views
2K
Replies
2
Views
3K
Back
Top