|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
有没有人编过增量谐波平衡法的Mathematica程序?我最近在编程序,一直都不行,想请教一下
下面是我编的Van der pol方程程序,但是好像不收敛,不知道是程序有问题还是初值选取不好- Unprotect["`*"];
- ClearAll["`*"];
- (*输入初始数据*)
- nc = 1; ns = 1; n = nc + ns;
- omega0 = 0.94;
- epsilon = 1.0;
- (*输入初始矩阵*)
- cba = epsilon; (*输入C拔矩阵*)
- kba = 1; (*输入K拔矩阵*)
- a = Array[a0, n]; (*输入A的初始矩阵*)
- a[[nc + 1]] = 2;
- Do[a[[i]] = 0.241, {i, 1, nc}];
- Do[a[[i]] = 0.126, {i, nc + 2, n}];
- (*主程序*)
- s = Array[cs0, {1, n}];
- Do[cs0[1, i] = Cos[i*t], {i, nc}];
- Do[cs0[1, i] = Sin[(i - nc)*t], {i, nc + 1, n}];
- s1 = Dt[s, t];
- s2 = Dt[s1, t];
- st = Transpose[s];
- m0 = st.s2;
- m = Integrate[m0, {t, 0, 2*Pi}];
- c0 = cba st.s1;
- c = Integrate[c0, {t, 0, 2*Pi}];
- k0 = kba st.s;
- k = Integrate[k0, {t, 0, 2*Pi}];
- r = Array[r0, {n, 1}];
- Do[r0[i, 1] = 1, {i, n}];
- maxr = 1;
- nn = 1;
- x = s.a;
- c3ba = epsilon x^2;
- x1 = Dt[x, t];
- k2ba = epsilon x x1;
- c30 = c3ba[[1]] st.s1;
- k20 = k2ba[[1]] st.s;
- c3 = Integrate[c30, {t, 0, 2*Pi}];
- k2 = Integrate[k20, {t, 0, 2*Pi}];
- kmc = omega0^2 m + omega0 (c3 - c) + k + 2 omega0 k2;
- rmc = -(2 omega0 m + c3 - c).a;
- r = -(omega0^2 m + omega0 (c3 - c) + k + k2).a;
- While[maxr > 0.00001,
-
- (*将kmc中第一列元素换为rmc*)
-
-
- Do[kmc[[i, nc + 1]] = -rmc[[i]], {i, 1, n}];
-
-
-
- (*定义方程*)
- (*left=kmc.da;
- right=r-domega*rmc;*)
-
-
- (*If[Det[kmc]<0.1*10^(-10),
- omega0=omega0+domega(*如果omega0增大不行,改成减小*);Continue[]];*)
- da = LinearSolve[kmc, r, ZeroTest -> (PossibleZeroQ[Simplify[#]] &)];
- (*Print["a0[1,1]="]
- a0[1,1]
- a0[1,1]+da[[1,1]]
- omega0
- omega0+domega*)
- omega0 = omega0 + da[[nc + 1]];
- Do[a[[i]] = a[[i]] + da[[i]], {i, 1, nc}];
- Do[a[[i]] = a[[i]] + da[[i]], {i, nc + 2, n}];
- (*omega0=omega0+domega;*)
- (*a0[1,1]
- omega0*)
- x = s.a;
- c3ba = epsilon x^2;
- x1 = Dt[x, t];
- k2ba = epsilon x x1;
- c30 = c3ba[[1]] st.s1;
- k20 = k2ba[[1]] st.s;
- c3 = Integrate[c30, {t, 0, 2*Pi}];
- k2 = Integrate[k20, {t, 0, 2*Pi}];
- kmc = omega0^2 m + omega0 (c3 - c) + k + 2 omega0 k2;
- rmc = -(2 omega0 m + c3 - c).a;
- r = -(omega0^2 m + omega0 (c3 - c) + k + k2).a;
- maxr = Max[Abs[Take[r, n]]];
- nn = nn + 1;
- If[nn > 10, Print["求解失败"]; Break[]];
- ]
- Print["x=" MatrixForm[s.a]];
- Print["Maxr="];
- maxr
- Print["Det[kmc]="];
- Det[kmc]
- Print["da"];
- da
复制代码 |
|