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
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
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
0 件のコメント
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!