필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

MatLab Debugging, I strated debugging but I can't find my error

조회 수: 1 (최근 30일)
Alexis Ortiz
Alexis Ortiz 2020년 3월 8일
마감: MATLAB Answer Bot 2021년 8월 20일
function [h,v]=debug_projectile(A,v0,t)
% [h,v]=debug_projectile(A,v0,t) calculate the height(h) and speed(v) of a
% projectile motion when the launch speed is v0 at an angle of A(in degree)
% to the horizontal for time t. t can be an array.
% This code contains several bugs. Find all bugs and fix them to generate
% correct results.
t=0:0.1:10;
h=vO*t*sin(A)-0.5*gt.^2;
v(t)=sqrt(v0^2-2*v0*g*t*sln(A+g^2*t^2);
% After you fix the code, type the following in the command window
% >>[h,v]=debug_projectile(90,20,[0,1]). You should get the result of
% h = 0 15.0950
% v = 20.0000 10.1900
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 3월 8일
What does sin(90) mean?
Ameer Hamza
Ameer Hamza 2020년 3월 8일
Since this seems like a homework question, so I will provide the correct code, but here are few tips you can use to identify the issues.
  • Some variables are not defined. Go through the formula for h and v to identify them.
  • In Matlab, trigonometric functions use angles in radian instead of degrees.
  • The index of an array cannot be floating-point numbers. It must be positive integer numbers or logical array.
  • The variable t in the input is not used inside the code. Read the description of function to see how you can use t inside your code.

답변 (1개)

Chidvi Modala
Chidvi Modala 2020년 3월 11일
You can make use of the following code which is free of syntax errors
function [h,v]=debug_projectile(A,v0,t)
g = 9.80665;
h=v0*t*sin(A)-0.5*g*(t.^2);
v=sqrt( v0^2-2*v0*g*t.*sin(A+g^2*t.^2));
end

이 질문은 마감되었습니다.

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by