• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Sep 19th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. % script for excercise 1 of case study 1 for EMATH171
2. % in this script we solve for V using newtons method repetating untill we
3. % have a tolerence of 0.0001
4. clear
5. clc
6. close all
7.
8. % Coefficients for the function and its deriviative
9. m = 1000;
10. g = 9.81;
11. theta = 0.25 * pi;
12. coff_friction = 0.2;
13. a = 1;
14. b = 100 * pi;
15. rgb = 20;
16. R = 0.5;
17.
18.
19. % functions
20. j = @(v) (m .* g .* (sin(theta)) .* v) + (coff_friction .* m .* g .* (cos(theta)) .* v);
21. % motor shaft rotation speed
22.
23. k = @(v) (a .* ((b .* ((rgb .* v) / R)) - (((rgb.^2) * (v.^2))/(R.^2))));
24. % power output
25.
26. f = @(v) j(v) - k(v);
27. % origional function
28.
29. g = @(v) (m .* g .* (sin(theta))) + (coff_friction .* m .* g .* (cos(theta))) - (a .* ((b .* (rgb / R)) - ((2 .* (rgb.^2).* v)/(R.^2))));
30. % deriviative
31.
32. h = @(old_x) old_x - ((f(old_x))/(g(old_x)));
33. % newtons method propper
34.
35. % Coefficients for newtons method
36.
37. N = 200;
38. % maximuim amount of repetitions, unlikley to actualy reach this value
39.
40. x = 2;
41. % initial guess
42.
43. tol = 0.0001;
44. %tolerence of diffrence between iterations
45.
46. out_array = [x];
47. % output array of the results of newtons methods approximations
48.
49. error_array = [abs(f(x))];
50. % array of the error
51.
52. delta_array = [];
53. % array of change between iterations
54.
55. counter = 0;
56. % tracks number of iterations
57.
58. % Newtons method implementaion
59.
60. for item = 1:N
61.     old_x = x; % saving old x
62.     delta_array(item) = (x);
63.     x = h(x); % creating new x
64.     counter = counter + 1;
65.     out_array(item+1) = x;
66.     error_array(item+1) = abs(f(x));
67.     delta_array(item) = abs(delta_array(item)- x);
68.     if and((abs(f(x))<tol),(abs(x-old_x)<tol))
69.         counter = counter - 1;
70.         break
71.     end
72. end
73.
74. % display
75. figure
76. hold on
77. x_actual_array = [0:0.1:5];
78. plot (x_actual_array, j(x_actual_array))
79. plot (x_actual_array, k(x_actual_array))
80. hold off
81. x
82. counter
83. out_array
84. error_array;
85. delta_array;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?