Problem 61142. Shifting vertically a function's graph

Given a real function, f, by n input-output pairs, consider a translation in the up-down direction given by an amount k.
For a real constant k, you may assume that the translation is given. However, if k = 'mean', you firstly must determine the real constant k such that the translated function has an average value of 0 over the given interval (see figure below).
Find
  • y_shifted, which is the 1×n vector that stands for the outputs of the translated function;
  • v, which stands for either 'up' or 'down' if the function's graph is upward or downward shifted, respectively, and it stands for '' if the graph does not undergo a translation.
Hint. Calculate the mean of a piecewise linear discrete function, represented as an array of x and an array of y values. Be aware to the existence of calculus discrepancies whenever the function f will be continuous, but not piecewise linear.
input: (x, y, k)
output: [y_shifted, v]
Vertical shift

Solution Stats

100.0% Correct | 0.0% Incorrect
Last Solution submitted on Dec 29, 2025

Solution Comments

Show comments

Problem Recent Solvers1

Suggested Problems

More from this Author10

Community Treasure Hunt

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

Start Hunting!