전산물리학:선형_회귀_분석_linear_regression_analysis

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
전산물리학:선형_회귀_분석_linear_regression_analysis [2022/01/16 18:08] jonghoon전산물리학:선형_회귀_분석_linear_regression_analysis [2023/09/05 15:46] (current) – external edit 127.0.0.1
Line 14: Line 14:
  
 scipy를 쓸 때는 표준오차가 포함되어 있는 경우에는 absolute_sigma 옵션을 True로 줘야 한다. scipy를 쓸 때는 표준오차가 포함되어 있는 경우에는 absolute_sigma 옵션을 True로 줘야 한다.
 +====== 실습 =======
 다음의 데이터를 예로 각 언어로 적합(fitting)해보자. 다음의 데이터를 예로 각 언어로 적합(fitting)해보자.
  
Line 39: Line 39:
 | 4.75 | 10.519384785632700 | 0.47616567472190800 | | 4.75 | 10.519384785632700 | 0.47616567472190800 |
  
 +===== Python =====
 먼저 Python 코드는 아래와 같다. 먼저 Python 코드는 아래와 같다.
  
-<Code:Python>+<code:Python | curve_fit.py>
 import numpy as np import numpy as np
 from scipy.optimize import curve_fit from scipy.optimize import curve_fit
Line 64: Line 65:
  
 print("y = {0}x + {1}".format(popt[0],popt[1]) print("y = {0}x + {1}".format(popt[0],popt[1])
-</Code>+</code>
  
 +===== C++ =====
 다음은 C++에서 gsl을 이용한 코드이다. 다음은 C++에서 gsl을 이용한 코드이다.
-<Code:C++>+<code:C++ | curve_fit.cpp>
 #include <iostream> #include <iostream>
 #include <gsl/gsl_fit.h> #include <gsl/gsl_fit.h>
Line 146: Line 148:
     cout << "y = " << a << "x + "<< b << "\n";     cout << "y = " << a << "x + "<< b << "\n";
 } }
-</Code>+</code>
  
 +===== 결과 =====
 각각의 결과는 다음과 같다 각각의 결과는 다음과 같다
 $$\text{Python:}\quad y = 2.09749(\pm 0.0771828)x + 0.838641(\pm 0.213449)$$ $$\text{Python:}\quad y = 2.09749(\pm 0.0771828)x + 0.838641(\pm 0.213449)$$
-$$\text{C++:}\quad y = 2.09356(\pm 0.0771828)x + 0.853546(\pm 0.0.213449)$$ +$$\text{C++:}\quad y = 2.09749(\pm 0.0771828)x + 0.838641(\pm 0.0.213449)$$ 
-유효숫자는 c++의 기본 자릿수인 6자리에 맞췄다.+유효숫자는 c++ cout의 기본 자릿수인 6자리에 맞췄다.
  • 전산물리학/선형_회귀_분석_linear_regression_analysis.1642324117.txt.gz
  • Last modified: 2023/09/05 15:46
  • (external edit)