How can I make a for loop to calculate the angle value (θ) according to time?
2 views (last 30 days)
Show older comments
The object is moving at a constant velocity of 25 km per hour and no acceleration.
Consider:
y(x) = P
y'(x) = tan (θ)
θ = inverse tangent of y'(x)
x = [ 0 250 500 750 1000 1250 1500 1750 2000 2250 2500 2750 3000 3250 3500 3750 4000 4250 4500 4750 5000 5250 5500 5750 6000 6250 6500 6750 7000 7250 7500 7750 8000 8250 8500 8750 9000 9250 9500 9750 10000 10250 10500 10750 11000 11250 11500 11750 12000 12250 12500 12750 13000 13250 13500 13750 14000 14250 14500 14750 15000 ]; % Meters
y = [ 10 6.333 2.886 0.334 -0.962 -1.036 -0.28 0.673 1.136 0.561 -1.299 -4.304 -7.944 -11.447 -13.963 -14.772 -13.462 -10.05 -4.993 0.902 6.645 11.279 14.087 14.74 13.358 10.459 6.825 3.304 0.605 -0.865 -1.086 -0.407 0.56 1.125 0.71 -0.979 -3.854 -7.45 -11.021 -13.715 -14.781 -13.762 -10.612 -5.733 0.106 5.927 10.757 13.835 14.778 13.643 10.904 7.318 3.737 0.897 -0.745 -1.119 -0.529 0.44 1.096 0.835 -0.681 ]; % Meters
n = 20;
P = polyfit(x, y, n);
Q = polyder(P);
0 Comments
Answers (1)
Image Analyst
on 5 Dec 2020
Yes, you can. Try it.
x = [ 0 250 500 750 1000 1250 1500 1750 2000 2250 2500 2750 3000 3250 3500 3750 4000 4250 4500 4750 5000 5250 5500 5750 6000 6250 6500 6750 7000 7250 7500 7750 8000 8250 8500 8750 9000 9250 9500 9750 10000 10250 10500 10750 11000 11250 11500 11750 12000 12250 12500 12750 13000 13250 13500 13750 14000 14250 14500 14750 15000 ]; % Meters
y = [ 10 6.333 2.886 0.334 -0.962 -1.036 -0.28 0.673 1.136 0.561 -1.299 -4.304 -7.944 -11.447 -13.963 -14.772 -13.462 -10.05 -4.993 0.902 6.645 11.279 14.087 14.74 13.358 10.459 6.825 3.304 0.605 -0.865 -1.086 -0.407 0.56 1.125 0.71 -0.979 -3.854 -7.45 -11.021 -13.715 -14.781 -13.762 -10.612 -5.733 0.106 5.927 10.757 13.835 14.778 13.643 10.904 7.318 3.737 0.897 -0.745 -1.119 -0.529 0.44 1.096 0.835 -0.681 ]; % Meters
n = 20; % 20th order polynomial. You've got to be kidding me!
P = polyfit(x, y, n);
Q = polyder(P);
% Now compute angle for every (x,y) location.
for k = 1 : length(x)
theta(k) = atan(..................) % See if you can finish it.
end
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!