http://alexgorbatchev.com/SyntaxHighlighter/
2011年9月30日
Serial Programming(step 0:馬桶蓋)
好文章-講解set與get周邊device的原理
引用:http://www.programmer-club.com.tw/showsametitleN/c/39077.html
從 serial programming HOWTO 這份文件中讓我可以透過RS232 使得兩台電腦互相溝通,
但其中有一些不解的地方,想請各位幫我解答.
以下次一個完整的非標準的接收程式(serial programming HOWTO 中的範例)
其中有疑問的利用註解方式標示出來//???????????????????????????????????????????????????
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#define BAUDRATE B38400
#define MODEMDEVICE "/dev/ttyS1"
#define _POSIX_SOURCE 1 /* POSIX compliant source */
#define false 0
#define true 1
volatile int STOP=false;
main()
{
int fd,c, res;
struct termios oldtio,newtio;//?????????????????????????????????????????????????????
char buf[255];
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY );
if (fd <0) {perror(MODEMDEVICE); exit(−1); }
tcgetattr(fd,&oldtio); /* save current port settings *//???????????????????????????????????
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
/* set input mode (non−canonical, no echo,...) */
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 0; /* inter−character timer unused */
newtio.c_cc[VMIN] = 5; /* blocking read until 5 chars received */
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);//?????????????????????????????????????????????????????
while (STOP==false) { /* loop for input */
res = read(fd,buf,255); /* returns after 5 chars have been input */
buf[res]=0; /* so we can printf... */
printf(":%s:%d\n", buf, res);
if (buf[0]=='z') STOP=true;
}
tcsetattr(fd,TCSANOW,&oldtio);//??????????????????????????????????????????????????????
}
對於以上有//???????????????????的那幾行 我存在的主要疑問就是
為什麼要宣告兩個struct termios oldtio,newtio
事有什麼特別用途嗎? 是要備份嗎? 還是有其他原因呢?
答案其實很簡單,一個是 ..get..、另一個是..set..,也就是取得跟設定罷了。
當應用程式在存取周邊設備時,程式設計師必須記得一件事情,那就是各項周邊(通常來說)應該是大家共用的,當然,有時候會因系統架構上的特殊考量,出現讓某一個程式獨佔某一個周邊的情形,但這算是特例。讀過OS相關書籍的人應該會明白,其實作業系統的其中一項重要工作,就是讓所有周邊能夠開放給所有應用程式,但這是題外話,所以就此打住。
既然周邊是共用的,那麼當我需要使用時,我該怎麼做呢?這就像馬桶蓋的學問....???
男生宿舍的廁所裡,馬桶座通常都是翻起來的,為什麼?...這應該不用我說明;相反的,女生廁所的馬桶座通常都是保持放下的狀態,這也不需要我說明。如果你進入某人家的廁所,不論其馬桶座是處於何種狀態,以禮貌性來說,回復最初的位置,就是最好的策略!所以你在使用前,必須先記住它的位置(翻起或放下),然後才開始使用(可能是翻起或放下),完成後,再回復最早的狀態就行了。重點是,如果你一開始沒有先留意它的狀態,你就不知道該如何回復,這就可能要被主人白眼了!當然,好朋友可能不會在乎這種小事情,可是在程式運作上,卻會出現大災難喔!
除非你是很古老的程式人,否則你應該沒有機會在單人單工的環境下寫程式(Embedded System除外)。現代的程式設計幾乎都是在多工的假設下發展的,這意味著,同一時間會有很多程式在運行。當然,在單一CPU的電腦系統,一個時間只能服務一個行程(process/thread),但其他因呼叫IPC服務而處於Waiting/Blocking、或被 preemption 而 Suspend 的行程,仍可視為同時執行的個體,在這種情況下,你如果沒有適當地回復(周邊設備)先前的狀態,那麼另一個被停格(被點穴不能動)但回復運作(解穴)的程式就倒楣了!你能想像你放下馬桶座,一屁股坐下去,馬桶座竟然是翻起來的狀況嗎?你的反應會是........好涼喔~~~嗎?
周邊設備在使用前必須先設定參數,以RS232為例,你必須設定 Baud/Data/Stop/Parity等,一旦設定後,這些數值會儲存在周邊的控制暫存器裡,前述的 get 就是先取得目前暫存器的內容,再用 get 來設定你所需的,最後再用一次 get 來寫回原來的內容。
Good Luck.
引用:http://www.programmer-club.com.tw/showsametitleN/c/39077.html
從 serial programming HOWTO 這份文件中讓我可以透過RS232 使得兩台電腦互相溝通,
但其中有一些不解的地方,想請各位幫我解答.
以下次一個完整的非標準的接收程式(serial programming HOWTO 中的範例)
其中有疑問的利用註解方式標示出來//???????????????????????????????????????????????????
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#define BAUDRATE B38400
#define MODEMDEVICE "/dev/ttyS1"
#define _POSIX_SOURCE 1 /* POSIX compliant source */
#define false 0
#define true 1
volatile int STOP=false;
main()
{
int fd,c, res;
struct termios oldtio,newtio;//?????????????????????????????????????????????????????
char buf[255];
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY );
if (fd <0) {perror(MODEMDEVICE); exit(−1); }
tcgetattr(fd,&oldtio); /* save current port settings *//???????????????????????????????????
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
/* set input mode (non−canonical, no echo,...) */
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 0; /* inter−character timer unused */
newtio.c_cc[VMIN] = 5; /* blocking read until 5 chars received */
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);//?????????????????????????????????????????????????????
while (STOP==false) { /* loop for input */
res = read(fd,buf,255); /* returns after 5 chars have been input */
buf[res]=0; /* so we can printf... */
printf(":%s:%d\n", buf, res);
if (buf[0]=='z') STOP=true;
}
tcsetattr(fd,TCSANOW,&oldtio);//??????????????????????????????????????????????????????
}
對於以上有//???????????????????的那幾行 我存在的主要疑問就是
為什麼要宣告兩個struct termios oldtio,newtio
事有什麼特別用途嗎? 是要備份嗎? 還是有其他原因呢?
答案其實很簡單,一個是 ..get..、另一個是..set..,也就是取得跟設定罷了。
當應用程式在存取周邊設備時,程式設計師必須記得一件事情,那就是各項周邊(通常來說)應該是大家共用的,當然,有時候會因系統架構上的特殊考量,出現讓某一個程式獨佔某一個周邊的情形,但這算是特例。讀過OS相關書籍的人應該會明白,其實作業系統的其中一項重要工作,就是讓所有周邊能夠開放給所有應用程式,但這是題外話,所以就此打住。
既然周邊是共用的,那麼當我需要使用時,我該怎麼做呢?這就像馬桶蓋的學問....???
男生宿舍的廁所裡,馬桶座通常都是翻起來的,為什麼?...這應該不用我說明;相反的,女生廁所的馬桶座通常都是保持放下的狀態,這也不需要我說明。如果你進入某人家的廁所,不論其馬桶座是處於何種狀態,以禮貌性來說,回復最初的位置,就是最好的策略!所以你在使用前,必須先記住它的位置(翻起或放下),然後才開始使用(可能是翻起或放下),完成後,再回復最早的狀態就行了。重點是,如果你一開始沒有先留意它的狀態,你就不知道該如何回復,這就可能要被主人白眼了!當然,好朋友可能不會在乎這種小事情,可是在程式運作上,卻會出現大災難喔!
除非你是很古老的程式人,否則你應該沒有機會在單人單工的環境下寫程式(Embedded System除外)。現代的程式設計幾乎都是在多工的假設下發展的,這意味著,同一時間會有很多程式在運行。當然,在單一CPU的電腦系統,一個時間只能服務一個行程(process/thread),但其他因呼叫IPC服務而處於Waiting/Blocking、或被 preemption 而 Suspend 的行程,仍可視為同時執行的個體,在這種情況下,你如果沒有適當地回復(周邊設備)先前的狀態,那麼另一個被停格(被點穴不能動)但回復運作(解穴)的程式就倒楣了!你能想像你放下馬桶座,一屁股坐下去,馬桶座竟然是翻起來的狀況嗎?你的反應會是........好涼喔~~~嗎?
周邊設備在使用前必須先設定參數,以RS232為例,你必須設定 Baud/Data/Stop/Parity等,一旦設定後,這些數值會儲存在周邊的控制暫存器裡,前述的 get 就是先取得目前暫存器的內容,再用 get 來設定你所需的,最後再用一次 get 來寫回原來的內容。
Good Luck.
2011年9月8日
感興趣的開源碼軟體
http://civicrm.org/
http://clip-bucket.com/
http://code.google.com/p/crawlzilla/
http://zh.wikipedia.org/wiki/Inkscape
2011年9月1日
2011年8月23日
2011年8月7日
fall detection - cmopile error pfnBkCheck
env:visual c++ 6.0 enterprice ver.
workspace:fall _detection雙手版雙手有G結構鏈結串列
compile error msg:
LNK2001 : unresolved external symbol ___pfnBkCheck
solve:
project -> settings -> Microsoft foundation classes -> select "Use MFC in a shared DLL"
the fall_detection.csv with detected data will be saved to c:\
(one zigbee receiver on notebook , three Arduino boards with a gyroscope and two accelerometer)
date:2011/08/08
2011年3月12日
GSL(GNU Scientific Library) in Visual studio 2008
1.安裝好visual studio 2008
2.下載好GSL安裝檔(gsl-1.8-src.exe),並安裝
http://gnuwin32.sourceforge.net/downlinks/gsl-src.php
3.C:\Program Files\GnuWin32\src\gsl\1.8\gsl-1.8\VC8底下,執行專案:libgsl.sln
4.libgsl要建置四次(右鍵-->建置),分別為Debug-DLL,Debug-StaticLib,Release-DLL,Release-StaticLib模式下(選擇上方工具列的下拉式選單即可)
5.install_libgsl專案右鍵-->建置,C槽底下就會出現編譯好的檔案,但lib bin是空的
6.修改install_libgsl右鍵中的屬性-->組態屬性-->建置事件-->建置前事件-->命令列,內容為
mkdir %LIBGSL_INSTALL_DIR%\bin
if exist .\..\libgsl\Debug-DLL\libgsl_d.dll copy .\..\libgsl\Debug-DLL\libgsl_d.dll %LIBGSL_INSTALL_DIR%\bin
if exist .\..\libgsl\Release-DLL\libgsl.dll copy .\..\libgsl\Release-DLL\libgsl.dll %LIBGSL_INSTALL_DIR%\bin
if exist .\..\libgslcblas\Debug-DLL\libgslcblas_d.dll copy .\..\libgslcblas\Debug-DLL\libgslcblas_d.dll %LIBGSL_INSTALL_DIR%\bin
if exist .\..\libgslcblas\Release-DLL\libgslcblas.dll copy .\..\libgslcblas\Release-DLL\libgslcblas.dll %LIBGSL_INSTALL_DIR%\bin
mkdir %LIBGSL_INSTALL_DIR%\lib
if exist .\..\libgsl\Debug-StaticLib\libgsl_d.lib copy .\..\libgsl\Debug-StaticLib\libgsl_d.lib %LIBGSL_INSTALL_DIR%\lib
if exist .\..\libgsl\Release-StaticLib\libgsl.lib copy .\..\libgsl\Release-StaticLib\libgsl.lib %LIBGSL_INSTALL_DIR%\lib
if exist .\..\libgslcblas\Debug-StaticLib\libgslcblas_d.lib copy .\..\libgslcblas\Debug-StaticLib\libgslcblas_d.lib %LIBGSL_INSTALL_DIR%\lib
if exist .\..\libgslcblas\Release-StaticLib\libgslcblas.lib copy .\..\libgslcblas\Release-StaticLib\libgslcblas.lib %LIBGSL_INSTALL_DIR%\lib
if exist .\..\libgsl\Debug-DLL\libgsl_dll_d.lib copy .\..\libgsl\Debug-DLL\libgsl_dll_d.lib %LIBGSL_INSTALL_DIR%\lib
if exist .\..\libgsl\Release-DLL\libgsl_dll.lib copy .\..\libgsl\Release-DLL\libgsl_dll.lib %LIBGSL_INSTALL_DIR%\lib
if exist .\..\libgslcblas\Debug-DLL\libgslcblas_dll_d.lib copy .\..\libgslcblas\Debug-DLL\libgslcblas_dll_d.lib %LIBGSL_INSTALL_DIR%\lib
if exist .\..\libgslcblas\Release-DLL\libgslcblas_dll.lib copy .\..\libgslcblas\Release-DLL\libgslcblas_dll.lib %LIBGSL_INSTALL_DIR%\lib
7.install_libgsl專案右鍵-->建置,C槽底下就會出現編譯好的lib bin
8.vs2008中,開啟專案empty-->工具-->選項-->專案和方案
可執行檔加入:C:\libgsl-1.8\bin
include檔案加入:C:\libgsl-1.8\include
程式庫檔加入:C:\libgsl-1.8\lib
9.專案右鍵-->屬性-->連結器-->輸入-->其他相依性加入:libgsl_d.lib libgslcblas_d.lib
10.
範例1:
#include <gsl/gsl_math.h>
#include <iostream>
using namespace std;
int main()
{
double x = 5.0;
double y = gsl_pow_int(x,2);
cout << x << " " << y;
system("pause");
}
程式碼範例2
#include <iostream>
using namespace std;
#include <stdio.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_roots.h>
struct quadratic_params
{
double a, b, c;
};
double quadratic (double x, void *params);
double quadratic_deriv (double x, void *params);
void quadratic_fdf (double x, void *params, double *y, double *dy);
double quadratic (double x, void *params)
{
struct quadratic_params *p = (struct quadratic_params *) params;
double a = p->a;
double b = p->b;
double c = p->c;
return (a * x + b) * x + c;
}
double quadratic_deriv (double x, void *params)
{
struct quadratic_params *p = (struct quadratic_params *) params;
double a = p->a;
double b = p->b;
double c = p->c;
return 2.0 * a * x + b;
}
void quadratic_fdf (double x, void *params, double *y, double *dy)
{
struct quadratic_params *p = (struct quadratic_params *) params;
double a = p->a;
double b = p->b;
double c = p->c;
*y = (a * x + b) * x + c;
*dy = 2.0 * a * x + b;
}
int main (void)
{
struct quadratic_params params = {1.0, 0.0, -5.0};
double r = 0, r_expected = sqrt (5.0);
//////////// ROOT BRACKETING ////////////////////////////
gsl_function F;
F.function = &quadratic;
F.params = ¶ms;
const gsl_root_fsolver_type *T = gsl_root_fsolver_brent;
gsl_root_fsolver *s = gsl_root_fsolver_alloc (T);
double x_lo = 0.0, x_hi = 5.0;
gsl_root_fsolver_set (s, &F, x_lo, x_hi);
printf ("using %s method\n", gsl_root_fsolver_name (s));
printf ("%5s [%9s, %9s] %9s %10s %9s\n",
"iter", "lower", "upper", "root",
"err", "err(est)");
int status;
int iter = 0, max_iter = 100;
do {
iter++;
status = gsl_root_fsolver_iterate (s);
r = gsl_root_fsolver_root (s);
x_lo = gsl_root_fsolver_x_lower (s);
x_hi = gsl_root_fsolver_x_upper (s);
status = gsl_root_test_interval (x_lo, x_hi,
0, 0.001);
if (status == GSL_SUCCESS)
printf ("Converged:\n");
printf ("%5d [%.7f, %.7f] %.7f %+.7f %.7f\n",
iter, x_lo, x_hi,
r, r - r_expected,
x_hi - x_lo);
} while (status == GSL_CONTINUE && iter < max_iter);
gsl_root_fsolver_free (s);
//////////// ROOT POLISHING ////////////////////////////
gsl_function_fdf Fdf;
Fdf.f = &quadratic;
Fdf.df = &quadratic_deriv;
Fdf.fdf = &quadratic_fdf;
Fdf.params = ¶ms;
const gsl_root_fdfsolver_type *Tdf = gsl_root_fdfsolver_steffenson;
gsl_root_fdfsolver *sdf = gsl_root_fdfsolver_alloc (Tdf);
gsl_root_fdfsolver_set (sdf, &Fdf, 1.0);
printf ("using %s method\n", gsl_root_fdfsolver_name (sdf));
printf ("%5s %9s %10s\n",
"iter", "root", "err");
iter = 0;
do {
iter++;
status = gsl_root_fdfsolver_iterate (sdf);
r = gsl_root_fdfsolver_root (sdf);
status = gsl_root_test_residual (quadratic (r,¶ms), 0.001);
if (status == GSL_SUCCESS)
printf ("Converged:\n");
printf ("%5d %.7f %+.7f\n",
iter, r, r - r_expected);
} while (status == GSL_CONTINUE && iter < max_iter);
system("pause");
gsl_root_fdfsolver_free (sdf);
return status;
}
2.下載好GSL安裝檔(gsl-1.8-src.exe),並安裝
http://gnuwin32.sourceforge.net/downlinks/gsl-src.php
3.C:\Program Files\GnuWin32\src\gsl\1.8\gsl-1.8\VC8底下,執行專案:libgsl.sln
4.libgsl要建置四次(右鍵-->建置),分別為Debug-DLL,Debug-StaticLib,Release-DLL,Release-StaticLib模式下(選擇上方工具列的下拉式選單即可)
5.install_libgsl專案右鍵-->建置,C槽底下就會出現編譯好的檔案,但lib bin是空的
6.修改install_libgsl右鍵中的屬性-->組態屬性-->建置事件-->建置前事件-->命令列,內容為
mkdir %LIBGSL_INSTALL_DIR%\bin
if exist .\..\libgsl\Debug-DLL\libgsl_d.dll copy .\..\libgsl\Debug-DLL\libgsl_d.dll %LIBGSL_INSTALL_DIR%\bin
if exist .\..\libgsl\Release-DLL\libgsl.dll copy .\..\libgsl\Release-DLL\libgsl.dll %LIBGSL_INSTALL_DIR%\bin
if exist .\..\libgslcblas\Debug-DLL\libgslcblas_d.dll copy .\..\libgslcblas\Debug-DLL\libgslcblas_d.dll %LIBGSL_INSTALL_DIR%\bin
if exist .\..\libgslcblas\Release-DLL\libgslcblas.dll copy .\..\libgslcblas\Release-DLL\libgslcblas.dll %LIBGSL_INSTALL_DIR%\bin
mkdir %LIBGSL_INSTALL_DIR%\lib
if exist .\..\libgsl\Debug-StaticLib\libgsl_d.lib copy .\..\libgsl\Debug-StaticLib\libgsl_d.lib %LIBGSL_INSTALL_DIR%\lib
if exist .\..\libgsl\Release-StaticLib\libgsl.lib copy .\..\libgsl\Release-StaticLib\libgsl.lib %LIBGSL_INSTALL_DIR%\lib
if exist .\..\libgslcblas\Debug-StaticLib\libgslcblas_d.lib copy .\..\libgslcblas\Debug-StaticLib\libgslcblas_d.lib %LIBGSL_INSTALL_DIR%\lib
if exist .\..\libgslcblas\Release-StaticLib\libgslcblas.lib copy .\..\libgslcblas\Release-StaticLib\libgslcblas.lib %LIBGSL_INSTALL_DIR%\lib
if exist .\..\libgsl\Debug-DLL\libgsl_dll_d.lib copy .\..\libgsl\Debug-DLL\libgsl_dll_d.lib %LIBGSL_INSTALL_DIR%\lib
if exist .\..\libgsl\Release-DLL\libgsl_dll.lib copy .\..\libgsl\Release-DLL\libgsl_dll.lib %LIBGSL_INSTALL_DIR%\lib
if exist .\..\libgslcblas\Debug-DLL\libgslcblas_dll_d.lib copy .\..\libgslcblas\Debug-DLL\libgslcblas_dll_d.lib %LIBGSL_INSTALL_DIR%\lib
if exist .\..\libgslcblas\Release-DLL\libgslcblas_dll.lib copy .\..\libgslcblas\Release-DLL\libgslcblas_dll.lib %LIBGSL_INSTALL_DIR%\lib
7.install_libgsl專案右鍵-->建置,C槽底下就會出現編譯好的lib bin
8.vs2008中,開啟專案empty-->工具-->選項-->專案和方案
可執行檔加入:C:\libgsl-1.8\bin
include檔案加入:C:\libgsl-1.8\include
程式庫檔加入:C:\libgsl-1.8\lib
9.專案右鍵-->屬性-->連結器-->輸入-->其他相依性加入:libgsl_d.lib libgslcblas_d.lib
10.
範例1:
#include <gsl/gsl_math.h>
#include <iostream>
using namespace std;
int main()
{
double x = 5.0;
double y = gsl_pow_int(x,2);
cout << x << " " << y;
system("pause");
}
程式碼範例2
#include <iostream>
using namespace std;
#include <stdio.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_roots.h>
struct quadratic_params
{
double a, b, c;
};
double quadratic (double x, void *params);
double quadratic_deriv (double x, void *params);
void quadratic_fdf (double x, void *params, double *y, double *dy);
double quadratic (double x, void *params)
{
struct quadratic_params *p = (struct quadratic_params *) params;
double a = p->a;
double b = p->b;
double c = p->c;
return (a * x + b) * x + c;
}
double quadratic_deriv (double x, void *params)
{
struct quadratic_params *p = (struct quadratic_params *) params;
double a = p->a;
double b = p->b;
double c = p->c;
return 2.0 * a * x + b;
}
void quadratic_fdf (double x, void *params, double *y, double *dy)
{
struct quadratic_params *p = (struct quadratic_params *) params;
double a = p->a;
double b = p->b;
double c = p->c;
*y = (a * x + b) * x + c;
*dy = 2.0 * a * x + b;
}
int main (void)
{
struct quadratic_params params = {1.0, 0.0, -5.0};
double r = 0, r_expected = sqrt (5.0);
//////////// ROOT BRACKETING ////////////////////////////
gsl_function F;
F.function = &quadratic;
F.params = ¶ms;
const gsl_root_fsolver_type *T = gsl_root_fsolver_brent;
gsl_root_fsolver *s = gsl_root_fsolver_alloc (T);
double x_lo = 0.0, x_hi = 5.0;
gsl_root_fsolver_set (s, &F, x_lo, x_hi);
printf ("using %s method\n", gsl_root_fsolver_name (s));
printf ("%5s [%9s, %9s] %9s %10s %9s\n",
"iter", "lower", "upper", "root",
"err", "err(est)");
int status;
int iter = 0, max_iter = 100;
do {
iter++;
status = gsl_root_fsolver_iterate (s);
r = gsl_root_fsolver_root (s);
x_lo = gsl_root_fsolver_x_lower (s);
x_hi = gsl_root_fsolver_x_upper (s);
status = gsl_root_test_interval (x_lo, x_hi,
0, 0.001);
if (status == GSL_SUCCESS)
printf ("Converged:\n");
printf ("%5d [%.7f, %.7f] %.7f %+.7f %.7f\n",
iter, x_lo, x_hi,
r, r - r_expected,
x_hi - x_lo);
} while (status == GSL_CONTINUE && iter < max_iter);
gsl_root_fsolver_free (s);
//////////// ROOT POLISHING ////////////////////////////
gsl_function_fdf Fdf;
Fdf.f = &quadratic;
Fdf.df = &quadratic_deriv;
Fdf.fdf = &quadratic_fdf;
Fdf.params = ¶ms;
const gsl_root_fdfsolver_type *Tdf = gsl_root_fdfsolver_steffenson;
gsl_root_fdfsolver *sdf = gsl_root_fdfsolver_alloc (Tdf);
gsl_root_fdfsolver_set (sdf, &Fdf, 1.0);
printf ("using %s method\n", gsl_root_fdfsolver_name (sdf));
printf ("%5s %9s %10s\n",
"iter", "root", "err");
iter = 0;
do {
iter++;
status = gsl_root_fdfsolver_iterate (sdf);
r = gsl_root_fdfsolver_root (sdf);
status = gsl_root_test_residual (quadratic (r,¶ms), 0.001);
if (status == GSL_SUCCESS)
printf ("Converged:\n");
printf ("%5d %.7f %+.7f\n",
iter, r, r - r_expected);
} while (status == GSL_CONTINUE && iter < max_iter);
system("pause");
gsl_root_fdfsolver_free (sdf);
return status;
}
訂閱:
文章 (Atom)
NO-CARRIER 網卡無法啟動
工作時,由於想要啟動linux OS的網卡, 發現某張新設定的網卡一直無法啟動,就算下指令UP了,但是也沒有順利啟動 所以爬文後,想要確認該網卡的status, 發現某行為: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu...