Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am new to matlab and I do not know to figure this out. When I try to run my pr

ID: 3622089 • Letter: I

Question

I am new to matlab and I do not know to figure this out. When I try to run my program or code I get errors that say :
??? distance = input("Enter the distance for the target (must be >= 0): ");
|
Error: The input character is not valid in MATLAB statements or expressions.

Please help me figure this out.
My code is:

distance = -1;
v0 = -1;
theta = -1;
g = -9.81;

while(distance < 0)
distance = input("Enter the distance for the target (must be >= 0): ");
if (distance < 0)
disp("Please enter a distance greater than or equal to 0")
end
end

disp("The distance of the target is")
disp(distance)

while(v0 < 0)
v0 = input("What is the initial velocity of the projectile? ");
if(v0 < 0)
disp("Please enter a velocity greater than 0")
end
end

while(theta < 0 || theta > 90)
theta = input("What is the initial angle the projectile will be fired at? ");
if(theta < 0 || theta > 90)
disp("Please enter an angle between 0 and 90 degrees")
end
end

theta = theta*(pi/180);

v_y0 = v0*sin(theta);
v_x0 = v0*cos(theta);

t = -2*v_y0/g;
x = 0 + v_x0*t;

if((distance - x) > 2)
disp("You were short")

elseif((distance - x) < -2)
disp("You were long")

else
disp("You hit!")
end


disp("Time X Y")
t = 0:t/40:t;

for i=1:41
x = v_x0*t(i);
y = 0 + v_y0*t(i)+0.5*g*t(i)^2;
data = [t(i),x,y];
disp(data)
end

Explanation / Answer

Dear, entered quotation mistake, instead of single quotaion ', entered double quotation " after changed the quotation, program as follows >> distance = -1; v0 = -1; theta = -1; g = -9.81; while(distance < 0) distance = input('Enter the distance for the target (must be >= 0): '); if (distance < 0) disp('Please enter a distance greater than or equal to 0') end end disp('The distance of the target is') disp(distance) while(v0 < 0) v0 = input('What is the initial velocity of the projectile? '); if(v0 < 0) disp('Please enter a velocity greater than 0') end end while(theta < 0 || theta > 90) theta = input('What is the initial angle the projectile will be fired at? '); if(theta < 0 || theta > 90) disp('Please enter an angle between 0 and 90 degrees') end end theta = theta*(pi/180); v_y0 = v0*sin(theta); v_x0 = v0*cos(theta); t = -2*v_y0/g; x = 0 + v_x0*t; if((distance - x) > 2) disp('You were short') elseif((distance - x) < -2) disp('You were long') else disp('You hit!') end disp('Time X Y') t = 0:t/40:t; for i=1:41 x = v_x0*t(i); y = 0 + v_y0*t(i)+0.5*g*t(i)^2; data = [t(i),x,y]; disp(data) end
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote