Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1.  
  2. % script for excercise 2 of case study 1 for EMATH171
  3. % in this script we solve for power using newtons method repetating untill we
  4. % have a tolerence of 0.0001
  5. clear
  6. clc
  7. close all
  8.  
  9. % Coefficients for the function and its deriviative
  10.  
  11. m = 1500; % mass
  12. g = 9.81; % gravity
  13. R = 0.205; % wheel raduis
  14. beta = 0.44;
  15. acell_angular = 420;
  16. rgb = 0.8;
  17. rfd = 3.5;
  18. drag_coff = 0.3;
  19. area = 2;
  20. fluid_density = 1.2;
  21.  
  22. crr = 0.01;
  23.  
  24. acceleration = 0;
  25. theta = 10;
  26.  
  27. % functions
  28. k = R /(rgb * rfd);
  29.  
  30. pwr = @(v) ((acell_angular .* v)/k) - ((beta .* v.^2) / (k.^2));
  31. % power output
  32.  
  33. roll = @(v) crr .* m .* g .* (cos(theta)) .* v;
  34. % power dissipated by rolling resistance
  35.  
  36. drag = @(v) drag_coff .* area .* 0.5 .* fluid_density * v.^3;
  37. % power dissipated by aerodynamic drag
  38.  
  39. acell = @(v) m .* acceleration .* v;
  40. % power required for acceleration at rate of dv/dt
  41.  
  42. grad = @(v) m .* g .* (sin(theta)) .* v;
  43. % Gradient climbing resistance
  44.  
  45. f = @(v) drag(v) + grad(v) + roll(v) + acell(v) - pwr(v);
  46. % origional function
  47.  
  48. % derrivative functions
  49. drag_derivative = @(v) 3 .* drag_coff .* area .* 0.5 .* fluid_density .* v^2;
  50.  
  51. grad_derivative = m * g * sin(theta);
  52.  
  53. roll_derivative = crr * m * g * cos(theta);
  54.  
  55. pwr_derivative = @(v) (acell_angular / k) - ((2 .* beta .* v)/(k.^2));
  56.  
  57. g = @(v) drag_derivative(v) + grad_derivative + roll_derivative + m * acceleration - pwr_derivative(v);
  58. % deriviative
  59.  
  60. h = @(old_x) old_x - ((f(old_x))/(g(old_x)));
  61. % newtons method propper
  62.  
  63. % Coefficients for newtons method
  64.  
  65. N = 200;
  66. % maximuim amount of repetitions, unlikley to actualy reach this value
  67.  
  68. x = 200;
  69. % initial guess
  70.  
  71. tol = 0.0001;
  72. %tolerence of diffrence between iterations
  73.  
  74. out_array = [x];
  75. % output array of the results of newtons methods approximations
  76.  
  77. error_array = [abs(f(x))];
  78. % array of the error
  79.  
  80. delta_array = [];
  81. % array of change between iterations
  82.  
  83. counter = 0;
  84. % tracks number of iterations
  85.  
  86. % Newtons method implementaion
  87.  
  88. for item = 1:N
  89. old_x = x; % saving old x
  90. delta_array(item) = (x);
  91. x = h(x); % creating new x
  92. counter = counter + 1;
  93. out_array(item+1) = x;
  94. error_array(item+1) = abs(f(x));
  95. delta_array(item) = abs(delta_array(item)- x);
  96. if and((abs(f(x))<tol),(abs(x-old_x)<tol))
  97. counter = counter - 1;
  98. break
  99. end
  100. end
  101.  
  102. % display
  103. figure
  104. hold on
  105. x_actual_array = [-200:1:1500]; % road speed v
  106. plot(x_actual_array, pwr(x_actual_array))
  107. plot(x_actual_array, roll(x_actual_array))
  108. plot(x_actual_array, drag(x_actual_array))
  109. plot(x_actual_array, acell(x_actual_array))
  110. plot(x_actual_array, grad(x_actual_array))
  111. plot(x_actual_array, f(x_actual_array))
  112. legend('power', 'rolling resistance', 'drag resistance', 'aceleration', 'gradient resistance', 'total')
  113. hold off
  114. x
  115. counter
  116. out_array;
  117. error_array;
  118. delta_array;
  119.  
  120. %
  121. % The xlabel and ylabel commands generate labels along x-axis and y-axis.
  122. % The title command allows you to put a title on the graph.
  123. % The grid on command allows you to put the grid lines on the graph.
  124. % The axis equal command allows generating the plot with the same scale factors and the spaces on both axes.
  125. % The axis square command generates a square plot.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement