Please someone tell me what's wrong with my code, it keeps on returning the message, ''Unrecognized variable of v''. The image below the code is the problem?
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Abdulswamad Salim
el 27 de Abr. de 2020
Comentada: Abdulswamad Salim
el 27 de Abr. de 2020
function distance = DTask1_f(v, theta);
h0 = 1.8;
g = 9.8;
v = 60;
t = linspace(0,1,1000);
x=v*cos(theta*pi/180)*t;
y=h+v*sin(theta*pi/180)*t-.5*g*t.^2;
c = find(y<0);
if isempty (c);
disp('The ball does not hit the ground in 10 seconds.');
distance = Nan
else
distance = x(c(1));
end
clear
v = 60;
theta = 0:1:60;
distance = zeros(1,61);
for i = 1:60
distance(i)=DTask1_f(v,theta(i));
end
figure
plot(theta,distance);
xlabel('Initial angle (deg)');
ylabel('Distance thrown (m)');
title('Distance of ball thrown as a function of release angle');
legend(['v= ' num2str(v)])

Respuesta aceptada
Mrutyunjaya Hiremath
el 27 de Abr. de 2020
Hello
There is a problem in the calculation of 'y' in function 'DTask1_f'
Calculated value first value is around 2.4, but it should come around 2.2 according to your graph.
I have done small corrections in you function code.
function distance = DTask1_f(v, theta)
h = 1.5;
g = 9.8;
% v = 60;
t = linspace(0,1,1000);
x = v * cos(theta*pi/180) * t;
y = h + v * sin(theta*pi/180) * t -.5*g*t.^2;
c = find(y<0);
if isempty (c);
disp('The ball does not hit the ground in 10 seconds.');
distance = NaN;
else
disp('The ball hit the ground in 10 seconds.');
distance = x(c(1));
end

0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!