Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Some data points have been created in which the y values rise to a peak and then

ID: 3711192 • Letter: S

Question

Some data points have been created in which the y values rise to a peak and then fall again. However, instead of fitting a quadratic curve through these points, it is desired to fit two straight lines through these points: one through all points from the beginning through the point with the largest y value, and another that starts with the point with the largest y value through the last point. Write a function fscurve that will receive as input arguments the x and y vectors, and will plot the original points as red stars (*) and the two lines (with default colors, line widths, etc.). The Figure below shows the Figure Window resulting from an example of calling the function.

>> y = [2 4.3 6.5 11.11 8.8 4.4 3.1];

>> x = 1:length(y);

>> fscurve(x,y)

Figure Two straight lines

Do not assume that you know anything about the data except that you may assume that they do rise to a peak and then fall again.

Explanation / Answer

function fscurve(x,y)
maxY = max(y)
maxX = find(y == maxY)
figure
plot(x,y,'*','MarkerEdgeColor','red')
hold on
plot([x(1) maxX],[y(1) maxY])
hold on
plot([maxX x(length(x))],[maxY y(length(y))])
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote