NIntegrate within NDSolve-optimization?
- To: mathgroup at smc.vnet.net
- Subject: [mg128169] NIntegrate within NDSolve-optimization?
- From: maves <vesel.mateja at gmail.com>
- Date: Thu, 20 Sep 2012 00:25:26 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-newout@smc.vnet.net
- Delivered-to: mathgroup-newsend@smc.vnet.net
Hello, I am trying to numerically solve a set of differential equations, and the problem is that the expression also contains numerical integrals, I believe this is why I am getting large numerical errors. Firstly, I define three integrals (for instance for b=6, c=0.5): int1[x_?NumericQ, z_?NumericQ] := NIntegrate[-(R (x - R Cos[\[Phi]]))/ ((x - R Cos[\[Phi]])^2 + (R Sin[\[Phi]])^2 + (z - Z)^2)^(3/2), {\[Phi], 0, 2 Pi}, {R, b, b + c}, {Z, R - (b + c), -R + (b + c)}]; int2[x_?NumericQ, z_?NumericQ] := NIntegrate[-(R (z-Z))/ ((x - R Cos[\[Phi]])^2 + (R Sin[\[Phi]])^2 + (z - Z)^2)^(3/2), {\[Phi], 0, 2 Pi}, {R, b, b + c}, {Z, R - (b + c), -R + (b + c)}]; int3[x_?NumericQ, z_?NumericQ] := NIntegrate[-R/((x - R Cos[\[Phi]])^2 + (R Sin[\[Phi]])^2 + (z - Z)^2)^(1/2), {\[Phi], 0, 2 Pi}, {R, b, b + c}, {Z, R - (b + c), -R + (b + c)}]; And then I use them in NDSolve: s = NDSolve[{ x''[t] == int1[x[t], z[t]], z''[t] == int2[x[t], z[t]], x[0] == 7.1, x'[0] == 0, z'[0] == 0, z'[0] == 1}, {x, x= ', z, z'}, {t, 0, 5}][[1]] And plot the solution: ParametricPlot[Evaluate[{x[t], z[t]} /. s], {t, 0, 5}, PlotRange -> All] Plot[Evaluate[0.5*((x'[t])^2+(z'[t])^2+int3[x[t],z[t]]) /. s], {t, 0, 5}] I change the initial conditions and try to find something "useful", but this second plot shows me, that something just isn't right, as it should be constant, but it oscillates with a huge amplitude. Could this be due to numerical errors and how you think I should optimize my code to get a good result? Is this combination of NIntegrate and NDSolve even acceptable? Thank you. But the solution just doesn't seem right