Mass spring system equation help
조회 수: 25 (최근 30일)
이전 댓글 표시
I am good at Matlab programming but over here I am stuck in the maths of the problem, I am dealing with the differential equation of spring mass system mx’’+cx’+kx=0 where x’’=dx2/dt2 and x’=dx/dt. I have the values of mass and I also have the array of time and x i.e x is given for a particular value of time so I can find x’’ and x ‘ easily. I am stuck at what method to apply to find the value of c and k. I can program any method but have searched several books but didn’t get how to find c and k. If I get to know the method I can program it easily.
댓글 수: 0
채택된 답변
Star Strider
2012년 8월 8일
편집: Star Strider
2012년 8월 8일
I suggest you write an objective function containing your differential equation that would integrate the differential equation, then do curve-fitting of x(t) with nlinfit or lsqcurvefit.
I have provided an objective function here that may work for you. You do not have to pass the parameters specifically to DifEq. It has access to them in the function space. This code assumes all variables and parameters are column vectors.
function X = SMD(B, t, m) % ‘SMD’ for ‘Spring-Mass-Damper’
% B = parameter and initial conditions column vector (unless you want to
% supply the initial conditions in this function rather than passing
% them as parameters).
X0 = B(3:4);
% This gives you the option of passing the last two entries of the
% parameter vector as the initial values of your ODE. In this case, the
% curve-fitting function will also fit the initial conditions as well as
% Kd and Ks. If you don't want the initial conditions to be parameters,
% B becomes [2 x 1] and you define X0 as whatever you like in the
% function.
[T,X] = ode45(@DifEq, t, X0);
function xdot = DifEq(t, x)
% B(1) is the coefficient of viscous friction (‘damper’), Kd;
% B(2) is the spring constant, Ks;
xdot = zeros(2,1);
xdot(1) = x(2);
xdot(2) = -x(1)*B(2)/m -x(2)*B(1)/m;
end
X = xdot(:,2); % Assumes ‘xdot’ is a [N x 2] matrix where N = length(t)
end
I've had success with this general approach in several situations. You may have to experiment with it a bit to fit your particular situation. See Passing Extra Parameters for details in passing the mass m to SMD, or you can define m in the function if it never changes. If you do, then remove it from the SMD argument list.
댓글 수: 2
추가 답변 (3개)
Sumit Tandon
2012년 8월 8일
I feel that if you can calculate the values of x' and x'', then you could take a couple of sets of x, x' and x'' and get a system of linear equation of the form Ax - B = 0.
Any other ideas?
Greg Heath
2012년 8월 9일
There appears to be 2 straightforward approaches:
1. For c1=c/2m, k1=k/m and sufficiently small dt(i) = t(i)-t(i-1)
a. Obtain an inhomogeneous system of linear equations for C = [c1 ; k1] by converting the differential equation to a difference equation in x(i).
b. Obtain the solution to A*C=B via C = A\B.
2. Use NLINFIT or LSQCURVEFIT to estimate c1, k1, A and B from the form of the exact solution
x(i) = exp(-c1*t(i)) * ( A * cos( sqrt(c1^2-k1) * t(i))
+ B * sin( sqrt(c1^2-k1) * (t(i) )
However, since the equation is linear in A and B, a two step estimation of [c1 ; k1 ] and [ A B] might be useful.
Hope this helps.
Greg
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!