⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test2d.c

📁 该文件为c++的数学函数库!是一个非常有用的编程工具.它含有各种数学函数,为科学计算、工程应用等程序编写提供方便!
💻 C
📖 第 1 页 / 共 2 页
字号:
/* histogram/test2d.c *  * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough *  * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. *  * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#include <config.h>#include <stdlib.h>#include <stdio.h>#include <gsl/gsl_errno.h>#include <gsl/gsl_math.h>#include <gsl/gsl_machine.h>#include <gsl/gsl_histogram2d.h>#include <gsl/gsl_test.h>#include <gsl/gsl_ieee_utils.h>#define M 107#define N 239#define M1 17#define N1 23#define MR 10#define NR 5voidtest2d (void){  double xr[MR + 1] =    { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 };  double yr[NR + 1] = { 90.0, 91.0, 92.0, 93.0, 94.0, 95.0 };  gsl_histogram2d *h, *h1, *g, *hr;  size_t i, j, k;  gsl_ieee_env_setup ();  h = gsl_histogram2d_calloc (M, N);  h1 = gsl_histogram2d_calloc (M, N);  g = gsl_histogram2d_calloc (M, N);  gsl_test (h->xrange == 0,            "gsl_histogram2d_calloc returns valid xrange pointer");  gsl_test (h->yrange == 0,            "gsl_histogram2d_calloc returns valid yrange pointer");  gsl_test (h->bin == 0, "gsl_histogram2d_calloc returns valid bin pointer");  gsl_test (h->nx != M, "gsl_histogram2d_calloc returns valid nx");  gsl_test (h->ny != N, "gsl_histogram2d_calloc returns valid ny");  hr = gsl_histogram2d_calloc_range (MR, NR, xr, yr);  gsl_test (hr->xrange == 0,            "gsl_histogram2d_calloc_range returns valid xrange pointer");  gsl_test (hr->yrange == 0,            "gsl_histogram2d_calloc_range returns valid yrange pointer");  gsl_test (hr->bin == 0,            "gsl_histogram2d_calloc_range returns valid bin pointer");  gsl_test (hr->nx != MR, "gsl_histogram2d_calloc_range returns valid nx");  gsl_test (hr->ny != NR, "gsl_histogram2d_calloc_range returns valid ny");  {    int status = 0;    for (i = 0; i <= MR; i++)      {        if (hr->xrange[i] != xr[i])          {            status = 1;          }      };    gsl_test (status,              "gsl_histogram2d_calloc_range creates xrange");  }  {    int status = 0;    for (i = 0; i <= NR; i++)      {        if (hr->yrange[i] != yr[i])          {            status = 1;          }      };    gsl_test (status,              "gsl_histogram2d_calloc_range creates yrange");  }  for (i = 0; i <= MR; i++)    {      hr->xrange[i] = 0.0;    }  for (i = 0; i <= NR; i++)    {      hr->yrange[i] = 0.0;    }  {    int status = gsl_histogram2d_set_ranges (hr, xr, MR + 1, yr, NR + 1);    for (i = 0; i <= MR; i++)      {        if (hr->xrange[i] != xr[i])          {            status = 1;          }      };    gsl_test (status, "gsl_histogram2d_set_ranges sets xrange");  }  {    int status = 0;    for (i = 0; i <= NR; i++)      {        if (hr->yrange[i] != yr[i])          {            status = 1;          }      };    gsl_test (status, "gsl_histogram2d_set_ranges sets yrange");  }  k = 0;  for (i = 0; i < M; i++)    {      for (j = 0; j < N; j++)        {          k++;          gsl_histogram2d_accumulate (h, (double) i, (double) j, (double) k);        };    }  {    int status = 0;    k = 0;    for (i = 0; i < M; i++)      {        for (j = 0; j < N; j++)          {            k++;            if (h->bin[i * N + j] != (double) k)              {                status = 1;              }          }      }    gsl_test (status,              "gsl_histogram2d_accumulate writes into array");  }  {    int status = 0;    k = 0;    for (i = 0; i < M; i++)      {        for (j = 0; j < N; j++)          {            k++;            if (gsl_histogram2d_get (h, i, j) != (double) k)              status = 1;          };      }    gsl_test (status, "gsl_histogram2d_get reads from array");  }  for (i = 0; i <= M; i++)    {      h1->xrange[i] = 100.0 + i;    }  for (i = 0; i <= N; i++)    {      h1->yrange[i] = 900.0 + i * i;    }  gsl_histogram2d_memcpy (h1, h);  {    int status = 0;    for (i = 0; i <= M; i++)      {        if (h1->xrange[i] != h->xrange[i])          status = 1;      };    gsl_test (status, "gsl_histogram2d_memcpy copies bin xranges");  }  {    int status = 0;    for (i = 0; i <= N; i++)      {        if (h1->yrange[i] != h->yrange[i])          status = 1;      };    gsl_test (status, "gsl_histogram2d_memcpy copies bin yranges");  }  {    int status = 0;    for (i = 0; i < M; i++)      {        for (j = 0; j < N; j++)          {            if (gsl_histogram2d_get (h1, i, j) !=                gsl_histogram2d_get (h, i, j))              status = 1;          }      }    gsl_test (status, "gsl_histogram2d_memcpy copies bin values");  }  gsl_histogram2d_free (h1);  h1 = gsl_histogram2d_clone (h);  {    int status = 0;    for (i = 0; i <= M; i++)      {        if (h1->xrange[i] != h->xrange[i])          status = 1;      };    gsl_test (status, "gsl_histogram2d_clone copies bin xranges");  }  {    int status = 0;    for (i = 0; i <= N; i++)      {        if (h1->yrange[i] != h->yrange[i])          status = 1;      };    gsl_test (status, "gsl_histogram2d_clone copies bin yranges");  }  {    int status = 0;    for (i = 0; i < M; i++)      {        for (j = 0; j < N; j++)          {            if (gsl_histogram2d_get (h1, i, j) !=                gsl_histogram2d_get (h, i, j))              status = 1;          }      }    gsl_test (status, "gsl_histogram2d_clone copies bin values");  }  gsl_histogram2d_reset (h);  {    int status = 0;    for (i = 0; i < M * N; i++)      {        if (h->bin[i] != 0)          status = 1;      }    gsl_test (status, "gsl_histogram2d_reset zeros array");  }  gsl_histogram2d_free (h);  h = gsl_histogram2d_calloc (M1, N1);  {    int status = 0;    for (i = 0; i < M1; i++)      {        for (j = 0; j < N1; j++)          {            gsl_histogram2d_increment (h, (double) i, (double) j);            for (k = 0; k <= i * N1 + j; k++)              {                if (h->bin[k] != 1)                  {                    status = 1;                  }              }            for (k = i * N1 + j + 1; k < M1 * N1; k++)              {                if (h->bin[k] != 0)                  {                    status = 1;                  }              }          }      }    gsl_test (status, "gsl_histogram2d_increment increases bin value");  }  gsl_histogram2d_free (h);  h = gsl_histogram2d_calloc (M, N);  {    int status = 0;    for (i = 0; i < M; i++)      {        double x0 = 0, x1 = 0;        gsl_histogram2d_get_xrange (h, i, &x0, &x1);        if (x0 != i || x1 != i + 1)          {            status = 1;          }      }    gsl_test (status,              "gsl_histogram2d_get_xlowerlimit and xupperlimit");  }  {    int status = 0;    for (i = 0; i < N; i++)      {        double y0 = 0, y1 = 0;        gsl_histogram2d_get_yrange (h, i, &y0, &y1);        if (y0 != i || y1 != i + 1)          {            status = 1;          }      }    gsl_test (status,              "gsl_histogram2d_get_ylowerlimit and yupperlimit");  }  {    int status = 0;    if (gsl_histogram2d_xmax (h) != M)      status = 1;    gsl_test (status, "gsl_histogram2d_xmax");  }  {    int status = 0;    if (gsl_histogram2d_xmin (h) != 0)      status = 1;    gsl_test (status, "gsl_histogram2d_xmin");  }  {    int status = 0;    if (gsl_histogram2d_nx (h) != M)      status = 1;    gsl_test (status, "gsl_histogram2d_nx");  }  {    int status = 0;    if (gsl_histogram2d_ymax (h) != N)      status = 1;    gsl_test (status, "gsl_histogram2d_ymax");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -