How i can simulate a mass-spring-damper system with variable mass?

3 次查看(过去 30 天)
What is the proper form to simulate a mass-spring-damper system with variable mass?
I've analized 3 alternatives, based on Matlab Help
Option 1: mass change in the function
m = 1.2;
k = 15;
c = 1.2;
f = 1;
tspan = 0:0.01:100-0.01;
y0 = [0 0];
opciones0=odeset('RelTol',1e-12,'AbsTol',1e-12);
fun_1 = @(t,z) [z(2); (f*sin(2*pi*t) - k*z(1)-c*z(2))/(m*(1+0.01*sin(2*pi*t/10)))];
[t1,z1]=ode15s(@(t,z) fun_1(t,z),tspan,y0,opciones0);
Option 2: mass change in odeset
fun_2 = @(t,z) [z(2); (f*sin(2*pi*t) - k*z(1)-c*z(2))/m];
fun_m = @(t,z) m*(1+0.01*sin(2*pi*t/10))*eye(2);
opciones2=odeset('RelTol',1e-12,'AbsTol',1e-12,'Mass',fun_m,'MStateDependence','none','MassSingular','no');
[t2,z2]=ode15s(@(t,z) fun_2(t,z),tspan,y0,opciones2);
Option 3: mass change in the function and odeset
fun_3 = @(t,z) [z(2); (f*sin(2*pi*t) - k*z(1)-c*z(2))/(m*(1+0.01*sin(2*pi*t/10)))];
fun_m = @(t,z) m*(1+0.01*sin(2*pi*t/10))*eye(2);
opciones3=odeset('RelTol',1e-12,'AbsTol',1e-12,'Mass',fun_m,'MStateDependence','none','MassSingular','no');
[t3,z3]=ode15s(@(t,z) fun_3(t,z),tspan,y0,opciones3);
But when i see the spectrums, with the 3 alternatives I get different results, and i don't know which is the correct. (the first graph is with constant mass)

回答(1 个)

Ced
Ced 2016-3-14
编辑:Ced 2016-3-14
You should be able to include the changing mass either in the function, or then through odeset, but I am not sure if you did it correctly.
Case 1: In function --> looks good to me
Case 2: Is a bit confusing to me. You have m in both fun_2 and in the settings. Also, afaik, matlab takes the odeset option to set M(t)*dy = f(....). Why would you multiply the first dimension with the mass as well? Is that intended?
Case 3: Well, as you already stated, you include the mass twice.
Case 4: For odeset, I think it should look something like
fun_4 = @(t,z) [z(2); (f*sin(2*pi*t) - k*z(1)-c*z(2))];
fun_m = @(t,z) diag([1, m*(1+0.01*sin(2*pi*t/10)]);
opciones4=odeset('RelTol',1e-12,'AbsTol',1e-12,'Mass', ...
fun_m,'MStateDependence','none','MassSingular','no');
[t4,z4]=ode15s(@(t,z) fun_4(t,z),tspan,y0,opciones4);
  2 个评论
Manuel
Manuel 2016-3-14
Thanks for you anser! Now I understood.
Case 2 and 3 are wrong so you mention.
Now I compared the results of cases 1 and 4, in the time and frequency domain they give the same results. So, when the mass matrix is time dependent and it's no singular, it's no necessary to use the 'Mass' option in odeset and solve like the case 1?
Ced
Ced 2016-3-15
编辑:Ced 2016-3-15
Correct. At least that's the theory. There might be cases were your mass matrix is not singular, but badly conditioned. In these cases, it might still be better to use that option.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by