Skip to main content

Posts

numerical integration - How to use NIntegrate when there are symbolic constant coefficients

I would like to numerically integrate an equation such as the one below in which there are symbolic constant coefficients. I used a very simple code but it doesn't work in general, that tried to deal with constant coefficients with patterns. Is there any general approach to NIntegrate where symbolic constant coefficients exist? 11.94` a[1, 1]^2 Cos[x]^2 Cos[θ]^2 + 21.31` c[1, 1]^2 Cos[x]^2 Cos[θ]^2 + 0.14702` a[1, 1] b[1, 1] Cos[x] Cos[θ]^2 Sin[x] - ( 1.395` b[1, 1]^2 Cos[x] Cos[θ]^2 Sin[x])/(1 + x/2)^3 + 0.4669` b[1, 1]^2 Cos[θ]^2 Sin[x]^2 + ( 1.395` b[1, 1]^2 Cos[θ]^2 Sin[x]^2)/(1 + x/ 2)^4 /. {b[a1_, a2_] b[a3_, a4_] g_ :> b[a1, a2] b[a3, a4] NIntegrate[g, {θ, 0, 2}, {x, 0, 1}], a[a1_, a2_] a[a1_, a2_] g_ :> a[a1, a2] a[a1, a2] NIntegrate[g, {θ, 0, 2}, {x, 0, 1}, Method -> {Automatic, "SymbolicProcessing" -> 0}], a[a1_, a2_] a[a3_, a4_] g_ :> a[a1, a2] a[a3, a4] NIntegrate[g, {θ, 0, 2}, {x, 0, 1}, ...

graphics - Programmatically combine 2D contour plots with 1D projections

I regularly need to plot 2D and 1D data together. I want to be able to show a 2D contour plot with the projections along each of the axes. As it is now, I create the three plots separately and use Inkscape to combine them. The problem with this is twofold. First, it is cumbersome if I have to do it over and over. Second, I have to use my eyes to move the 1D plot so that its features line up properly with the 2D data. As a simple working example, consider this 2D array of data xRange = {8, 19}; yRange = {6, 16}; twoDlist = Table[Abs[ I/(ω1 - 14 + I) I/(ω2 - 11 + I) + ( I/3)/(ω1 - 8 + I/3) I/(ω2 - 16 + I)], {ω1, yRange[[1]], yRange[[2]], .05}, {ω2, xRange[[1]], xRange[[2]], .05}]; From this I generate the 2D and 1D plots. topplot = ListLinePlot[Total[twoDlist], Axes -> False, DataRange -> xRange, PlotStyle -> {{Thick, Red}}, PlotRange -> {Full, All}]; rightplot = ListLinePlot[Total /@ twoDlist, Axes -> False, DataRange -> yRange, PlotStyle ...

Hold[Expression] (or similar) in InputField that truly holds the input unmodified

I am trying to design a user interface where the specific form that the user enters in InputFields are left unchanged. For example, if the user puts in a number in scientific notation, it would be really nice for that value in the field to stay the same, even though it is modified internally into a different form. None of the Hold-type functions seem to do what I want (and only Hold[Expression] seems to be an option in InputField anyway). Any ideas? Answer InputField[Dynamic[var], Boxes] Column[{InputField[Dynamic[var], Boxes], Dynamic[var], Dynamic[RawBoxes @ var], Dynamic[ToExpression @ var] }]

calculus and analysis - What exactly does GenerateConditions do?

Consider for example this strange behavior: Integrate[1/x, {x, 0, Infinity}, GenerateConditions -> False] (*0*) I'd also like to know the difference between GenerateConditions -> Automatic and GenerateConditions -> True . Answer Here is a quick description. GenerateConditions -> False will both skip some code for checking parameter regions of validity for an integral, and also a regularized integral might be computed. This interface should probably be improved but I've no idea if or when that might happen. GenerateConditions -> Automatic behaves like True for single definite integrals. In the multiple case it behaves like False for all inner integrals, and True for the final integration step. The reason is that the ability to spawn conditions is more powerful than the code required to sort through them, so defaulting to True at all levels might keep many inputs from running to completion. There are probably exceptions to this general categorization.

front end - how to get the Messages Tab back in version 11.1 Edit->Preferences?

On windows 7, version 11.1, when doing edit->Preferences, no longer has the very nice messages tab there any more. I searched but so far, not able to find this tab. So can't change where my Print output go to easily as before, and change other similar settings. Is it possible to get this tab back? If not, is there other easy way to make same changes? I really do not want to go through advanced setting and go search option inspector and edit things each time I want to make such changes, since I used to change these settings all the time. Answer I don't know why but: [...] Unfortunately removing the Evaluation and Messages tabs in Mathematica 11.1 Preferences is by design. However those settings can be found in our Option Inspector: [...] Here is an official documentation about that issue: You can use old preferences dialog but I can't guarantee everything will be fine: Module[{relPath, newPath, oldVersion = "11.0"} , relPath = Sequence[ "System...

DSolve leads to an equation that is different from paper solution

I'm following the method in the two images in an attempt to obtain a value for $\beta$ . I know that there's a mistake in (4.36) from here so I used Mathematica's solution to continue the solution. I used the following code: ClearAll[Y, y, \[Mu] , k, a, \[Theta]] sol = DSolve[{Y''[y] - ((\[Mu] k \[Pi])/a)^2 Y[y] == (-8 \[Theta])/( k \[Pi]), Y[-b/2] == 0, Y[b/2] == 0}, Y, y]; Y2[y_] = FullSimplify[ExpToTrig[Y[y] /. sol[[1]]]]; \[Phi][x_, y_] = Y2[y]*Sin[(k \[Pi])/a x]; gj = 2 \!\( \*SubsuperscriptBox[\(\[Integral]\), FractionBox[\(-b\), \(2\)], FractionBox[\(b\), \(2\)]]\(\(( \*SubsuperscriptBox[\(\[Integral]\), \(0\), \(a\)]\[Phi][x, y] \[DifferentialD]x)\) \[DifferentialD]y\)\); a = b; Gx = Gy; \[Mu] = Sqrt[Gx/Gy]; \[Beta] = gj/(Gx a b^3) to get that $$\beta=\frac{32 \theta \sin ^2\left(\frac{\pi k}{2}\right) \left(\pi b k-2 b \tanh \left(\frac{\pi k}{2}\right)\right)}{\pi ^5 b G_y k^5}$$ According to the solution in the images and my understanding,...

plotting - Can Mathematica plot this financial simulation?

I'd like to run a simple financial simulation with something like the following constraints: You start out with $S$ dollars. Let's say $S$ is $\$1M$ dollars You repeatedly make an investment that costs $I$ dollars (let's say $I = \$5K$ ) with an $F$ percent (let's say $F = 0.95$ ) chance of returning $\$0$ and an $(1-F)$ percent chance of returning $\%100,000$ of $I$ (or just $1,000 \cdot I$ ). Is there a way in Mathematica to repeatedly make this investment hundreds of times over time? Could we have Mathematica repeatedly run the simulation and then plot the average of all of its simulation as a line as well? Answer It can certainly be done using NestList : s = 100; i = 0.5; f = 0.95; nStep = 100; sim := NestList[If[RandomReal[] nStep]; Now sim will generate a simulation of such process at each evaluation. You can use the following to do multiple runs and plot: runs = Table[sim, {r, 100}]; ListPlot[runs, Joined -> True, PlotRange -> All] Also plot ...