help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] Doubt (bug?) in gsl_fit_linear function


From: Juan Pablo Amorocho D.
Subject: Re: [Help-gsl] Doubt (bug?) in gsl_fit_linear function
Date: Sat, 9 Jun 2012 18:47:52 +0200

Hi Ruchin,

Note that the value of m in y = mx+b in your problem is \infty. Just in
case, here is the code:

/*
 * linear.c
 *
 *  Created on: Jun 9, 2012
 *      Author: jamoroch
 */


#include <stdlib.h>
#include <stdio.h>
#include "gsl/gsl_fit.h"

int main(){

    double *x, *y;

    double c0 = 0., c1 = 0, cov00 = 0., cov01 = 0., cov11 = 0., sumsq = 0.;

    const int N = 5;
    int i = 0;

    x = (double*) calloc(N, sizeof(double));

    y = (double*) calloc(N, sizeof(double));

    for(i = 0; i < N; i++)
        x[i] = 50.0;

    for(i = 0; i < N; i ++)
        y[i] = i + 49.0;

    gsl_fit_linear (x, 1, y, 1, N, &c0, &c1, &cov00, &cov01, &cov11,
&sumsq);

    printf("c0 = %f\nc1 = %f\ncov00 = %f\ncov01 = %f\ncov11 = %f\nsumsq =
%f", c0, c1, cov00, cov01, cov11, sumsq);

    return 0;
}

Cheers,

Juan


2012/6/9 Ruchin Kansal <address@hidden>

> Hi,
>
> I am using gsl_fit_linear to fit a straight line through my data samples.
> Incidentally, I came across a situation when
> the data samples lie on a vertical line. I observed that in this case
> gsl_fit_linear returns everything as (nan). Is it a known behavior or there
> may be something wrong at my end?
>
> I passed the following data samples to this function:
> {(50, 52), (50, 50), (50, 53), (50, 49), (50, 51)}
>
> Please help.
>
> Regards,
> Ruchin.
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]