function output = perf(FROM)
% This function returns the RMSE performance of predicting a time series.
%	It calculates the RMSE of the time span [FROM, FROM+999];

if nargin < 1, FROM = 1000; end

span = 1000;
TO = FROM+span-1;
[t, x, y] = rk45('blackbox', [0, TO]);
%plot(t, x, '.');
xlabel('Time (second)');
title('Time Series');

% At time = t, we want to predict x(t+1) based on x(t), x(t-1), ..., x(0).
% We assume the true value of x(t), x(t-1), ... x(0) are known at time = t.

% The prediction is perform from t = FROM to TO
predicted = zeros(size(x));
for i = FROM:TO,
	predicted(i) = mymodel(x(1:i-1));
end
error = x(FROM:TO)-predicted(FROM:TO);
output = norm(error)/sqrt(span); 

subplot(2,1,1);
plot(t(FROM:TO), [x(FROM:TO) predicted(FROM:TO)]);
axis([-inf inf -inf inf]);
title('Actual and predicted time series');

subplot(2,1,2);
plot(t(FROM:TO), x(FROM:TO)-predicted(FROM:TO));
title('Prediction error');
axis([-inf inf -inf inf]);
