57.6k views
2 votes
Piecewise functions are sometimes useful when the relationship between a dependent and an independent variable cannot be adequately represented by a single equation. For example, the velocity [in m/s] of a rocket might be described by:

[image]

Develop a script to compute v as a function of t where t = 0 to 50 seconds with a step size of 1.

Use relational operators and logical array indexing to determine the pieces of the t vector that correspond to each velocity equation.

Compute your velocities

Combine the velocities you calculated into a single velocity vector.

Generate a plot of velocity over time. Don't forget to properly label your axes.

Determine the maximum velocity the rocket reaches. Do not output this value yet.

The escape velocity from the surface of Mercury is 4250 m/s. If the rocket is launched from Mercury will the rocket reach escape velocity? Use conditionals to answer this question. Your answer should be include both the maximum velocity and the escape velocity in the text. The max velocity should have 2 decimals and the escape velocity should be a whole number. Make sure that you are using variables for values found by the script instead of typing values. The conditions must be able to work correctly even if the maximum velocity and escape velocities were different values.

Piecewise functions are sometimes useful when the relationship between a dependent-example-1
User Sarahjayne
by
8.7k points

1 Answer

5 votes

Answer:

"The rocket does not reach escape velocity."

Step-by-step explanation:

% Define time vector from 0 to 50 seconds with a step size of 1.

t = 0:1:50;

% Initialize velocity vector.

v = zeros(size(t));

% Calculate velocities for each time interval.

% Use relational operators to determine the appropriate equation.

v(t >= 0 & t < 5) = 100*t(t >= 0 & t < 5);

v(t >= 5 & t < 10) = 500;

v(t >= 10 & t < 15) = 2000 - 100*t(t >= 10 & t < 15);

v(t >= 15 & t <= 50) = 500 - 10*(t(t >= 15 & t <= 50) - 15);

% Calculate the maximum velocity.

max_velocity = max(v);

% Escape velocity from Mercury (you can change this value if needed).

escape_velocity_mercury = 4250;

% Determine if the rocket reaches escape velocity.

if max_velocity >= escape_velocity_mercury

fprintf('The rocket reaches escape velocity.\\');

else

fprintf('The rocket does not reach escape velocity.\\');

end

% Generate a plot of velocity over time.

figure;

plot(t, v, 'b', 'LineWidth', 1.5);

xlabel('Time (s)');

ylabel('Velocity (m/s)');

title('Rocket Velocity vs. Time');

grid on;

% Display the maximum velocity and escape velocity.

fprintf('Maximum velocity: %.2f m/s\\', max_velocity);

fprintf('Escape velocity from Mercury: %d m/s\\', escape_velocity_mercury);

Sorry if the code is formatted incorrectly.

User HoosierDaddy
by
9.0k points