Mass spring system equation help
24 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Star Strider
le 8 Août 2012
Modifié(e) : Star Strider
le 8 Août 2012
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 commentaires
Plus de réponses (3)
Sumit Tandon
le 8 Août 2012
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?
Jacob
le 8 Août 2012
Modifié(e) : Jacob
le 8 Août 2012
In response to Sumit above:
x = 2xn matrix of x' and x, A = 1x2 matrix of c and k, and B = 1xn matrix of mx''. Solve for A.
Example:
x=[v1 v2 v3 v4;x1 x2 x3 x4];
B=[mx1'' mx2'' mx3'' mx4''];
A=x\B;
This should get you the values of c and k (c=A(1), k=A(2)).
6 commentaires
Greg Heath
le 9 Août 2012
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 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!