SymbolicC++ 는 GiNaC 처럼 심볼 처리 수학식 계산을 지원하지만, 리눅스 계열 뿐만 아니라 윈도우 환경에서도 Visual C++ 나 MinGW 의 g++ 와 함께 사용할 수 있는 수학 심볼 처리 라이브러리이다.
* Wikipedia 에서 설명하는 SymbolicC++
* Visual C++ 를 위한 SymbolicC++ 라이브러리 만들기
Visual Studio 에서 솔루션 파일 SymbolicC++3.sin 을 열고 아래 그림 처럼 메뉴 탭에서 Dynamic 이라고 설정된 곳을 Static 으로 변경하고 빌드한다.
그러면 에러와 경고가 몇 개 쏟아질 것이다.
* 에러 해결하기
SymbolicC++ 를 빌드하는 과정에서 C:\Program Files (x86)\Microsoft Visual Studio 10\VC\include 폴더에 있는 파일 xlocmon 의 410 째 줄에서 에러가 걸린다. 이 줄을
_Str2 += '-', ++_Off; ------> _Str2 += '-'; ++_Off;
처럼 수정(즉 콤마를 세미콜론으로 수정)하여 다시 저장한다.
그러면 에러는 해결되고 경고(warning) 몇 개가 남는다.
* 몇 가지 경고(warning) 해결하기
1) SymbolicC++ 의 소스 파일 중에 integrate.cpp 파일에서 "변수 se 가 선언되었지만 사용되지 않았다"는 경고가 몇 곳 나온다. 이런 경고를 해결하려면, integrate.cpp 파일에서
} catch(const SymbolicError &se) {}
처럼 된 중을 모두 찾아
} catch(const SymbolicError &se) { std::cout << se.message() << std::endl; }
처럼 수정하고, 이 파일의 선두 부분에 include 문
#include <iostream>
을 추가한다..
2) equation.cpp 파일의 95 째 줄
{ return lhs.compare(rhs); }
을
{ return (lhs.compare(rhs) == 0) ? false : true; }
로 수정한다.
3) sum.cpp 파일의 373 째 줄
if(j != matchpart.end()); matchpart.erase(j);
을
(j != matchpart.end()) matchpart.erase(j);
로 수정한다. (세미콜론 하나 제거)
* SymbolicC++ 를 이용하는 간단한 부정적분 예제
/*
SymbolicC++ : An object oriented computer algebra system written in C++
Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb
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.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
// integration.cpp
#include <iostream>
#include "symbolicc++.h"
using namespace std;
int main(void)
{
Symbolic x("x"), c("c"), z("z"), y;
z = z[x];
y = (1-x)*(1-x)+cos(x)+x*exp(x)+c+z;
cout << "y = " << y << endl;
for(int i=0;i<3;i++)
{
y = integrate(y,x);
y = y[integrate(x*exp(x),x) == x*exp(x) - exp(x)];
cout << "y = " << y << endl;
}
return 0;
}
* 위의 예제 소스 컴파일하기 (컴파일 옵션 /MD 가 중요)
프롬프트> cl /EHsc /I SymbolicC++3-3.35-vc\include integration.cpp SymbolicC++3.lib /MD
* 실행하기
프롬프트> integration
y = x^(2)-2*x+cos(x)+x*e^x+c+z[x]+1
y = 1/3*x^(3)-x^(2)+sin(x)+x*e^x-e^x+c*x+int(z[x],x)+x
y = 1/12*x^(4)-1/3*x^(3)-cos(x)+x*e^x-2*e^x+1/2*c*x^(2)+int(z[x],x,x)+1/2*x^(2)
y = 1/60*x^(5)-1/12*x^(4)-sin(x)+x*e^x-3*e^x+1/6*c*x^(3)+int(z[x],x,x,x)+1/6*x^(3)
'프로그래밍 > C++' 카테고리의 다른 글
Qt 5.2.1 의 Qt Creater 3.0.1 을 이용한 Hello 예제 작성하기 (0) | 2014.02.28 |
---|---|
MinGW 의 g++ 와 SymbolicC++ 를 이용한 간단한 인터프리터 (0) | 2014.01.17 |
C++ 언어에서 동작하는 쓰레기 수집기(Garbage collector) (0) | 2013.10.20 |
명령줄 컴파일러로 컴파일하는 간단한 Visual C++ 2010 용 MFC 응용프로그램 예제 (0) | 2013.10.10 |
명령줄 컴파일러로 컴파일하는 간단한 Visual C++ 2010 용 Win32 응용프로그램 예제 (0) | 2013.10.10 |