pushing'
authorNils Forssén <forssennils@gmail.com>
Tue, 6 Dec 2022 22:18:25 +0000 (23:18 +0100)
committerNils Forssén <forssennils@gmail.com>
Tue, 6 Dec 2022 22:18:25 +0000 (23:18 +0100)
collar_ekv.m [new file with mode: 0644]
collar_events.m [new file with mode: 0644]
mek_upg.m [new file with mode: 0644]

diff --git a/collar_ekv.m b/collar_ekv.m
new file mode 100644 (file)
index 0000000..cd7dc0b
--- /dev/null
@@ -0,0 +1,7 @@
+function y_dot=collar_ekv(t, y, g, k, m, b)
+z = y(1);
+z_dot = y(2);
+
+y_dot = zeros(2,1);
+y_dot(1) = z_dot;
+y_dot(2) = -g - ((k/m)*z*(1-((3*b)/(2*sqrt((z.^2) + (b.^2))))));
\ No newline at end of file
diff --git a/collar_events.m b/collar_events.m
new file mode 100644 (file)
index 0000000..c5c89b1
--- /dev/null
@@ -0,0 +1,6 @@
+function [value,isterminal,direction] = collar_events(t, y, stopheight)
+
+value = y(1) - stopheight;
+isterminal=1;
+direction=0;
+end
\ No newline at end of file
diff --git a/mek_upg.m b/mek_upg.m
new file mode 100644 (file)
index 0000000..dec2aaf
--- /dev/null
+++ b/mek_upg.m
@@ -0,0 +1,59 @@
+%BANAN
+stopheight=0;
+g = 9.82;
+k = 100;
+m = 0.5;
+b = 0.3;
+
+
+t_max = 10;
+z_0 = sqrt(3)*b;
+
+
+options = odeset("Events", @(t,y) collar_events(t, y, stopheight), ...
+    'RelTol', 1e-3,'AbsTol', 1e-6, 'MaxStep', 0.01);
+
+[t_vek,Y]=ode45(@(t,y) collar_ekv(t,y,g,k,m,b), [0 t_max], [z_0 0], options);
+
+z = Y(:, 1);
+z_dot = Y(:,2);
+s = z_0 - z;
+
+subplot(1,3,1);
+p1 = plot(s, z_dot);
+xlabel("s");
+ylabel("zdot");
+title("Hastighet krage");
+
+zdotdot = zeros(length(t_vek), 1);
+for i=1:length(t_vek)
+    zdotdot(i) = -g - ((k/m)*z(i)*(1-((3*b)/(2*sqrt((z(i)^2) + (b.^2))))));
+end
+subplot(1,3,2)
+p2 = plot(s, zdotdot);
+xlabel("s");
+ylabel("ydotdot");
+title("Acceleration krage")
+
+step = 0.01;
+y = zeros(t_max/step, 1);
+v = zeros(t_max/step, 1);
+for i=0:length(new_t)
+
+    v(i+1) = g*step*i;
+    y(i+1) = z_0 - (v(i+1)*step*i/2);
+    if z_0 - (g*step*i*step*i/2) < 0
+        v = v(1:i, 1);
+        y = y(1:i, 1);
+        v = flip(v,1);
+
+        break
+    end
+end
+subplot(1,3,3)
+p3 = plot(y, v);
+xlabel("s");
+ylabel("v");
+
+max(v)
+z_dot(end)