# 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?

조회 수: 4(최근 30일)
댓글: Abdulswamad Salim 2020년 4월 27일
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
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)]) ##### 댓글 수: 1표시숨기기 없음
Thank you so much brother Hiremath, seems it was a simple problem. You are appreciated.

댓글을 달려면 로그인하십시오.

### 채택된 답변

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.
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 댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!