Guest User

Untitled

a guest
Sep 7th, 2019
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.37 KB | None | 0 0
  1. clear
  2. close all
  3. clc
  4.  
  5.  
  6. syms amin amax Vmax
  7. syms dav dvt dxt t
  8. syms aav avt axt
  9. syms vel
  10.  
  11.  
  12. % Równanie hamowania
  13. decel_firstEquation = struct('x', 0, 'y', 0)
  14. decel_secondEquation = struct('x', Vmax/2, 'y', amax)
  15. decel_thirdEquation = struct('x', Vmax, 'y', amin)
  16. [dav, dvt, dxt] = parabolicAccelerationTrajectory(decel_firstEquation, decel_secondEquation, decel_thirdEquation);
  17.  
  18. syms decel_v(t) decel_a(vel) decel_x(t)
  19. decel_v(t) = dvt
  20. decel_a(vel) = dav
  21. decel_x(t) = dxt
  22.  
  23.  
  24. % Równanie przyspieszenia
  25. accel_firstEquation = struct('x', 0, 'y', amin)
  26. accel_secondEquation = struct('x', Vmax/2, 'y', amax)
  27. accel_thirdEquation = struct('x', Vmax, 'y', 0)
  28. [aav, avt, axt] = parabolicAccelerationTrajectory(accel_firstEquation, accel_secondEquation, accel_thirdEquation);
  29.  
  30.  
  31. syms accel_v(t) accel_a(vel) accel_x(t)
  32. accel_v(t) = avt
  33. accel_a(vel) = aav
  34. accel_x(t) = axt
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. function [av, vt, xt] = parabolicAccelerationTrajectory(firstPointEquation, secondPointEquation, thirdPointEquation)
  42.     % Wyprowadzenie funkcji zależności przyspieszenia od prędkości
  43.     % Deklaracja zmiennych symbolicznych
  44.     syms amin amax Vmax
  45.     syms a2 a1 a0
  46.  
  47.     syms a(v)
  48.     syms v(t)
  49.     syms x(t)
  50.     syms v
  51.  
  52.     % Zależność w formie funkcji kwadratowej
  53.     a(v) = sym(a2*v^2 + a1*v + a0);
  54.  
  55.     % Określamy trzy punkty przez które ma przechodzić parabola:
  56.  
  57.     eq1 = a(firstPointEquation.x) == firstPointEquation.y;
  58.     eq2 = a(secondPointEquation.x) == secondPointEquation.y;
  59.     eq3 = a(thirdPointEquation.x) == thirdPointEquation.y;
  60.    
  61.     eqs = [eq1 eq2 eq3];
  62.    
  63.     % Znalezienie współczynników a0 a1 a2
  64.     vars = [a2 a1 a0];
  65.     sol = solve(eqs, vars);
  66.  
  67.     a0 = sol.a0;
  68.     a1 = sol.a1;
  69.     a2 = sol.a2;
  70.  
  71.     % Rozwiązanie
  72.     a(v) = a2*v^2 + a1*v + a0;
  73.  
  74.  
  75.     % Wyznaczanie wzoru funkcji v(t), gdzie v(t) = integ(a(v))
  76.     syms v(t) v0
  77.  
  78.     % Równanie różniczkowe powstałe z całkowania równania v(t) = integ(a(v))
  79.     ode = diff(v, t) == a(v);
  80.     cond = v(0) == v0;
  81.  
  82.     v(t) = dsolve(ode,cond);
  83.    
  84.  
  85.     % Wyznaczanie wzoru funkcji x(t), gdzie x(t) = integ(v(t))
  86.     syms x(t) x0
  87.     ode = diff(x, t) == v(t);
  88.     cond = x(0) == x0;
  89.  
  90.     x(t) = dsolve(ode, cond);
  91.    
  92.     syms vel
  93.    
  94.     av = subs(a2*vel^2 + a1*vel + a0);
  95.     vt = v(t);
  96.     xt = x(t);
  97.    
  98.     parabolicAccelerationTrajectory = [av, vt, xt];
  99. end
Advertisement
Add Comment
Please, Sign In to add comment