% Bug in polyfit:
% Different polynomial coefficients when using optional output
% ------------------------------------------------------------
% Reported by Nicole Droege, nicole.droege@mubea.com
% 05.10.2015

clc;clear all;close all

diary on

disp('-------------------------------------------------------------')
disp('Bug in polyfit:')
disp('Different polynomial coefficients when using optional output')
disp('-------------------------------------------------------------')

disp(['Octave version: ',version()])
disp(['Computer: ',computer])
disp(strftime("%d.%m.%Y, %H:%M:%S",	localtime(time())));
disp(' ')

% Test data:
x = [1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0]
y = [0.5 4.5 2.1 3.0 2.3 1.4 7.8 9.2 3.6]
N = 1

% Polyfit:
p1 = polyfit(x,y,N)
[p2,s,mu] = polyfit(x,y,N)
disp(' ')

% Evaluation:
disp('Expectation: delta := p1 - p2 = 0, but reality is delta != 0')
delta = p1 - p2

disp('-------------------------------------------------------------')

diary off
rename('diary',['Bug_polyfit_Octave',version,'.out']);

% ------------------------------------------------------------