polyfitZero
Fit polynomial to data, forcing y-intercept to zero or arb. value and slope to zero or arb. value
Author: Mark Mikofski

I wonder if you could modify the routine so that higher powers could also be forced to be zero. For example, the current routine set the constant coefficient to zero. But, can the 1st order coefficient also be forced to be zero. And so on...

A couple of modifications that could be implemented.

Let there be one input, the order of the denominator, and accept an array. Calculate rms error and return that for the array. Could either set the numerator to the denominator, or sweep the numerator from 2 to the order of the denominator.

Incorporate a lag term, including raising the exponent to a power.

In your examples, you may want to include extracting the polynomial from a psd, generating a time history from a filter on rand, and replotting the resulting psd for comparison.

Thank you for writinig this, it does generate an interesting set of colors that do appear to be contrasting. Would it be possible to generate one, or more, "key" colors that are highly contasted with the rest. I have about 30 lines on a figure, along with the average. While I did make the average wider, it is difficult to determine the color for the "key" line(s) using this routine.

I'm having trouble with this routine. In the example below, the x and y ranges dont' seem to be correct, and also the distribution doesn't look right either.

function hist3_test
close all; clc;
events = 1000000;
xrange=0:.1:1;
nxs=length(xrange);
x=[]; y=[];
for xx=0:.1:1
xs=xx+sqrt(0.005)*randn(round(events/nxs),1);
if (xx<.3)
ys=cos(xs)+ sqrt(0.001)*randn(round(events/nxs),1);
else
ys=cos(xs)+ sqrt(0.1)*randn(round(events/nxs),1);
end
x = [x; xs];
y = [y; ys];
end