Physics problem help!
Show older comments
We were given a problem in my physics class that we are supposed to code, despite not being given much on how to use matlab. I've been at this for hours and I can't seem to figure it out and any type of help will be appreciated.
Problem 3: Oscillation of a Sodium atom in a Sodium-Chloride crystal
Problem: The Sodium-Chloride crystal is an example of a ionic crystal. It consists of alternating positively and negatively charged ions, the Sodium and Chloride atoms respectively. A Sodium atom moves subject to forces from the surrounding ions - and an analysis of the system shows that for small perturbations from the equilibrium configuration, a Sodium ion will experience an acceleration of a = −kx , where k = 0.17×1027s^−2 , where x is the position of the ion measured in meters. Assume that the ion starts at position x0 = 0 time t = 0 with a velocity v0 = 364m/s. (a) Find the time development of x(t). (b) Find the maximum value of x. (c) Find the oscillation time, that is the time it takes until the ion is in the same state as it started in.
2 Comments
James Tursa
on 11 Apr 2018
Supposed to code it how? Using your own written ordinary differential equation code, such as Euler method? Using a built-in integrator such as ode45? Symbolically in MATLAB? Solving by hand?
E.g., see this page for the close form solution:
Joe Worster
on 11 Apr 2018
Answers (1)
James Tursa
on 11 Apr 2018
Edited: James Tursa
on 11 Apr 2018
So, I will give you a start for an Euler scheme. You have two states to keep track of, the position and the velocity. Define two variables for this:
x is the position
v is the velocity
You are given two initial conditions for these states:
x0 = 0 m
v0 = 364 m/s
And a force constant
k = 0.17×10^27 s^−2 <-- I assume this is 10^27 ???
For an arbitrary variable Y, the Euler method of propagating is
Y(t+dt) = Y(t) + (dY/dt) * dt;
So putting the pieces together here is an outline of your code:
% Initial conditions
x0 = 0; % m
v0 = 364; % m/s
k = 0.17e27; % s^−2
n = 1000; % Number of steps to integrate (you will have to experiment with this value)
dt = ________; % You will have to experiment with this value also
% Allocate states
x = zeros(1,n);
v = zeros(1,n);
t = zeros(1,n);
% Initialize first state
x(1) = x0;
v(1) = v0;
t(1) = 0;
% Loop for the integration
for i=1:n-1
x(i+1) = x(i) + ___________;
v(i+1) = v(i) + ___________;
t(i+1) = t(i) + ___________;
end
You need to figure out what goes in the blanks above. The x equation will be based on the derivative of x, which is velocity. The v equation will be based on the derivative of v, which is acceleration. The t equation is just to increment t by dt.
9 Comments
Joe Worster
on 11 Apr 2018
Edited: James Tursa
on 11 Apr 2018
James Tursa
on 11 Apr 2018
Edited: James Tursa
on 11 Apr 2018
You are not integrating enough time. Increase your time.
Also, typically one uses the current state for the derivatives in Euler's method. So the x equation would be:
x(i+1) = x(i) + v(i)*dt;
What are you using for a(i)?
Joe Worster
on 11 Apr 2018
Edited: James Tursa
on 11 Apr 2018
Joe Worster
on 11 Apr 2018
James Tursa
on 12 Apr 2018
Edited: James Tursa
on 12 Apr 2018
It helps here to know the solution in advance to pick appropriate values for dt and n without a lot of trial and error. If you look at the wiki link I posted above, the period of a harmonic oscillator is:
period = T = 2*pi/sqrt(k/m)
In your case you are using an equivalent mass value of 1, so we just get
period = 2*pi/sqrt(k) = 2*pi/sqrt(0.17e27) = 4.82e-13
So, pick dt to make sure you have enough samples per period to make a meaningful integration and plot. This is somewhat arbitrary, but let's just make it 1000. Then
dt = period / 1000;
And if you want to run three full periods, then
n = 3000;
Give these values a try. Note that the period of 4.82e-13 is much larger than your time duration of 2.5e-37. Essentially you are currently only plotting a very small piece of the full period, and that very small piece looks linear.
P.S. Your y label should be 'x[m]', not 'v[m/s]'.
James Tursa
on 12 Apr 2018
Another thing I noticed was these lines:
a = -k*x;
v(i+1) = v(i) + a(i)*dt;
This works, but it looks strange since the a = -k*x part is multiplying k by the entire x vector at each iteration. You don't really need this. All you need is to multiply k by the current x position. E.g.,
a = -k*x(i);
v(i+1) = v(i) + a*dt;
James Tursa
on 12 Apr 2018
@Jim Riggs: Yes, I noticed that. I first advised him to increase his total integration time hoping he would look at that himself, and the latest is I have actually given him appropriate integration times and step sizes to use. So, hopefully he can get everything fixed up now.
Joe Worster
on 12 Apr 2018
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!