- the actual line of code that threw the error,
- the line number,
- the error description,
- etc.
I am doing this assignment for school and I keep getting a specific error even though my code works properly.
조회 수: 1 (최근 30일)
이전 댓글 표시
% 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.');
fprintf('The x coordinate of the point of impact is %3.2f ft.\n',x1);
disp('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);
fprintf('\n');
disp ('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
Cris LaPierre
2021년 9월 15일
I ran your code in your original post (you can now see outputs inline with the code). There was no error message.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Equation Solving에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!