I have a system of differential equations as follows:
β*M*L^2*D[Θ[i,t],{t,2}]=M*g*μ*L*(-Sin[Θ[i,t]])+τ[Θ[i+1,t],Θ[i,t]], (*for i=1*)
β*M*L^2*D[Θ[i,t],{t,2}]=M*g*μ*L*(-Sin[Θ[i,t]])+τ[Θ[i-1,t],Θ[i,t]]+τ[Θ[i+1,t],Θ[i,t]], (*for i between 1 and n-1*)
β*M*L^2*D[Θ[i,t],{t,2}]=M*g*μ*L*(-Sin[Θ[i,t]])+τ[Θ[i-1,t],Θ[i,t]], (*for i=n*)
Basically, what the equation describes is a series of coupled oscillators from 0 to n, with the i^th oscillator being connected to the (i-1)^th and (i+1)^th ones with a spring. τ[Θ[j],Θ[i]] describes the torque exerted by the j^th oscillator on the i^th.
Edit: My initial conditions for the systems are as follows.
- Initially, at time
t=0, all the oscillators have:- an angular position of 0, that is,
Θ[i,0]=0 for all i from 0 to n - and an angular velocity of 0, that is
D[Θ[i,t],{t,1}]=0 at t=0 for all i from 0 to n
- an angular position of 0, that is,
- Now, what I do next is to apply a force on the first oscillator causing it to accelerate and follow a certain path of motion over a specific initial time interval. For example, the force that I apply could cause it to complete to full rounds from time
t=0 to 20; that is, theΘ[0,t]=t/10*2π from t=0 to t=20. As I apply this force, (some of) the other oscillators will move too as the first oscillator will exert a force on them through the spring which connects the oscillators. - Finally, after time
t=20, I no longer apply an external force on any of the oscillators and just allow it to oscillate based on the relations found in the differential equations.
If you're interested to see all the function definitions and the constants, they can be found below:
(* providing values for all our variables. these variables describe one particular set of coupled oscillators *)
M=0.1;
L=0.2;
β=1;
μ=1;
k=100;
η=0.3;
γ=0.2;
α=1;
g=9.81
(* defining the torque τ. funcf and funcg are only used to make the expression for τ simpler.*)
funcg=(1-η/(2(1-Cos[#1-#2])+(γ/α)^2)^0.5)&;
funcf=#+Abs[#]&;
τ=Sin[#1-#2]*k*L^2*funcf[funcg[#1,#2]]&;
Edit: Since I was solving a physics question, I forgot to state that what I meant by g in the equations was the gravitational acceleration on earth 9.81 and nothing related to the function g which I was using as an intermediate function to make my expression of τ less complicated. I've modified this by writing the function g as funcg.
After some work, I realized that the method suggested below of using nodes helped to simplify the code a great deal. Thanks, @Spawn1701D.
Mgshould progably beM*gorM g), the comments miss a*)and the part about the initial/boundary conditions is still not clear. Isn't the angle of the first oscillator a fixed function so that it isn't a dependent variable anymore? You'll still need to fix the initial conditions for the others, then. If you have a solution involvingWhile, why don't you post it so we have something to start with? – Albert Retey Mar 12 '13 at 13:18g. With my rephrased question, the way in whichgis written in his answer isn't aligned with what I actually need. I've voted his answer up as useful, nevertheless. – Vincent Tjeng Mar 12 '13 at 15:40n-1oscillators andΘ[0,t]=t/10*2πfixed (Θ[0,t]then isn't a dependent variable anymore). Then use the final states of that solution as initial conditions of another call toNDSolvefor the full system withnoscillators for20<t<tmax. Does that make sense? – Albert Retey Mar 12 '13 at 22:43