Stats

Popular Posts

Followers

顯示包含「Mathematica 教學 微積分」標籤的文章。顯示所有文章
顯示包含「Mathematica 教學 微積分」標籤的文章。顯示所有文章

Mathematica 教學: Prove that 3/8< (1-cos(x)/cos(x/2))/x^2< 4/Pi^2 for all 0< x < Pi/2

由 戴忠淵 於 2017年9月19日星期二 下午8:52 發表



KKTMinimize[obj_,eqns_,ineqns_,variables_]:=
Block[{myrule,lambda,u,\[Lambda],Lagrange,eqnu,ineqnlam,
eqnus,ineqnlams,kkteqns,kktvars,kktans},
myrule={z_[i_]:>ToExpression[ToString[z]<>ToString[i]]};
eqnu=u[#]&/@Range[Length@eqns];
ineqnlam=\[Lambda][#]&/@Range[Length@ineqns];
eqnus=If[Length@eqns>=1,eqns.eqnu,0];
ineqnlams=If[Length@ineqns>=1,ineqns.ineqnlam,0];
kktvars=Flatten@{variables,eqnu,ineqnlam}/.myrule;
Lagrange=obj-eqnus-ineqnlams;
kkteqns=Flatten@{Thread[D[Lagrange,{variables}]==0],
Thread[eqns==0],Thread[ineqns<=0],
Thread[ineqns*ineqnlam==0],Thread[ineqnlam<=0]}/.
myrule;
If[MemberQ[PolynomialQ[#,kktvars]&/@kkteqns[[All,1]],False],
Print["KKT限制式均需為多項式。"],
kktans=Reduce[kkteqns,kktvars,
Backsubstitution->True]/.{And->List,Or->List,
Equal->Rule};
If[Length@Dimensions@kktans==1,{obj/.kktans,
kktans},{obj/.#,#}&/@kktans]]];

Plot[(1-Cos[x]/Cos[x/2])/x^2,{x,0.-10,Pi/2},
PlotRange->{{0,Pi/2},{0.3,0.5}},Frame->True,
FrameTicks->{{{0.3,0.5,{3/8,"3/8"},{4/Pi^2,"4/Pi^2"}},
None},{{0,Pi/2},None}},
GridLines->{None,{3/8,4/Pi^2}},GridLinesStyle->Dashed]

D[(1-Cos[x]/Cos[x/2])/x^2,x]//Simplify

D[(1-(Cos[x/2]^2-Sin[x/2]^2)/Cos[x/2])/x^2,x]//Simplify

D[4-4Sec[x/2]+3xTan[x/2]-4Tan[x/2]^2+xTan[x/2]^3,x]//TrigExpand//Simplify

(D[(6x-2Sin[x/2]-4Sin[x]-2Sin[(3x)/2]+Sin[2x]),x]//TrigExpand)
/.{Sin[z_]:>a,Cos[z_]:>b}

KKTMinimize[6+4a^2+2a^4-b+9a^2b-4b^2-12a^2b^2-3b^3+2b^4,{},
{-a,-b,a-1/Sqrt[2],1/Sqrt[2]-b,b-1},{a,b}]

Limit[(1-(Cos[x/2]^2-Sin[x/2]^2)/Cos[x/2])/x^2,x->0]

Limit[(1-(Cos[x/2]^2-Sin[x/2]^2)/Cos[x/2])/x^2,x->Pi/2]

Let f(x)=(1-cos(x)/cos(x/2))/x^2. Taking the first derivative of f(x) with respect to x yields d/dx f(x)=cos(x/2)*g(x)/(2x^3),
where g(x)=x*tan^3(x/2)-4*tan^2(x/2)+3*x*tan(x/2)-4*sec(x/2)+4. Because g'(x)=1/4*sec(x/2)^2*h(x) and h'(x)=k(x)=2*sin^4(x/2)+4*sin^2(x/2)+2*cos^4(x/2)-3*cos^3(x/2)-4*cos^2(x/2)-cos(x/2)-12*sin^2(x/2) *cos^2(x/2)+9*sin^2(x/2) cos(x/2)+6. Let a=sin(x/2) and b=cos(x/2). By Karush-Kuhn-Tucker conditions, we know that k(x) reaches its minimum at a=0 and b=1. This, together with the facts that h(0)=0, g(0)=0, and f(0)=0, indicates that f(x) is increasing in x, which also implies that 3/8<(1-Cos[x]/Cos[x/2])/x^2<4 br="" completes="" proof.="" the="" this="">
繼續閱讀全文 Mathematica 教學: Prove that 3/8< (1-cos(x)/cos(x/2))/x^2< 4/Pi^2 for all 0< x < Pi/2

Mathematica 教學: Prove that 1 - 3 s^2 + (1 + s^2) Cosh[s] >0.

由 戴忠淵 於 2017年9月18日星期一 下午11:55 發表



Plot[1-3s^2+(1+s^2)Cosh[s],{s,0,Pi},Frame->True]
SeriesCoefficient[1-3s^2+(1+s^2)Cosh[s],{s,0,n}]
Normal[Series[1-3s^2+(1+s^2)Cosh[s],{s,0,5}]]
Minimize[2-(3s^2)/2+(13s^4)/24,s]
Solve[D[2-(3s^2)/2+(13s^4)/24,s]==0,s]

Since the coefficient in the n-th order of the taylor series of 1-3s^2+(1 + s^2)Cosh[s] is positive for every even term and is
zero for every odd term for all n>=3, it is obvious to see that 1-3s^2+(1+s^2)Cosh[s]>2-(3s^2)/2+(13s^4)/24>25/26, which implies that 1-3s^2+(1+s^2)Cosh[s]>0. This completes the proof.
繼續閱讀全文 Mathematica 教學: Prove that 1 - 3 s^2 + (1 + s^2) Cosh[s] >0.

Mathematica 教學:非線性規劃

由 戴忠淵 於 2016年2月11日星期四 下午9:23 發表

繼續閱讀全文 Mathematica 教學:非線性規劃

Mathematica 教學:Interpolation 的函數要如何輸出

由 戴忠淵 於 2015年1月6日星期二 上午11:02 發表




(* test data*)
plot1=Plot[PDF[LogNormalDistribution[0,1],x],{x,0,5}]
mypts=plot1[[1,1,-1,2,1]];
ListLinePlot[mypts]

(* models and parameters *)
myrule=b[coef_]:>ToExpression["b"<>ToString[coef]];
mymodel=Accumulate[b[#]*x^#&/@Range[0,10,1]/.myrule][[2;;-1]]
myvar=b[#]&/@Range[0,10]/.myrule

(* fitting models *)
myfit=FindFit[mypts,mymodel[[#]],myvar[[1;;#+1]],x]&/@
Range[Length@mymodel]

(* plot data and model *)
Plot[mymodel[[#]]/.myfit[[#]],{x,0,5},Epilog->Point[mypts],
PlotRange->{{0,5},{0,0.8}}]&/@Range[Length@mymodel]
繼續閱讀全文 Mathematica 教學:Interpolation 的函數要如何輸出

Mathematica 教學:級數係數

由 戴忠淵 於 2014年8月12日星期二 下午2:29 發表





Unprotect[Power];0^0:=1;Protect[Power];
f=(p0*z)^k(1-p0*z)(1-p0*z-q0*z*(1-(p0*z)^k))^(-1);
D[f,{z,1}]/.k->1/.z->0
D[f,{z,2}]/2/.k->1/.z->0//Simplify
D[f,{z,3}]/6/.k->1/.z->0//Simplify
D[f,{z,4}]/24/.k->1/.z->0//Simplify
test1=Table[(D[f,{z,n}]/n!/.k->1/.z->0),{n,1,10}]//Simplify
SeriesCoefficient[f/.k->1,{z,0,n}]
test2=SeriesCoefficient[f/.k->1,{z,0,#}]&/@Range[10]//Simplify
test1===test2

mytable[{kl_,ku_},{nl_,nu_}]:=
TableForm[Table[SeriesCoefficient[f/.k->kk,{z,0,nn}],
{kk,kl,ku},{nn,nl,nu}],
TableHeadings->{Range[kl,ku],"第"<>ToString[#]<>"項"&/@Range[nl,nu]}]

mytable[{11,20},{8,15}]
繼續閱讀全文 Mathematica 教學:級數係數

Mathematica 教學 微積分的運用

由 戴忠淵 於 2013年11月30日星期六 下午9:20 發表




Mathematica在最佳化理論上的應用





















































繼續閱讀全文 Mathematica 教學 微積分的運用