Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

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

1 vue (au cours des 30 derniers jours)
Alexis Ortiz
Alexis Ortiz le 8 Mar 2020
Clôturé : MATLAB Answer Bot le 20 Août 2021
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 commentaires
Walter Roberson
Walter Roberson le 8 Mar 2020
What does sin(90) mean?
Ameer Hamza
Ameer Hamza le 8 Mar 2020
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.

Réponses (1)

Chidvi Modala
Chidvi Modala le 11 Mar 2020
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

Cette question est clôturée.

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by