
12

 DAS


Thank you Doug for your response!
I would like to fit some data to a curve using pade approximation. I have
used polyfit and it worked reasonably well, but I think pade may give the
most accurate fit equation.
This is the data I would like to fit 
2.35504, 0.87524, 0.76141, 0.87769, 3.08380, 1.01227, 0.77118, 4.92401,
0.68878 , 0.87189 , 2.60315 0.70099 , 0.85419 , 9.17908, 1.07910 ,
0.80322 , 2.39624 , 3.36853 , 1.19812 , 0.66193 , 0.78033
When I use this data as an argument to padecoef, I get the following
exception 
error: padecoef: T must be a nonnegative scalar
error: called from
padecoef at line 92 column 5
padefunction at line 12 column 12
Do I have to convert the data to some form?
Please let me know.
Thank you,
Vivek.

Sent from: https://octave.1599824.n4.nabble.com/OctaveGeneralf1599825.html


Thank you Doug for your response!
I would like to fit some data to a curve using pade approximation. I have
used polyfit and it worked reasonably well, but I think pade may give the
most accurate fit equation.
This is the data I would like to fit 
2.35504, 0.87524, 0.76141, 0.87769, 3.08380, 1.01227, 0.77118, 4.92401,
0.68878 , 0.87189 , 2.60315 0.70099 , 0.85419 , 9.17908, 1.07910 ,
0.80322 , 2.39624 , 3.36853 , 1.19812 , 0.66193 , 0.78033
When I use this data as an argument to padecoef, I get the following
exception 
error: padecoef: T must be a nonnegative scalar
error: called from
padecoef at line 92 column 5
padefunction at line 12 column 12
Do I have to convert the data to some form?
Please let me know.
Thank you,
Vivek.

Sent from: https://octave.1599824.n4.nabble.com/OctaveGeneralf1599825.html
I need to see your code.
 DAS


Hi Doug,
Here is the code 
input = [0.0036621,
2.3550415,
0.8752441,
66.8194580,
0.7614136,
0.8776855,
3.0838013,
1.0122681,
0.7711792,
4.9240112,
0.6887817,
0.8718872,
2.6031494
0.7009888,
18.9779663,
0.0021362,
0.0030518,
0.8541870,
9.1790771,
1.0791016,
80.2191162
0.0125122,
0.8032227,
2.3962402,
3.3685303,
0.0018311,
0.0054932,
1.1981201,
0.6619263,
0.7803345];
j = 1;
AreaT = 0;
for i = 1:size(input)
if(input(i) > 0 && input(i) < 10)
AreaT(j) = input(i);
j++;
end
end
[num, den] = padecoef(AreaT);

Sent from: https://octave.1599824.n4.nabble.com/OctaveGeneralf1599825.html


Hi Doug,
Here is the code 
input = [0.0036621,
2.3550415,
0.8752441,
66.8194580,
0.7614136,
0.8776855,
3.0838013,
1.0122681,
0.7711792,
4.9240112,
0.6887817,
0.8718872,
2.6031494
0.7009888,
18.9779663,
0.0021362,
0.0030518,
0.8541870,
9.1790771,
1.0791016,
80.2191162
0.0125122,
0.8032227,
2.3962402,
3.3685303,
0.0018311,
0.0054932,
1.1981201,
0.6619263,
0.7803345];
j = 1;
AreaT = 0;
for i = 1:size(input)
if(input(i) > 0 && input(i) < 10)
AreaT(j) = input(i);
j++;
end
end
[num, den] = padecoef(AreaT);

Sent from: https://octave.1599824.n4.nabble.com/OctaveGeneralf1599825.html
padecoef is not curve fitting code. It just approximates a delay in the input data. I don't know what you are trying to do, So I can't help you
 DAS


On Thu, Oct 31, 2019 at 7:15 PM vivek guajri < [hidden email]> wrote:
>
> Okay. Thank you for letting me know.
> I thought it is similar to polyfit function where it fits the data to a
> polynomial equation.
If you want to fit the data to orthogonal polynomials than you want to
use something like Chebyshev
or Legendre polinomial fit. Pade is to approximate functions not data.
Dmitri.



Thank you Dmitri for your response! I do not want to fit orthogonal
polynomials!
I have some data and would like to fit it to a polynomial equation. The
polyfit function is fine, but I need something which can fit better than
that. Maybe a combination of polyfit and lsqin will do the job!

Sent from: https://octave.1599824.n4.nabble.com/OctaveGeneralf1599825.html


Vivek,
> Original Message
> From: Helpoctave <helpoctave
> bounces+allen.windhorn= [hidden email]> On Behalf Of vivek
> guajri
>
> I have some data and would like to fit it to a polynomial equation. The
> polyfit function is fine, but I need something which can fit better than
> that. Maybe a combination of polyfit and lsqin will do the job!
The polyfit function fits the BEST POSSIBLE polynomial to your data, as long
as you want the "best" in a leastsquare sense, so it's no use trying to find
a better polynomial. If you want "best" in a minimax sense then Chebyshev
is the way to go. But generally most data isn't wellfit by a highorder
polynomial  the higher the order, the more it wants to shoot off to infinity,
and real data generally don't go there. So you probably want to fit another
type of function instead of a polynomial.
You may have been on the right track with a Pade approximant, which fits a
rational function, but apparently the Pade package is for some specialized
purpose and not suitable for function fitting. You can use leasqr to fit any
function including rational functions. It's in the optim package.
The data you provided had only Y values  are the X values equally spaced?
Plotting the data, it's very "spiky" and probably hopeless to fit any kind of
reasonable function to it, certainly not a polynomial. What are you trying
to predict?
Regards,
Allen


In the plot you can see that there are some negative slopes in the fit
function. How do I make it nondecreasing?

Sent from: https://octave.1599824.n4.nabble.com/OctaveGeneralf1599825.html
Hi Vivek,
There is no standard way to do this, and I can't see any straight forward way to do so, even if you set this up as a kind of constrained optimization, for example even if you were fitting a 3rd degree polynomial ax^3 + bx^2 + cx^1 + dx^0
Then you could put a constraint that the first derivative is positive or zero:
3ax^2 + 2bx^1 + cx^0 >= 0
But this would still only be a constraint at the values for x in your data set, and not for all positive(?) values for x that you seem to want it for.
Hope this helps,
James Sherman Jr.


In reply to this post by Octave  General mailing list
Yes, the data is different from the previous data I sent.
The data is from our in built neutron spectrometer. The y values are the
area values of the pulses and x values are just the normalized ascending
ordered number. I do not know the uncertainty or model of the data at this
point!

Sent from: https://octave.1599824.n4.nabble.com/OctaveGeneralf1599825.html


PCHIP [1] is an interpolation method that is guaranteed to be preserve monotonicity. If the data has noise, you can fit a nonparametric monotone function to it using, e.g. monotone_smooth [2].


On 11/1/19 3:19 PM, vivek guajri wrote:
> The data is from our in built neutron spectrometer. The y values are the
> area values of the pulses and x values are just the normalized ascending
> ordered number. I do not know the uncertainty or model of the data at this
> point!
As it happens, I am involved with neutron spectroscopy so if you explain
how you set up your experiment I may be able to suggest a way to get
some useful information from the data.


Vivek,
> Original Message
> From: Helpoctave <helpoctave
> bounces+allen.windhorn= [hidden email]> On Behalf Of vivek
> guajri
>
> Yes, I think I am going to just constrain the polynomial to be nondecreasing
> wherever there is negative slope! That should be the closest I can get!
Generally there is some physical principle that determines the curve you should be fitting  is that true in this case?
Getting offtopic a bit, but curve fitting being a hobby of mine, I used a function 0.005276*(exp(7.66x)1)+0.66 which is guaranteed monotonic and fit pretty well. I didn't even bother with Octave, just fit it in Excel using Solver.
Regards,
Allen

12
