Getting negative y-intercept of a line

142 Views Asked by At

I am quite weak in mathematics and stuck in a problem. I am fitting the data points to a line and then computing the y-intercept. Problem here is that sometimes the y-intercept becomes negative which makes no sense to me. I have implemented an algorithm in C# and also used the following MATLAB code:

plot(time, f1, 'b*-', 'LineWidth', 2, 'MarkerSize', 15);
coeffs = polyfit(time, f1, 1);
% Get fitted values
fittedX = linspace(min(time), max(time), 200);
fittedY = polyval(coeffs, fittedX);
% Plot the fitted line
hold on;
plot(fittedX, fittedY, 'r-', 'LineWidth', 3);

Output figure is inserted below:

enter image description here

coeff(2) should be the y-intercept which is negative in the my case. Someone please explain this behavior.

1

There are 1 best solutions below

3
On BEST ANSWER

Look at your $x$-axis and your $y$-axis. $x = 0$ cannot be seen in the plot because it is far left. If you continue your line to the left (just straight continuation) it is for sure possible, that in $x = 0$ the corresponding $y$ value is negative.