Question: Please write this in MATLAB.... function y = hitTheSpot(v0,theta) Cd = 0.5; dxdt = @(t,x) [x(3:4);(-1/2*1*pi*(0.1^2)*Cd*norm(x(3:4))*x(3:4)-[0;9.81])]; if size(v0) == size(theta) [m,n] = size(v0); y =

Please write this in MATLAB....

function y = hitTheSpot(v0,theta) Cd = 0.5; dxdt = @(t,x) [x(3:4);(-1/2*1*pi*(0.1^2)*Cd*norm(x(3:4))*x(3:4)-[0;9.81])]; if size(v0) == size(theta) [m,n] = size(v0); y = zeros(m,n); for i = 1:m for j = 1:n [t,x] = ode45(dxdt,[0,2*v0(i,j)*sind(theta(i,j))/9.81],[0;0;v0(i,j)*cosd(theta(i,j));v0(i,j)*sind(theta(i,j))]); % figure % plot(x(:,1),x(:,2)) % hold on % plot(v0*cosd(theta)*t,v0*sind(theta)*t-1/2*9.81*t.^2) % set(gca,'ylim',[0,inf]) [~,b] = max(x(:,2)); y(i,j) = interp1(x(b:end,2),x(b:end,1),0,'pchip'); end end elseif size(v0) == [1,1] [m,n] = size(theta); y = zeros(m,n); for i = 1:m for j = 1:n [t,x] = ode45(dxdt,[0,2*v0*sind(theta(i,j))/9.81],[0;0;v0*cosd(theta(i,j));v0*sind(theta(i,j))]); % figure % plot(x(:,1),x(:,2)) % hold on % plot(v0*cosd(theta)*t,v0*sind(theta)*t-1/2*9.81*t.^2) % set(gca,'ylim',[0,inf]) [~,b] = max(x(:,2)); y(i,j) = interp1(x(b:end,2),x(b:end,1),0,'pchip'); end end elseif size(theta) == [1,1] [m,n] = size(v0); y = zeros(m,n); for i = 1:m for j = 1:n [t,x] = ode45(dxdt,[0,2*v0(i,j)*sind(theta)/9.81],[0;0;v0(i,j)*cosd(theta);v0(i,j)*sind(theta)]); % figure % plot(x(:,1),x(:,2)) % hold on % plot(v0*cosd(theta)*t,v0*sind(theta)*t-1/2*9.81*t.^2) % set(gca,'ylim',[0,inf]) [~,b] = max(x(:,2)); y(i,j) = interp1(x(b:end,2),x(b:end,1),0,'pchip'); end end end

Please write this in MATLAB.... function y = hitTheSpot(v0,theta) Cd = 0.5;

2) 1D DOMAIN INTERPOLATION FROM A FUNCTION Download hitTheSpot.m from Canvas. hitTheSpot() is a function that, when given an initial speed and ngle above the horizontal, predicts how far away a projectile will land if fired with those initial onditions. The distance the projectile would travel is called the "range". Generate data from the function (as if measured by running tests) using angle values 0 E [5,85), 40 = 0, v. = 35 m/s. Then, use interpolation on that data set to return the following results. a) Linear interpolation to find the projectile range for 0 = 30 (HW5_6.dat) b) Spline interpolation to find the projectile range for 0 = 30 (HW5_7.dat) c) Compare the results from parts a) and b) with the true range, generated by plugging 30 into the hitTheSpot() function directly. Subtract the true answer from the interpolated answer, and save on HW5_8.dat and HW5_9.dat 2) 1D DOMAIN INTERPOLATION FROM A FUNCTION Download hitTheSpot.m from Canvas. hitTheSpot() is a function that, when given an initial speed and ngle above the horizontal, predicts how far away a projectile will land if fired with those initial onditions. The distance the projectile would travel is called the "range". Generate data from the function (as if measured by running tests) using angle values 0 E [5,85), 40 = 0, v. = 35 m/s. Then, use interpolation on that data set to return the following results. a) Linear interpolation to find the projectile range for 0 = 30 (HW5_6.dat) b) Spline interpolation to find the projectile range for 0 = 30 (HW5_7.dat) c) Compare the results from parts a) and b) with the true range, generated by plugging 30 into the hitTheSpot() function directly. Subtract the true answer from the interpolated answer, and save on HW5_8.dat and HW5_9.dat

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!