tag 标签: include经管大学堂:名校名师名课

相关帖子

版块 作者 回复/查看 最后发表
如何应用“#include”呢 Gauss专版 hshore 2009-8-2 14 5576 Maple24246 2019-1-8 20:54:09
悬赏 400币求 Expanding the criterion domain to include elements of contextual - [!reward_solved!] attachment 求助成功区 zhaiqinghua 2013-2-14 9 3549 小喵2016 2016-11-25 11:07:14
悬赏 求助外文文献一篇!Expanding the criterion domain to include elements of 。。。 - [悬赏 10 个论坛币] 文献求助专区 dongfangbaishi 2013-2-25 2 2868 Mengguren15 2016-11-22 20:44:26
curve estimation中,选中与不选中include constant in equation的差别问题 SPSS论坛 mincheng 2010-1-8 2 2680 matlab-007 2016-4-28 18:48:47
标 题: 有道CFA计算题想请教一下版上大牛~ 经管考证 dellazhu 2013-1-27 6 4925 颠倒的世界 2015-4-2 01:05:21
关于include Gauss专版 iooo 2011-2-8 3 3117 jungsee 2015-1-19 20:33:21
Global Finance Magazine Grades the World's Top Central Bankers 2012 attachment 休闲灌水 bot2007 2012-8-26 1 3169 潭生.经济学笔记 2014-12-7 10:33:05
Eviews ADF检验什么时候选择Trend and intercept attach_img EViews专版 追风的猫 2013-9-5 4 10438 wsyuanan 2013-9-5 22:34:08
MACROECONOMICS THEORY SOLUTION attachment 宏观经济学 PaulBond 2013-1-29 2 1755 cunxws 2013-7-29 22:23:00
美国农业部最新发布的农业展望数据 attachment 行业分析报告 qinsong 2011-8-12 31 4661 淡水鱼007 2013-6-7 17:08:55
悬赏 STATA正交化处理以及残差问题 - [悬赏 4 个论坛币] 悬赏大厅 kid381 2013-4-12 1 4166 第七小分队 2013-5-31 16:06:44
悬赏 初学计量,一个实验作业不是很会,希望高手指导下 - [悬赏 50 个论坛币] attachment 计量经济学与统计软件 wangyanse 2013-5-18 1 1323 wangyanse 2013-5-24 22:39:47
求问如何确定滞后阶数 EViews专版 蓉蓉紫萱 2013-3-14 1 2380 ermutuxia 2013-5-17 17:20:40
分享一个下载金融图书的好地方 金融学(理论版) ytcathy 2013-3-26 6 2275 1976594721稳健 2013-3-26 11:24:37
MLC Exam to include a written part from Spring 2014 金融类 schtiven 2013-2-13 1 1437 o0odudu 2013-2-28 13:16:40
Gauss问题:#include Gauss专版 xiangyu71 2007-2-24 5 3870 robinsonyr 2011-10-15 14:38:15
IEEE软件工程与数据挖掘国际研讨会(EI核心检索) 学术资源/课程/会议/讲座 sedm2012 2011-10-3 0 1127 sedm2012 2011-10-3 11:52:26
2008.Schweser.CFA.Level.1.Practice.Exams. include answer attachment CFA、CVA、FRM等金融考证论坛 seraph851205 2009-3-10 2 2038 nkgenghis 2010-2-19 13:58:53

相关日志

分享 C++—for
accumulation 2015-5-2 14:11
#include iostream #include iomanip using namespace std; int main() {long f1,f2; int i; f1=f2=1; for(i=1;i=20;i++) {coutsetw(12)f1setw(12)f2; if(i%2==0) coutendl; f1=f1+f2; f2=f2+f1; } return 0; }
个人分类: 物理学|0 个评论
分享 C++—while
accumulation 2015-5-2 14:08
#include iostream #include iomanip #include cmath using namespace std; int main() {int s=1; double n=1,t=1,pi=0; while((fabs(t)) 1e-7) {pi=pi+t; n=n+2; s=-s; t=s/n; } pi=pi*4; cout"pi="setiosflags(ios::fixed)setprecision(6)piendl; return 0; }
个人分类: 物理学|0 个评论
分享 C++—while
accumulation 2015-5-2 14:05
#include iostream using namespace std; int main() {int i=1,sum=0; do { sum=sum+i; i++; }while (i=100); cout"sum="sumendl; return 0; }
个人分类: 物理学|0 个评论
分享 C++—while
accumulation 2015-5-2 14:03
#include iostream using namespace std; int main() { int i=1,sum=0; while (i=100) {sum=sum+i; i++; } cout"sum="sumendl; return 0; }
个人分类: 物理学|0 个评论
分享 C++—三角形面积
accumulation 2015-5-2 13:56
#include iostream #include cmath #include iomanip using namespace std; int main() { double a,b,c; cout"please enter a,b,c:"; cinabc; if (a+bc b+ca c+ab) { double s,area; s=(a+b+c)/2; area=sqrt(s*(s-a)*(s-b)*(s-c)); coutsetiosflags(ios::fixed)setprecision(4); cout"area="areaendl; } else cout"it is not a trilateral!"endl; return 0; }
个人分类: 物理学|0 个评论
分享 C++—解方程公式
accumulation 2015-5-2 13:54
#include iostream #include cmath using namespace std; int main() {float a,b,c,x1,x2; cinabc; x1=(-b+sqrt(b*b-4*a*c))/(2*a); x2=(-b-sqrt(b*b-4*a*c))/(2*a); cout"x1="x1endl; cout"x2="x2endl; return 0; }
个人分类: 物理学|0 个评论
分享 C++—类与成员函数
accumulation 2015-5-2 13:43
#include iostream using namespace std; class Student { private: int num; int score; public: void setdata() { cinnum; cinscore; } void display() { cout"num="numendl; cout"score="scoreendl; }; }; Student stud1,stud2; int main() { stud1.setdata(); stud2.setdata(); stud1.display(); stud2.display(); return 0; }
个人分类: 物理学|0 个评论
分享 确定初始划界为极小的程序
accumulation 2015-5-2 13:25
#include cmath #include "nr.h" using namespace std; namespace { inline void shft3(DP a, DP b, DP c, const DP d) { a=b; b=c; c=d; } } void NR::mnbrak(DP ax, DP bx, DP cx, DP fa, DP fb, DP fc, DP func(const DP)) { const DP GOLD=1.618034,GLIMIT=100.0,TINY=1.0e-20; DP ulim,u,r,q,fu; fa=func(ax); fb=func(bx); if (fb fa) { SWAP(ax,bx); SWAP(fb,fa); } cx=bx+GOLD*(bx-ax); fc=func(cx); while (fb fc) { r=(bx-ax)*(fb-fc); q=(bx-cx)*(fb-fa); u=bx-((bx-cx)*q-(bx-ax)*r)/ (2.0*SIGN(MAX(fabs(q-r),TINY),q-r)); ulim=bx+GLIMIT*(cx-bx); if ((bx-u)*(u-cx) 0.0) { fu=func(u); if (fu fc) { ax=bx; bx=u; fa=fb; fb=fu; return; } else if (fu fb) { cx=u; fc=fu; return; } u=cx+GOLD*(cx-bx); fu=func(u); } else if ((cx-u)*(u-ulim) 0.0) { fu=func(u); if (fu fc) { shft3(bx,cx,u,cx+GOLD*(cx-bx)); shft3(fb,fc,fu,func(u)); } } else if ((u-ulim)*(ulim-cx) = 0.0) { u=ulim; fu=func(u); } else { u=cx+GOLD*(cx-bx); fu=func(u); } shft3(ax,bx,cx,u); shft3(fa,fb,fc,fu); } } int main() { }
个人分类: 裂变模型|0 个评论
分享 Monte Carlo Simulation——期权定价模型
accumulation 2015-5-1 16:12
#include math.h #include vector #include iostream #include stdlib.h #include time.h using namespace std; double N(const double x) //标准正态分布的累积分布函数 { if (x6.0) { return 1.0; }; //当x大于6时,认为N(x)近似等于1 if (x-6.0) { return 0.0; }; //当x小于-6时,认为N(x)近似等于0 double b1=0.31938153; double b2=-0.356563782; double b3=1.781477937; double b4=-1.821255989; double b5=1.330274429; double p=0.2316419; double c2=0.3989423; double a=fabs(x); double t=1.0/(1.0+a*p); double b=c2*exp((-x)*(x/2.0)); double n=((((b5*t+b4)*t+b3)*t+b2)*t+b1)*t; n=1.0-b*n; //累积分布函数的近似公式 if (x0.0) n=1.0-n; //N(x)=1-N(-x) return n; } double option_price_call_BS(const double S, const double X, const double r, const double sigma, const double time) //BSM期权定价公式定价欧式看涨期权 { double time_sqrt=sqrt(time); double d1=(log(S/X)+r*time)/(sigma*time_sqrt)+0.5*sigma*time_sqrt; double d2=d1-(sigma*time_sqrt); double c=S*N(d1)-X*exp(-r*time)*N(d2); return c; } double option_price_put_BS(const double S, const double X, const double r, const double sigma, const double time) //BSM期权定价公式定价欧式看跌期权 { double time_sqrt=sqrt(time); double d1=(log(S/X)+r*time)/(sigma*time_sqrt)+0.5*sigma*time_sqrt; double d2=d1-(sigma*time_sqrt); double p=X*exp(-r*time)*N(-d2)-S*N(-d1); return p; } double sampleNormal() //生成期望值为0,方差为1的白噪声 { double u=((double) rand()/(RAND_MAX))*2-1; double v=((double) rand()/(RAND_MAX))*2-1; double r=u*u+v*v; if (r==0 || r1) return sampleNormal(); double c=sqrt(-2*log(r)/r); return u*c; } double simulate_random_variable(const double S, const double r, const double sigma, const double time) //计算下一时刻标的资产的价格 { double R=(r-0.5*pow(sigma,2))*time; double SD=sigma*sqrt(time); return S*exp(R+SD*sampleNormal()); //根据股票价格的对数正态分布特性进行计算 } double max(double a,double b) //计算二者最大值的函数 { if (ab) return a; else return b; } void option_price_european_simulated(const double S, const double X, const double r, const double sigma, const double time, const int no_sims, double call_option, double put_option) //欧式看涨期权与欧式看跌期权的蒙特卡洛模拟定价 { double R=(r-0.5*pow(sigma,2))*time; double SD=sigma*sqrt(time); double sum_payoffs1=0.0; double sum_payoffs2=0.0; for(int n=1; n=no_sims; n++) //no_sims为模拟次数 { double S_T=S*exp(R+SD*sampleNormal()); //根据股票价格的对数正态分布特性计算T期股票价格 sum_payoffs1+=max(0.0,S_T-X); //看涨期权的边界条件 sum_payoffs2+=max(X-S_T,0.0); //看跌期权的边界条件 } call_option=exp(-r*time)*(sum_payoffs1/double(no_sims)); //根据期望值并贴现求现值得到看涨期权价格 put_option=exp(-r*time)*(sum_payoffs2/double(no_sims)); //根据期望值并贴现求现值得到看跌期权价格 } int main() { cout"N(1.96)="N(1.96)endl; //计算标准正态分布的累积分布函数 double S=50; //现期股票价格为S=50 double X=50; //执行价格为X=50 double r=0.1; //无风险利率为r=0.1 double sigma=0.4; //年化波动率为40% double time=0.4167; //时间为0.4167年 cout"EUROPEAN CALL: "option_price_call_BS(S,X,r,sigma,time)endl; //BSM期权定价公式计算看涨期权的价格 cout"EUROPEAN PUT: "option_price_put_BS(S,X,r,sigma,time)endl; //BSM期权定价公式计算看跌期权的价格 cout"Next price: "simulate_random_variable(S,r,sigma,time)endl; //计算时刻time时的股票价格 int no_sims=5000000; //模拟次数 double call_option; double put_option; option_price_european_simulated(S,X,r,sigma,time,no_sims,call_option,put_option); cout"Monte Carlo Call: "call_optionendl; //蒙特卡洛方法计算的欧式看涨期权价格 cout"Monte Carlo Put: "put_optionendl; //蒙特卡洛方法计算的欧式看跌期权价格 system("pause"); }
个人分类: 金融工程|0 个评论
分享 蒙特卡洛模拟—期权定价模型
accumulation 2015-4-30 23:51
#include math.h #include vector #include iostream #include stdlib.h #include time.h using namespace std; double sampleNormal() { double u=((double) rand()/(RAND_MAX))*2-1; double v=((double) rand()/(RAND_MAX))*2-1; double r=u*u+v*v; if (r==0 || r1) return sampleNormal(); double c=sqrt(-2*log(r)/r); return u*c; } double simulate_random_variable(const double S, const double r, const double sigma, const double time) { double R=(r-0.5*pow(sigma,2))*time; double SD=sigma*sqrt(time); return S*exp(R+SD*sampleNormal()); } double max(double a,double b) { if (ab) return a; else return b; } void option_price_european_simulated(const double S, const double X, const double r, const double sigma, const double time, const int no_sims, double call_option, double put_option) { double R=(r-0.5*pow(sigma,2))*time; double SD=sigma*sqrt(time); double sum_payoffs1=0.0; double sum_payoffs2=0.0; for(int n=1; n=no_sims; n++) { double S_T=S*exp(R+SD*sampleNormal()); sum_payoffs1+=max(0.0,S_T-X); sum_payoffs2+=max(X-S_T,0.0); } call_option=exp(-r*time)*(sum_payoffs1/double(no_sims)); put_option=exp(-r*time)*(sum_payoffs2/double(no_sims)); } int main() { double seed=(double)time(NULL); double S=50; double X=50; double r=0.1; double sigma=0.4; double time=0.4167; cout"Next price: "simulate_random_variable(S,r,sigma,time)endl; int no_sims=5000000; double call_option; double put_option; option_price_european_simulated(S,X,r,sigma,time,no_sims,call_option,put_option); cout"Monte Carlo Call: "call_optionendl; cout"Monte Carlo Put: "put_optionendl; system("pause"); }
个人分类: 金融工程|0 个评论
分享 Adams求解偏微分方程
accumulation 2015-4-30 22:46
#includeiostream.h #includestdlib.h float f(float x,float y) { return -y+x+1; //y'=f(x,y) } //龙格库塔公式,提供初值用 void rk(float(*f)(float x,float y),float a,float b,float y0,int n,float yy =y; } } void adams(float a,float b,int n,float(*f)(float x,float y),float y0) { int i; float y1,y2,y,yp,yc,yy ,h,x; cout"X"" ""迭代N"" ""y值"endl; cout"x"0"="a" "0" "y0endl; rk(f,a,b,y0,n,yy); y1=yy ; y2=yy ; y=yy ; h=(b-a)/n; for(i=1;i=3;i++) { cout"x"i"="a+i*h" "i" "yy endl; } for(i=3;in;i++) { x=a+i*h; //预报格式========================= yp=y+h*(55*(*f)(x,y)-59*(*f)(x-h,y2)+37*(f)(x-2*h,y1)-9*(*f)(x-3*h,y0))/24; //修正格式========================= yc=y+h*(9*(*f)(x+h,yp)+19*(*f)(x,y)-5*(*f)(x-h,y2)+(*f)(x-2*h,y1))/24; cout"x"i+1"="x+h" "i+1" "ycendl; y0=y1; y1=y2; y2=y; y=yc; } } void main() { float a=0.0,b=2.0,y0=1; //a,b 区间, y0 初值 int n=10; //(a-b)/n 步长 cout"经典adams预报-校正格式求解y'=-y+x+1 x=(0,2) h=0.2"endl; adams(a,b,n,f,y0); system("pause"); }
个人分类: 裂变模型|0 个评论
分享 蒙特卡洛方法计算最值
accumulation 2015-4-30 18:33
#include iostream #include cmath #include ctime #include cstdlib using namespace std; const double b = 0.9; double u = 0; ///.....计算函数的值......//// double Ifunc(double x, double y, double z) { double hsz = 0.0; hsz = 50 - pow(5 * x - 2 * y , 2) - pow(x - 7 * y * y + 2 * z * z , 4); return hsz; } /////..........概率计算.........////// double glfunc(double w1, double w2, double T) { double p; double u = 0; double w3 = - 1.00 * abs(w1 - w2); u = exp(w3 / (b * T)); if (u 1) p = u; else p = 1; return p; } void main() { double x = 0 , y = 0 , z = 0 , x_next = 0 , y_next = 0 , z_next = 0 , hsz = 0 , hsz_next = 0 , hsz_max = 0; double x_max , y_max , z_max; cout "请输入 x y z 值 : " ; cin x y z; cout endl; double T = 20000; hsz_max = Ifunc(x,y,z); do { hsz = Ifunc(x,y,z); cout "hsz = " hsz endl;//计算初始值 srand(static_castunsigned(time(static_casttime_t *(NULL)))); //进行 y = x + z 变换 x_next = x + -x * (rand() % 10000) / 10100.00 ; y_next = y + -y * (rand() % 10000) / 10100.00 ; z_next = z + -z * (rand() % 10000) / 10100.00 ; cout "x_next = " x_next endl; cout "y_next = " y_next endl; cout "z_next = " z_next endl; hsz_next = Ifunc(x_next,y_next,z_next),u = 0.9 * u; cout "hsz_next = " hsz_next endl; //随机选取数r_rand double r_rand = 0.01 * (rand() + 500) / 33000.00; cout "r_rand = " r_rand endl; double p = glfunc(hsz,hsz_next,T); ///概率接受检验 if (r_rand = 1) { x = x_next; y = y_next; z = z_next; hsz = hsz_next; } else { x_next = x; y_next = y; z_next = z; hsz_next = hsz; } if(hsz_next hsz_max) { x_max = x_next; y_max = y_next; z_max = z_next; hsz_max = hsz_next; T = T * b; } cout endl endl; cout "最大值为 :" hsz_max endl; cout "当取得最大值时" endl; cout "x_max = " x_max endl; cout "y_max = " y_max endl; cout "z_max = " z_max endl; cout "***************************" endl; getchar(); }while(T = 0); }
个人分类: 金融工程|0 个评论
分享 BSM期权定价模型—内含差分法
accumulation 2015-4-30 13:31
#include “newlib.h” double option_price_call_european_finite_diff_implicit(const double S, const double X, const double r, const double sigma, const double time, const int no_S_steps, const int no_t_steps) { double sigma_sqr=sigma*sigma; int M; if((no_S_steps % 2)==1) { M=no_S_steps+1; } else { M=no_S_steps; } double delta_S=2.0*S/M; vectordouble S_values(M+1,0.0); for (int m=0; m=M; m++) { S_values =m*delta_S; } int N=no_t_steps; double delta_t=time/N; BandMatrix A(M+1,1,1); A=0.0; A.element(0,0)=1.0; for (int j=1; jM; ++j) { A.element(j,j-1)=0.5*j*delta_t*(r-sigma_sqr*j); A.element(j,j)=1.0+delta_t*(r+sigma_sqr*j*j); A.element(j,j+1)=0.5*j*delta_t*(-r-sigma_sqr*j); } A.element(M,M)=1.0; ColumnVector B(M+1); for (m=0; m=M; ++m) { B.element(m)=max(0.0,S_values -X); } ColumnVector F=A.i()*B; for (int t=N-1; t0; --t) { B=F; F=A.i()*B; } return F.element(M/2); } double option_price_put_european_finite_diff_implicit(const double S, const double X, const double r, const double sigma, const double time, const int no_S_steps, const int no_t_steps) { double sigma_sqr=sigma*sigma; int M; if((no_S_steps % 2)==1) { M=no_S_steps+1; } else { M=no_S_steps; } double delta_S=2.0*S/M; vectordouble S_values(M+1,0.0); for (int m=0; m=M; m++) { S_values =m*delta_S; } int N=no_t_steps; double delta_t=time/N; BandMatrix A(M+1,1,1); A=0.0; A.element(0,0)=1.0; for (int j=1; jM; ++j) { A.element(j,j-1)=0.5*j*delta_t*(r-sigma_sqr*j); A.element(j,j)=1.0+delta_t*(r+sigma_sqr*j*j); A.element(j,j+1)=0.5*j*delta_t*(-r-sigma_sqr*j); } A.element(M,M)=1.0; ColumnVector B(M+1); for (int n=0; n=M; ++n) { B.element(n)=max(0.0,X-S_values ); } ColumnVector F=A.i()*B; for (int t=N-1; t0; --t) { B=F; F=A.i()*B; } return F.element(M/2); }
个人分类: 金融工程|0 个评论
分享 MATLAB—C++混合编程—TRY
accumulation 2015-4-29 23:47
#include iostream.h #include iomanip.h #include stdlib.h #include windows.h #include "engine.h" #include "mat.h" void main() { double* b; double a ={1,4,7,2,5,8,3,6,9}; const char* file="mymat.mat"; mxArray* Ain; mxArray* Aout; mxArray* SV; Engine* ep; MATFile* mat; mat=matOpen(file,"w"); Ain=mxCreateDoubleMatrix(3,3,mxREAL); mxSetClassName(Ain,"z"); memcpy((char*)mxGetPr(Ain),(char*)a,sizeof(a)); matPutVariable(mat,"z",Ain); matClose(mat); mxDestroyArray(Ain); mat=matOpen(file,"r"); Aout=matGetVariable(mat,"z"); if(ep=engOpen(NULL)) try { engPutVariable(ep,"z",Aout); engEvalString(ep,"sv=svd(z);"); SV=engGetVariable(ep,"sv"); b=mxGetPr(SV); cout"A Matrix ""\n"; for (int j=0; j=2; j++) { coutsetw(16)b ; } cout"\n"; engClose(ep); matClose(mat); mxDestroyArray(Aout); mxDestroyArray(SV); } catch(...) { cout"Fail to start! ""\n"; } }
个人分类: 裂变模型|0 个评论
分享 计算金融C++—期权定价
accumulation 2015-4-29 12:17
#include math.h #include vector #include iostream #include stdlib.h #include time.h using namespace std; double N(const double x) { if (x6.0) { return 1.0; }; if (x-6.0) { return 0.0; }; double b1=0.31938153; double b2=-0.356563782; double b3=1.781477937; double b4=-1.821255989; double b5=1.330274429; double p=0.2316419; double c2=0.3989423; double a=fabs(x); double t=1.0/(1.0+a*p); double b=c2*exp((-x)*(x/2.0)); double n=((((b5*t+b4)*t+b3)*t+b2)*t+b1)*t; n=1.0-b*n; if (x0.0) n=1.0-n; return n; }
个人分类: 金融工程|0 个评论
分享 C++:变尺度法DFP求函数的最小值
accumulation 2015-4-24 16:53
#include "iostream.h" #include "math.h" #include "stdlib.h" double fun(double *x); double fcon(double *x); double funs(double *x,double M); void Grad(double (*pf)(double *x,double M),double m,int n,double *point,double *grad); double Search(double (*pf)(double *x,double M),double m,int n,double *start,double *direction); double DFP(double (*pf)(double *x,double M),double m,int n,double *min_point); double DFP(double (*pf)(double *x,double M),double m,int n,double *min_point) { int i,j,k; double e=1E-5,g_norm; double *g0=new double ; double *g1=new double ; double *dg=new double ; double *p=new double ; double t; double *x0=new double ; double *x1=new double ; double *dx=new double ; double **H=new double* ; for(i=0; in; i++) H = new double ; double **tempH=new double* ; for (i=0; in; i++) tempH = new double ; double *gH=new double ; double *Hg=new double ; double num1; double num2; for(i=0;in;i++) for(j=0;jn;j++) { if(i==j) H =1.0; else H =0.0; tempH =0.0; } for(i=0;in;i++) x0 =min_point ; Grad(pf,m,n,x0,g0); g_norm=0.0; for(i=0;in;i++) g_norm=g_norm+g0 *g0 ; g_norm=sqrt(g_norm); if(g_norme) { for(i=0;in;i++) min_point =x0 ; delete g1; delete p; delete x1; delete H ; delete tempH ; delete gH; delete =-g0 ; k=0; do { t=Search(pf,m,n,x0,p); for(i=0;in;i++) x1 =x0 +t*p ; Grad(pf,m,n,x1,g1); g_norm=0.0; for(i=0;in;i++) g_norm=g_norm+g1 *g1 ; g_norm=sqrt(g_norm); for(i=0;in;i++) { dx =x1 -x0 ; dg =g1 -g0 ; } for(i=0;in;i++) { gH =0.0; Hg =0.0; } for(i=0;in;i++) { for(j=0;jn;j++) { gH =gH +dg *H ; Hg =gH ; } } num1=0.0; num2=0.0; for(i=0;in;i++) { num1=num1+dx *dg ; num2=num2+gH *dg ; } for(i=0;in;i++) for(j=0;jn;j++) tempH =0.0; for(i=0;in;i++) { for(j=0;jn;j++) { tempH =tempH +H ; tempH =tempH +dx *dx /num1; tempH =tempH -Hg *gH /num2; } } for(i=0;in;i++) { for(j=0;jn;j++) { H =tempH ; } } for(i=0;in;i++) p =0.0; for(i=0;in;i++) { for(j=0;jn;j++) { p =p -H *g1 ; } } for(i=0;in;i++) { g0 =g1 ; x0 =x1 ; } k=k+1; }while(g_norme); for(i=0;in;i++) min_point =x1 ; delete g1; delete p; delete x1; delete H ; delete tempH ; delete gH; delete ; temp_point=new double ; Grad(pf,m,n,start,grad); diver_a=0; for(i=0;in;i++) diver_a=diver_a+grad *direction ; do { b=a+step; for(i=0;in;i++) temp_point =start +b*direction ; Grad(pf,m,n,temp_point,grad); diver_b=0; for(i=0;in;i++) diver_b=diver_b+grad *direction ; if( fabs(diver_b)1E-10 ) { delete temp_point; return b; } if( diver_b-1E-15 ) { a=b; diver_a=diver_b; step=2*step; } }while(diver_b=1E-15 ); for(i=0;in;i++) temp_point =start +a*direction ; value_a=pf(temp_point,m); for(i=0;in;i++) temp_point =start +b*direction ; value_b=pf(temp_point,m); do { s=3*(value_b-value_a)/(b-a); z=s-diver_a-diver_b; w=sqrt( fabs(z*z-diver_a*diver_b) ); t=a+(w-z-diver_a)*(b-a)/(diver_b-diver_a+2*w); value_b=pf(temp_point,m); for(i=0;in;i++) temp_point =start +t*direction ; value_t=pf(temp_point,m); Grad(pf,m,n,temp_point,grad); diver_t=0; for(i=1;i=n;i++) diver_t=diver_t+grad *direction ; if(diver_t1E-6) { b=t; value_b=value_t; diver_b=diver_t; } else if(diver_t-1E-6) { a=t; value_a=value_t; diver_a=diver_t; } else break; }while( (fabs(diver_t)=1E-6) (fabs(b-a)1E-6) ); delete temp_point; return t; } void Grad(double (*pf)(double *x,double M),double m,int n,double *point,double *grad) { double h=1E-3; int i; double *temp; temp = new double ; for(i=0;in;i++) { temp =point ; } for(i=0;in;i++) { temp +=0.5*h; grad =4*pf(temp,m)/(3*h); temp -=h; grad -=4*pf(temp,m)/(3*h); temp +=(3*h/2); grad -=(pf(temp,m)/(6*h)); temp -=(2*h); grad +=(pf(temp,m)/(6*h)); temp =point ; } delete ; double *x1=new double ; double e=1E-3,t; double M0,c; M0=1; c=2.5; for(i=0;in;i++) x0 =min_point ; k=0; do{ DFP(funs,M0,n,x0); for(i=0;in;i++) x1 =x0 ; t=fabs(fcon(x1)); if(te) { for(i=0;in;i++) min_point =x1 ; delete x1; return pf(min_point); } M0=c*M0; }while(k10); for(i=0;in;i++) min_point =x1 ; delete x1; return pf(min_point); } double fun(double *x) { //return -(0.5428-log(x )-((log(x )-5.9123)*(log(x )-5.9123))/0.0469-((x -127.2)*(x -127.2))/158.5624-0.1068*x -exp(-0.1068*(x -46.1355))); double a1=345,a2=181.52,b1=42.435,b2=10.70968; return log(2.51*b1*x )+0.5*((log(x )-a1)*(log(x )-a1))/(b1*b1)+log(2.51*b2)+0.5*((x -a2)*(x -a2)/(b2*b2)); } double fcon(double *x) { //return x -x -x ; return x -x ; } double funs(double *x,double M) { return fun(x)+M*fcon(x)*fcon(x); } void main() { int n=3; //double min_point ={201.15,201.15}; double mi ={5.836,181.52}; double min_value=Dev(fun,n,min_point); cout"本程序功能:使用变尺度法(DFP)求函数的最小值。"endl; cout"最小值点为:"endl; //cout"("min_point ","min_point ","min_point ")"endl; cout"("min_point ","min_point ")"endl; cout"最小值为:"endl; coutmin_valueendl; system("pause"); }
个人分类: 裂变模型|0 个评论
分享 二叉状态树—概率
accumulation 2015-4-12 19:19
#include iostream.h #include stdlib.h #include iomanip.h void main() { int n; cout"请输入行数"endl; cinn; if (n=0) { cout"输入错误!输入数据必须是大于零的整数"endl; cout'\n'; cout"请重新输入!"endl; } double compute(int x,int y); for (int i=0;i=n;i++) { for (int j=0;j=i-1;j++) { if(j==0) coutsetw((n-i+1)*3)compute(i,j); else coutsetw(3*2)compute(i,j); } coutendl; } system("pause"); } double compute(int x,int y)//x行y列 { if (x==12 y=5) return 1; else if (x==12 y=6) return 0; else return 0.3*compute(x+1,y)+0.7*compute(x+1,y+1); }
个人分类: 金融工程|0 个评论
分享 C++程序—类
accumulation 2015-3-19 23:53
#include iostream using namespace std; class Time { public: int hour; int minute; int sec; }; int main() { void set_time(Time) ; void show_time(Time); Time t1; set_time(t1); show_time(t1); Time t2; set_time(t2); show_time(t2); return 0; } void set_time(Time t) { cint.hour; cint.minute; cint.sec; } void show_time(Time t) { coutt.hour":"t.minute":"t.secendl; }
个人分类: 原子核物理|0 个评论
分享 C++程序—函数与类
accumulation 2015-3-19 23:50
#include iostream using namespace std; int main() { int max(int x,int y); int a,b,c; cinab; c=max(a,b); cout"max="cendl; return 0; } int max(int x,int y) { int z; if(xy) z=x; else z=y; return(z); } #include iostream using namespace std; class Student { private: int num; int score; public: void setdata() { cinnum; cinscore; } void display() { cout"num="numendl; cout"score="scoreendl; }; }; Student stud1,stud2; int main() { stud1.setdata(); stud2.setdata(); stud1.display(); stud2.display(); return 0; }
个人分类: 原子核物理|0 个评论
分享 C++程序—基础
accumulation 2015-3-19 23:46
#include iostream using namespace std; int main() { cout"This is a C++ program."; return 0; } #include iostream using namespace std; int main() { int a,b, sum; cinab; sum=a+b; cout"a+b="sumendl; return 0; } #include iostream using namespace std; int max(int x,int y) { int z; if(xy) z=x; else z=y; return(z); } int main() { int a,b,m; cinab; m=max(a,b); cout"max="mendl; return 0; }
个人分类: 原子核物理|0 个评论

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-26 16:12