How i can simulate a mass-spring-damper system with variable mass?
3 views (last 30 days)
Show older comments
What is the proper form to simulate a mass-spring-damper system with variable mass?
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)
0 Comments
Answers (1)
Ced
on 14 Mar 2016
Edited: Ced
on 14 Mar 2016
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 Comments
See Also
Categories
Find more on Ordinary Differential Equations 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!