The distance traveled by a ball falling in the air is given by the equation x = x_{0} + v_{0}*t + 1/2 * a * t ^ 2

18 次查看(过去 30 天)
The distance traveled by a ball falling in the air is given by the equation x = x_{0} + v_{0}*t + 1/2 * a * t ^ 2 Use MATLAB to calculate the position of the ball at time t = 5s x_{0} = 10m v_{0} = 15m / s and a = - 9.81m / (s ^ 2)
  6 个评论
Dyuman Joshi
Dyuman Joshi 2024-2-21
编辑:Dyuman Joshi 2024-2-21
You have calculated the displacement of the ball, but the question asks for position.
Now, how will you calculate position from the given value?
Torsten
Torsten 2024-2-21
Use MATLAB to calculate the position of the ball at time t = 5s x_{0} = 10m v_{0} = 15m / s and a = - 9.81m / (s ^ 2)
Just put the values in the equation.
x = 10 + 15*5 + 1/2 * (-9.81) * 5^2
x = -37.6250
Thus the ball made a big hole in the ground.

请先登录,再进行评论。

回答(2 个)

Sam Chak
Sam Chak 2024-2-21
It might be beneficial for you to explore how to utilize MATLAB for solving dynamical equations, particularly when dealing with systems where the states change over time. In your case, the dynamical equation for the falling ball with neglected air resistance can be expressed through this equation:
, with m and m/s.
By performing double integration, you can obtain an analytical solution, as you described in your question.
%% Unrealistic simulation of a falling ball by naively solving the ODE in pure math's way
tspan = [0 5];
y0 = [10, 15]; % initial values y = 10 m, v = 15 m/s
[t, y] = ode45(@falling, tspan, y0);
%% Plot results
figure
plot(t, y), grid on
legend('ball''s height', 'ball''s velocity')
title('Unrealistic simulation of a falling ball'), xlabel t
%% ball's height at the end of simulation
h = y(:,1);
h(end)
ans = -37.6250
%% Slightly realistic simulation of a falling ball
options = odeset('RelTol', 1e-8, 'AbsTol', 1e-10, 'Events', @touchDownEventFcn);
[t, y] = ode45(@falling, tspan, y0, options);
%% Plot results
figure
plot(t, y), grid on
legend('ball''s height', 'ball''s velocity')
title('Slightly realistic simulation of a falling ball'), xlabel t
%% the time when ball touches the surface
t(end)
ans = 3.6211
%% ---- Put local functions here -----
%% Function 1: Falling motion of a non-elastic solid ball when air resistance is neglected
function dydt = falling(t, y)
a = -9.81; % gravity
dydt(1,1) = y(2); %
dydt(2,1) = a;
end
%% Function 2: Stop simulation when the ball has touched the hard surface without deformation or bouncing
function [position, isterminal, direction] = touchDownEventFcn(t, y)
position = y(1); % The state variable that we want to be zero
isterminal = 1; % Halt integration
direction = -1; % The zero can be approached when x1 is decreasing
end
  1 个评论
Sam Chak
Sam Chak 2024-2-21
@Felix Jim, you can also use MATLAB to solve this equation
to determine the time when the ball hits the ground.
help fzero
FZERO Single-variable nonlinear zero finding. X = FZERO(FUN,X0) tries to find a zero of the function FUN near X0, if X0 is a scalar. It first finds an interval containing X0 where the function values of the interval endpoints differ in sign, then searches that interval for a zero. FUN is a function handle. FUN accepts real scalar input X and returns a real scalar function value F, evaluated at X. The value X returned by FZERO is near a point where FUN changes sign (if FUN is continuous), or NaN if the search fails. X = FZERO(FUN,X0), where X0 is a vector of length 2, assumes X0 is a finite interval where the sign of FUN(X0(1)) differs from the sign of FUN(X0(2)). An error occurs if this is not true. Calling FZERO with a finite interval guarantees FZERO will return a value near a point where FUN changes sign. X = FZERO(FUN,X0), where X0 is a scalar value, uses X0 as a starting guess. FZERO looks for an interval containing a sign change for FUN and containing X0. If no such interval is found, NaN is returned. In this case, the search terminates when the search interval is expanded until an Inf, NaN, or complex value is found. Note: if the option FunValCheck is 'on', then an error will occur if an NaN or complex value is found. X = FZERO(FUN,X0,OPTIONS) solves the equation with the default optimization parameters replaced by values in the structure OPTIONS, an argument created with the OPTIMSET function. See OPTIMSET for details. Used options are Display, TolX, FunValCheck, OutputFcn, and PlotFcns. X = FZERO(PROBLEM) finds the zero of a function defined in PROBLEM. PROBLEM is a structure with the function FUN in PROBLEM.objective, the start point in PROBLEM.x0, the options structure in PROBLEM.options, and solver name 'fzero' in PROBLEM.solver. [X,FVAL]= FZERO(FUN,...) returns the value of the function described in FUN, at X. [X,FVAL,EXITFLAG] = FZERO(...) returns an EXITFLAG that describes the exit condition. Possible values of EXITFLAG and the corresponding exit conditions are 1 FZERO found a zero X. -1 Algorithm terminated by output function. -3 NaN or Inf function value encountered during search for an interval containing a sign change. -4 Complex function value encountered during search for an interval containing a sign change. -5 FZERO may have converged to a singular point. -6 FZERO can not detect a change in sign of the function. [X,FVAL,EXITFLAG,OUTPUT] = FZERO(...) returns a structure OUTPUT with the number of function evaluations in OUTPUT.funcCount, the algorithm name in OUTPUT.algorithm, the number of iterations to find an interval (if needed) in OUTPUT.intervaliterations, the number of zero-finding iterations in OUTPUT.iterations, and the exit message in OUTPUT.message. Examples FUN can be specified using @: X = fzero(@sin,3) returns pi. X = fzero(@sin,3,optimset('Display','iter')) returns pi, uses the default tolerance and displays iteration information. FUN can be an anonymous function: X = fzero(@(x) sin(3*x),2) FUN can be a parameterized function. Use an anonymous function to capture the problem-dependent parameters: myfun = @(x,c) cos(c*x); % The parameterized function. c = 2; % The parameter. X = fzero(@(x) myfun(x,c),0.1) Limitations X = fzero(@(x) abs(x)+1, 1) returns NaN since this function does not change sign anywhere on the real axis (and does not have a zero as well). X = fzero(@tan,2) returns X near 1.5708 because the discontinuity of this function near the point X gives the appearance (numerically) that the function changes sign at X. See also ROOTS, FMINBND, FUNCTION_HANDLE. Documentation for fzero doc fzero Other uses of fzero optim/fzero

请先登录,再进行评论。


VBBV
VBBV 2024-2-21
Here is another simple way to find the position
t = 0:0.01:10; % consider a time vector for ball displacement (say 10s)
x0 = 10;
v0 = 15;
a = -9.81; % acceleration
x = x0+v0*t+0.5*a*t.^2;
hold on
plot(t,x); ylim([-50 50])
idx = t == 5; % find the index of 5s in time vector
plot(t(idx),x(idx),'r+','MarkerSize',20,'Linewidth',2); xlabel('time [s]');ylabel('position'); grid

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by