Info

此问题已关闭。 请重新打开它进行编辑或回答。

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

1 次查看(过去 30 天)
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 个评论
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