I am doing this assignment for school and I keep getting a specific error even though my code works properly.

5 views (last 30 days)
% Please enter your name inside the single quotes in the next line
name = 'Segesman Francis'; % Last Name, First Name
syms t1 x1 vy1; % Unknowns
assume(x1>0); % Eliminate the negative value of the double solution
assume(t1>0);
syms t x vy y; % Variables of integration
% Given
v0 = 100; % [ft/s]
theta = 60*pi/180; % [rad] Keep in mind that we will use the angle with cos rather than cosd
vx = v0*cos(theta); % Note the difference between cos and cosd.
t0 = 0;
x0 = 0;
ay = -32.2; % [ft/s^2]
y0 = 0;
vy0 = v0*sin(theta);
y1 = -0.001*x1^2;
% Solve
eqn1 = int(vx,t,t0,t1) == int(1,x,x0,x1);
eqn2 = int(ay,t,t0,t1) == int(1,vy,vy0,vy1); % Complete this line to define the second equation
eqn3 = int(ay,y,y0,y1) == int(vy,vy,vy0,vy1); % Pay attention to the integrand or the function to be integrated on the right-hand side.
[x1 t1 vy1] = solve([eqn1 eqn2 eqn3], [x1, t1, vy1]);
% If you have trouble completing the previous line, check out WK1MATLAB1 which is to solve a system of two equations.
% Display
disp('You should get: The x coordinate of the point of impact is 318.39 ft.');
You should get: The x coordinate of the point of impact is 318.39 ft.
fprintf('The x coordinate of the point of impact is %3.2f ft.\n',x1);
The x coordinate of the point of impact is 318.39 ft.
disp('You should get: The x coordinate of the point of impact is 318 ft.');
You should get: The x coordinate of the point of impact is 318 ft.
fprintf('The x coordinate of the point of impact is %.3g ft.\n',x1);
The x coordinate of the point of impact is 318 ft.
fprintf('\n');
disp ('Can you tell the difference between %f and %g?');
Can you tell the difference between %f and %g?
fprintf('\n');
nameInfo = isempty(name);
if (nameInfo==1)
disp('Please enter your name in Line 2.');
end;
%whenever I run this, i get this error: Variable x1 must be of size [1 1]. It is currently of size [0 1]. Check where the variable is assigned a value
% the program works, I am getting the correct numbers, but it looks like
% something about how the number is being stored is off.
  3 Comments
Francis Segesman
Francis Segesman on 15 Sep 2021
i did, It is outputting the right number but complaining that it isnt in the correct format, all it gives me is:
Variable x1 must be of size [1 1]. It is currently of size [0 1]. Check where the variable is assigned a value.
and nothing else. it does all of the math right, just outputs that I think there may be something wrong with how it is being checked
Cris LaPierre
Cris LaPierre on 15 Sep 2021
I ran your code in your original post (you can now see outputs inline with the code). There was no error message.

Sign in to comment.

Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!