Thank you so much brother Hiremath, seems it was a simple problem. You are appreciated.
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?
조회 수: 1 (최근 30일)
이전 댓글 표시
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)])
채택된 답변
Mrutyunjaya Hiremath
2020년 4월 27일
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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!