+++ /dev/null
-%% init
-clear
-clc
-
-set(gcf, 'Position', [50 50 1200 900]);
-
-stopheight=0;
-g = 9.82;
-k = 100;
-m = 0.5;
-b = 0.3;
-
-t_max = 10;
-z_0 = sqrt(3)*b;
-
-hold on;
-
-%% calcs
-options_collar = odeset("Events", @(t,y) collar_events(t, y, stopheight), ...
- 'RelTol', 1e-3,'AbsTol', 1e-6, 'MaxStep', 0.01);
-
-[t_vek_collar,Y_collar]=ode45(@(t,y) collar_ekv(t,y,g,k,m,b), [0 t_max], [z_0 0], options_collar);
-
-options_brick = odeset("Events", @(t,y) brick_events(t, y, stopheight), ...
- 'RelTol', 1e-3,'AbsTol', 1e-6, 'MaxStep', 0.01);
-
-[t_vek_brick,Y_brick]=ode45(@(t,y) brick_ekv(t,y,g), [0 t_max], [z_0 0], options_brick);
-
-z_collar = Y_collar(:, 1);
-z_dot_collar = Y_collar(:,2);
-s_collar = z_0 - z_collar;
-
-z_brick = Y_brick(:,1);
-z_dot_brick = Y_brick(:,2);
-s_brick = z_0 - z_brick;
-
-%% plot 1 - hastighet
-subplot(2,2,1);
-
-p1 = plot(s_collar, z_dot_collar);
-p2 = plot(s_brick, z_dot_brick);
-xlim([0 max(s_brick)]);
-xlabel("Fallsträcka (m)");
-ylabel("Hastighet (m/s)");
-legend([p1 p2], {"Krage", "Kloss"});
-title("Hastighet");
-
-%% plot 2 - acceleration
-zdotdot_collar = zeros(length(t_vek_collar), 1);
-for i=1:length(t_vek_collar)
- zdotdot_collar(i) = -g - ((k/m)*z_collar(i)*(1-((3*b)/(2*sqrt((z_collar(i)^2) + (b.^2))))));
-end
-subplot(2,2,2)
-p3 = plot(s_collar, zdotdot_collar);
-p4 = plot(s_brick, -g.*ones(length(s_brick), 1));
-xlim([0 max(s_brick)]);
-xlabel("Fallsträcka (m)");
-ylabel("Acceleration (m/s^2)");
-legend([p3 p4], {"Krage", "Kloss"}, "Location", "southeast");
-title("Acceleration")
-
-%% plot 3 - normalkraft
-subplot(2,2,3)
-normal = b.*k.*((1-(3.*b))./(2.*sqrt((s_brick.^2) + (b.^2))));
-p1 = plot(s_brick, normal);
-xlim([0 max(s_brick)]);
-xlabel("Fallsträcka (m)");
-ylabel("Normalkraft (N)");
-title("Normalkraft")
-
-%% plot 4 - energi
-T = (m.*(z_dot_collar.^2)./2;
-V_g = m*g*z_collar;
-V_e = k.*(sqrt((z_collar.^2) + (b.^2)) - (3.*b./2))./2;
-E_tot = T + V_g + V_e;
-subplot(2,2,4);
-p5 = plot(s_collar, T);
-p6 = plot(s_collar, V_g);
-p7 = plot(s_collar, V_e);
-p8 = plot(s_collar, E_tot);
-xlim([0 max(s_collar)]);
-xlabel("Fallsträcka (m)");
-ylabel("Energi (J)");
-legend([p5 p6 p7 p8], {"Rörelseenergi", "Potentiell energi", "Fjäderenergi", "Total energi"});
-title("Energi");
-
-%% print
-min(z_dot_collar)
-min(z_dot_brick)
-
set(gcf, 'Position', [50 50 1200 900]);
stopheight=0;
-g = 9.82;
+g = 9.81;
k = 100;
m = 0.5;
b = 0.3;
t_max = 10;
-z_0 = sqrt(3)*b;
+z_0 = 0.5*sqrt(3)*b;
%% calcs
options_collar = odeset('Events', @(t,y) collar_events(t, y, stopheight), ...
'RelTol', 1e-3,'AbsTol', 1e-6, 'MaxStep', 0.01);
%% plot 1 - hastighet
subplot(2,2,1);
-p1 = plot(s_collar, z_dot_collar);
+p1 = plot(s_collar, abs(z_dot_collar));
hold on;
-p2 = plot(s_brick, z_dot_brick);
+p2 = plot(s_brick, abs(z_dot_brick));
xlim([0 max(s_collar) + 0.05*max(s_collar)]);
xlabel('Fallsträcka (m)');
ylabel('Hastighet (m/s)');
hold off;
-legend([p1 p2], {'Krage', 'Kloss'});
-title('Hastighet');
+legend([p1 p2], {'Krage', 'Kloss'}, 'Location', 'southeast');
+title('Plot 9 - Hastighet');
%% plot 2 - acceleration
zdotdot_collar = zeros(length(t_vek_collar), 1);
ylabel('Acceleration (m/s^2)');
hold off;
legend([p3 p4], {'Krage', 'Kloss'}, 'Location', 'southeast');
-title('Acceleration')
+title('Plot 10 - Acceleration');
%% plot 3 - normalkraft
subplot(2,2,3)
-normal = b.*k.*((1-(3.*b))./(2.*sqrt((s_brick.^2) + (b.^2))));
-p1 = plot(s_brick, normal);
+normal = b.*k.*(1-((3.*b)./(2.*sqrt((z_collar.^2) + (b.^2)))));
+p1 = plot(s_collar, normal);
hold on;
-xlim([0 max(s_brick) + 0.05*max(s_brick)]);
+xlim([0 max(s_collar) + 0.05*max(s_collar)]);
xlabel('Fallsträcka (m)');
ylabel('Normalkraft (N)');
-title('Normalkraft')
+title('Plot 11 - Normalkraft');
hold off;
%% plot 4 - energi
-z_collar(end + 1) = z_collar(end);
-z_dot_collar(end + 1) = 0;
-s_collar(end + 1) = s_collar(end);
-
-T = abs((m.*(z_dot_collar.^2))./2);
-V_g = abs(m*g*z_collar);
-V_e = abs(k.*(sqrt((z_collar.^2) + (b.^2)) - (3.*b./2))./2);
+T = (m.*(z_dot_collar.^2))./2;
+V_g = m*g*z_collar;
+V_e = (k/2)*(sqrt(z_collar.^2 + b^2) - (3*b/2)).^2;
E_tot = T + V_g + V_e;
subplot(2,2,4);
p5 = plot(s_collar, T);
ylabel('Energi (J)');
hold off;
legend([p5 p6 p7 p8], {'Rörelseenergi', 'Potentiell energi', 'Fjäderenergi', 'Total energi'}, 'Location', 'north');
-title('Energi');
-
-%% print
-min(z_dot_collar)
-min(z_dot_brick)
-
+title('Plot 12 - Energi');
\ No newline at end of file