How can I change my constants and initial values, and plot the different variations of the resulting projectile on the same graph?

조회 수: 1 (최근 30일)
Hi, for a high-school math project I am finding the ideal velocity and angles for a three-point shot. For this I have a set of constants and I need to change them every trial I want to know how I can change the values to y0 from 7 to 7.1 for example and then plot the new line on the same graph as the previous line where y0 was 7. How can I do this?
%Trajectory of a basketball
%Initialization
clear all, close all, clc, format compact;
%constants and initial values
g = 32.3; % f/s^2, acceleration of gravity
v0 = 29; % ft/s, initial acceleration of the ball
th = 65.* pi./180; %radians, launch angle
y0 = 7.; %initial height, ft
x0 = 0; %initial position, ft
[vx0,vy0] = pol2cart (th,v0) % components of initial velocity
yhit = 10; % final height
thit = roots([-g./2, vy0, y0-yhit]) % time to final height (seconds)
thit = max(thit) % using for the second time on the way down
%generating the values for plotting
t = linspace(0,thit,500)
x = x0 + vx0.*t; %horizontal positions
y = y0 + vy0.*t - 0.5 .* g .*t.^2; %vertical positions
% draw the trajectory
figure('units','Centimeters',...
'Position',[0 0 15 10],...
'PaperPositionMode','auto');
subplot(1,1,1)
plot(x,y,'k-','LineWidth',1.25)
hold on
plot ([19-.75,19+.75],[10,10],'ko-') % plot the line for the rim %draw the 18"
%diameter rim and 9.4" diameter basketball
ang = linspace(0,2.*pi,100); %list of angles to calculate points on a circle
br = 9.4 ./ 12 ./ 2; %ft, radius of the basketball
xb = x(end) + br.*cos(ang); % pts for plotting ball
yb = y(end) + br.*sin(ang); % pts for plotting ball
fill(xb,yb,'w'); % a filled polygon
xlim([0 22])
ylim([0 20])
set(gca, 'XminorTick','on', 'XminorGrid','on')
set(gca, 'XminorTick','on', 'XminorGrid','on')
xlabel({'$x\hspace{1mm}[m]$'},...
'FontUnits','points',...
'interpreter','latex',...
'FontSize',12,...
'FontName','Baskerville')
ylabel({'$y\hspace{1mm}[m]$'},...
'FontUnits','points',...
'interpreter','latex',...
'FontSize',12,...
'FontName','Baskerville')
title({'$Basketball\hspace{1mm}Trajectory$'},...
'FontUnits','points',...
'FontWeight','normal',...
'interpreter','latex',...
'FontSize',13,...
'FontName','Baskerville')

답변 (0개)

카테고리

Help CenterFile Exchange에서 Polar Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by