Skip to main content

Posts

Showing posts from July, 2017

plotting - Maclaurin series

Can someone tells me, why is that not working? I'm starting to learn Mathematica. I have to solved this eq and draw the graph. It is developing a series of Taylor in about x0 = 0. eq = 60 - 53 x - 13 x^2 + 5 x^3 + x^4 seq = Solve[eq == 0, x] p1 = D[eq, x] s1 = Solve[p1 == 0, x] f1 = seq + s1/1! x^1 z = Solve[f1, x] Plot[z, {x, 0, 2}] This is my equation to solve Answer eq = 60 - 53 x - 13 x^2 + 5 x^3 + x^4; The roots are seq = Solve[eq == 0, x] {{x -> -5}, {x -> -4}, {x -> 1}, {x -> 3}} The first order series expansion about zero is f1 = Series[eq, {x, 0, 1}] // Normal 60 - 53 x z = Solve[f1 == 0, x][[1]] {x -> 60/53} Plotting the polynomial and approximation and highlighting the roots Plot[{eq, f1}, {x, -5.5, 3.5}, Epilog -> {Red, AbsolutePointSize[5], Point[{x, eq} /. seq], Point[{x, f1} /. z]}, PlotRange -> {-50, 100}, PlotLegends -> "Expressions"] Looking closer at the region of interest Plot[{eq, f1}, {x, -0.5, 2}, Epilog -> {Re

graphics - Filling a rectangle with an image

Say I have some rectangles of different sizes drawn on the screen. How can I fill them all with the same image? Ideally, the image would be resized to completely fill each rectangle. I've been trying to do this by wrapping each rectangle in graphics and adding the image wrapped in an inset in the epilog for each one, something like this Example: Show[Graphics[{Rectangle[{0, 0}, {0.5, 0.3}]}, Epilog -> Inset[pic, {0, 0}, {0, 0}]], Graphics[{Rectangle[{0.5, 0.3}, {0.7, 0.4}]}, Epilog -> Inset[pic, {0, 0}, {0, 0}]]] but it's not giving me the result I want. Is there anything like Fill[Rectangle[],pic] that would fill the rectangle with the image pic? I would also be fine with using something other than rectangles. Maybe there's something like a frame I can work with instead and just draw the image into those? Answer Code: (*Sample data*) data = Table[ ColorData["Rainbow", t] /. RGBColor -> List, {t, 0, 1, 1/100}]; (*Visualize*) Graphics[{Textu

meta programming - Macro functions in GeneralUtilities?

Questions have been asked about the Macros package before (e.g., (83815) ), but I'm interested if anyone has some examples of using the macro related functions in GeneralUtilities: In[2397]:= Names["GeneralUtilities`*Macro*"] Out[2397]= {"DefineLiteralMacro", "DefineMacro", "MacroEvaluate", \ "MacroExpand", "MacroExpandList", "MacroPanic", "MacroRules", \ "UseMacros", "$MacroDebugMode"} I find their docstrings a bit cryptic: Answer The only official information about the Macro functions I am aware of can be found in a short segment in this presentation , which describes the "Macro System" as an essential part of the next compiler generation. However, the CreateMExpr shown there isn't included in Mathematica 10.4.1. (But maybe someone can find parts of it digging deeper into it?) Nevertheless, one can already apply the Macro System practically (while being aware tha

plotting - Legend in a Show

I am trying to put some legends on a graph but I am not able to do that. This is my code: k = 1; (* J/K *) T = 1; (* K *) nlm = NonlinearModelFit[data, V, {M, n}, λ]; nlm["BestFitParameters"] Show[ListPlot[data], Plot[Normal[nlm], {λ, 0, 8}, PlotStyle -> Red], Frame -> True, GridLines -> Automatic, GridLinesStyle -> Directive[Gray, Dashed], AspectRatio -> 1.6, ImageSize -> Large, FrameLabel -> {"λ", "σ [MPa]"}, LabelStyle -> {FontFamily -> "Helvetica", 14}] I tried to look on the internet already but I don´t understand how to do it. For example there is this discussion: Dynamic legends involving show In which it looks like the same problem of mine, but I am not able to fully understand it. I am really new with Mathematica , so please consider it. Thanks, Fab. EDIT: After discussing here, this is the new code which works for me. Of course as someone told me, it is not running this piece of code because you need

bugs - Why does x++ behave strangely under Defer?

Bug introduced in 10.4.1 or earlier and persisting through 11.1.0 or later Using x++ or x=x+1 inside Defer generates strange results. Evaluating the following commands one by one (in three different input cells), with Shift + Enter , one gets: x=1; Defer[x++]; x (* 15 but I have also seen 17! *) Even stranger, if one creates a notebook with only those same commands, restarts the kernel, and does Evaluation ► Evaluate Notebook then the command x returns 1 instead of 15 . Any explanations?

differential equations - Mathematica9: NDSolve slows down after repeated calls

Bug introduced in 9.0 and persisting through 11.0.1 I have noted that in Mathematica 9 my code, which involves a lot of calls to NDSolve , slows down considerably after some time. Apparently, the problem is NDSolve itself and it seems to be related to Mathematica 9, as the following example shows: RunNDSolve := Timing[Do[NDSolve[{f''[x] == -f[x], f[0] == 1, f'[0] == 0}, {f[x]}, {x, 0, 1}], {1000}]][[1]] RunNDSolve integrates a simple differential equation 1000 times using NDSolve and returns the time needed to carry out the integrations. In Mathematica 9, RunNDSolve takes longer and longer times as it is called again, as the following example shows: Table[{j, RunNDSolve}, {j, 50}] In Mathematica 9 (extract of the full result): j, RunNDSolve 1, 0.712 10, 2.649000 20, 4.869000 30, 7.326000 50, 13.372000 In Mathematica 8 (extract of the full result): j, RunNDSolve 1, 0.5880000000000001` 10, 0.593` 20, 0.5719999999999992` 30, 0.5670000000000002` 40, 0.57700000000000

functions - What best practices or performance considerations are there for choosing between Cases, Position, Pick and Select?

Cases , Select , Pick and Position each have different syntaxes and purposes, but there are times when you can express the same calculation equivalently using either of them. So with this input: test = RandomInteger[{-25, 25}, {20, 2}] {{-15, 13}, {-8, 16}, {-8, -19}, {7, 6}, {-21, 9}, {-3, -25}, {21, -18}, {4, 4}, {2, -2}, {-24, 8}, {-17, -8}, {4, -18}, {22, -24}, {-4, -3}, {21, 0}, {19, 18}, {-23, -8}, {23, -25}, {14, -2}, {-1, -13}} You can get the following equivalent results: Cases[test, {_, _?Positive}] {{-15, 13}, {-8, 16}, {7, 6}, {-21, 9}, {4, 4}, {-24, 8}, {19, 18}} Select[test, #[[2]] > 0 &] {{-15, 13}, {-8, 16}, {7, 6}, {-21, 9}, {4, 4}, {-24, 8}, {19, 18}} Pick[test, Sign[test[[All, 2]] ], 1] {{-15, 13}, {-8, 16}, {7, 6}, {-21, 9}, {4, 4}, {-24, 8}, {19, 18}} test[[Flatten@Position[test[[All, 2]], _?Positive] ]] {{-15, 13}, {-8, 16}, {7, 6}, {-21, 9}, {4, 4}, {-24, 8}, {19, 18}} Are there performance or other considerations that should guide which you shou

plotting - Plot 3D boolean Array or matrix in Mathematica

I have been attempting several methods to plot a 3D diagram of a n by n boolean array in Mathematica but none of them produced satisfactory result. I want the $3D$ plot to have a cube when M[i,j,k] == 1 and when M[i,j,k] == 0 just leaves as blank. Below is the best result I got. L=10 M = RandomReal[{0, 1}, {L, L, L}]; For[k = 1, k <= L, k++, For[j = 1, j <= L, j++, For[i = 1, i <= L, i++, If[M[[i, j, k]] < 0.5, M[[i, j, k]] = 1, M[[i, j, k]] = 0 ]]]]; Image3D[M, ImageSize -> 500, Boxed -> True] The Image3D function gives a very fluffy and opaque look on the cubes which I couldn't change!! Is there someway I can change the opacity and color of the Image3D function in this case? Or is there a better way to plot this matrix?

performance tuning - How to find all the positions of max value of a list efficiently?

For Example, list=RandomInteger[{1,100},2000] . Yes,I know Position[list,Max[list]] can do. But it's based on pattern matching! Ordering[list,-1] could find one position but not all. So how to find all the positions of max value of list in a more efficient way?Thank you. Answer A fast uncompiled alternative without pattern matching is to use the NonzeroPositions property of SparseArray , as long as you're dealing with numerical data. list = RandomInteger[{1, 100}, 10^7]; SparseArray[Unitize[list - Max[list]] - 1]["NonzeroPositions"]; // RepeatedTiming (* 0.0855 *) Position[list, Max[list]] // RepeatedTiming (* 0.509 *) compPos[list, Max[list]] // RepeatedTiming (* Marius' solution *) (* 0.0366 *) SparseArray[Unitize[list - Max[list]], Automatic, 1][ "NonzeroPositions"]; // RepeatedTiming (* MichaelE2's solutions *) (* 0.0663 *)

differential equations - Plotting a Bifurcation diagram

I have the following system equation v'(t)=2*G*J1[v(t-τ)]cos(w*τ)-v(t) How do you plot the bifurcation diagram, τ in the x axis, Vmax in the y axis? I have written these lines but how can one plot using the following Table[NDSolve[{v'[t] == 2*G*BesselJ[1, v[t - τ + i]]*Cos[ω*(τ + i)] - v[t], v[0] == 0.001}, v, {t, 0, 500}], {i, 0, 4, 0.01}] τ is varied from 1 to 4 using step 0.01,G=3.55, ω=2*Pi*12*10^6 Answer An alternative representation is G = 3.55; ω = 2*Pi*12*10^6; s = ParametricNDSolveValue[{v'[t] == 2*G*BesselJ[1, v[t - τ]] Cos[ω*τ] - v[t], v[t /; t <= 0] == 0.001}, {v, v'}, {t, 0, 120}, {τ}]; Manipulate[ParametricPlot[{s[τ][[1]][t], s[τ][[2]][t]}, {t, 60, 120}, AxesLabel -> {v, v'}, AspectRatio -> 1], {{τ, 2}, 1, 4}] Note that the diagram becomes progressively more complex as τ is increased, and the run time increases correspondingly. Addendum The bifurcations can be seen even more clearly from a return map, for instance, tab = T

core language - What is the fastest way to get a list of subexpressions and their positions?

I have spent quite some time trying to figure out what the fastest way is to get a list lists of all subexpressions and their positions. I have tried things with MapIndexed, which seems ideal in cases where we have an expression in which no functions with Hold-Attributes are present that we can let evaluate freely. For Held expressions, however, I found using MapIndexed complicated and I was unable to get a practical solution using this. Furthermore, I have tried things with Extract and Position. All these things were hinted at in the comments of/answers to the positionFunction question by Mr.Wizard , which caused me to be interested in this. Because I have spent time on this and because I feel this is quite a fundamental question, I would like to get some feedback. To be fair, I am also quite glad with my own answer, as it is considerably faster than the alternatives I found (although it took me a long time), but if there are better alternatives I would be even gladder to know. Lastly

calculus and analysis - Integrate and NIntegrate disagreeing over branch cut of Sqrt?

Bug introduced after 8.0.4 and before 9.0.1, and fixed in 11.1.0. In Mathematica 10.2 I'm trying to integrate this piecewise continuous function, but Integrate and NIntegrate seem to disagree on the branch cut of Sqrt[] : Integrate[Sqrt[Exp[I*t]^2 - 1], {t, 0, Pi}] (* 2 Sqrt[2] - I Pi *) NIntegrate[Sqrt[Exp[I*t]^2 - 1], {t, 0, Pi}] (* 1.06568 - 4.51028*10^-16 I *) It seems that NIntegrate 's answer is correct if Sqrt[] has its branch cut on the negative real axis. Is there a way to force Integrate to use the same branch cut?

graphics3d - How do I keep my Animate running at high resolution?

I'm building an Animate where I have a 3D plot with some of its parameters changing: Animate[SphericalPlot3D[Sin[(3/z)*x], x, y, PlotStyle -> Opacity[0.7]], {z, 1, 5}] Whilst it is running through the changes though, the entire plot goes very low-res. How can I ensure that the resolution stays high throughout the animation, and not just when it stops running? Answer Also fix BoxRatios, PlotRange... 1-way: PerformanceGoal -> "Quality": Animate[SphericalPlot3D[Sin[(3/z)*x], x, y, PlotStyle -> Opacity[0.7], PerformanceGoal -> "Quality", BoxRatios -> 1, PlotRange -> 1], {z, 1, 5}] 2-way: specify explicitly options that set the quality: Animate[SphericalPlot3D[Sin[(3/z)*x], x, y, PlotStyle -> Opacity[0.7], BoxRatios -> 1, PlotRange -> 1, PlotPoints -> 30, Mesh -> 10], {z, 1, 5}]

import - Importing data sets from plain-text files and performing operations on them

I am working with a lot of daily weather files in the txt format. I need to calculate a daily quantity from each of them, e.g., daily light intensity, which involves a simple summation of the light intensity column in Excel. As I am working with over three years of data, it is not possible to do this manually. How can I automate this in Mathematica ? Currently I import all the files using the following method. (Example shown is for Jan 1 to Jan 31) filenames = FileNames[]; TestList = Flatten[Table[Files[[j, i]], {j, 1, 31}, {i, 2, 1437}], 1]; LightIntensity = TestList[[1 ;;, 5]]; DailyLightIntensity = Partition[LightIntensity, 1436]; DailySummation = Table[Total[DailyLightIntensity[[i]]], {i, 1, 31}] The method above only works assuming all the txt files contain rows from 2 to 1436, so I can use Partition , but I also need to handle cases with missing data. I want to automate this process with Mathematica , import each txt file separately, perform the necessary calculations, a

differential equations - PDE combined with ODE 1D

I try to solve the following system of PDE coupled with ODE: $$\theta_t - a\theta_{xx} + b\kappa_a(\theta^4-\varphi)=0,$$ $$-\alpha\varphi_{xx} + \kappa_a(\varphi - \theta^4) = 0,$$ $$-a\theta_x + \beta\theta|_{x=0} = 0,\;\;a\theta_x + \beta\theta|_{x=L} = 0$$ $$-\alpha\varphi_x + \gamma\varphi|_{x=0} = 0,\;\;\alpha\varphi_x + \gamma\varphi|_{x=L} = 0$$ $$\theta|_{t=0} = \theta_0, \;\;\varphi_{t=0} = \varphi_0$$ for functions $\theta, \varphi$. I use the following code ($\zeta = \theta - \theta_s$, $\xi = \varphi - \varphi_s$ where $\theta_s, \varphi_s$ is the solution of the stationary problem): s = NDSolve[{D[zeta[t, x], t] - a*D[zeta[t, x], x, x] + b*kappaa*(((thetas[x] + zeta[t, x])^4 - thetas[x]^4) - xi[t, x]) == 0, -alpha*D[xi[t, x], x, x] + kappaa*(xi[t, x] - ((thetas[x] + zeta[t, x])^4 - thetas[x]^4)) == 0, zeta[0, x] == zeta0[x], xi[0, x] == xi00[x], -a*Derivative[0, 1][zeta][t, 0] + beta*zeta[t, 0] == 0, a*Derivative[0, 1][zeta][t, ll] + beta*zeta[t

Replace "," in a list with "."

I have a list which consists of numbers which use comma (,) instead of dot (.) as their decimal point. I would like to replace the commas, but only those commas which are followed by more than five digits, with a dot. A little example: {0, "", 0, 1, 3, 93345, 27, 763212, 3} should be converted into: {0, "", 0, 1, 3.93345`, 27.763212`, 3}

constraint - Finding optimal taxation policy- constrained optimization

I need to solve two constrained optimization problems where the second problem depends on the results of the first. The agents in my economy maximize utility: $$\max_{c,d,l} p\ln(c)+\ln(d)+\ln(l)$$ subject to a budget constraint: $$(1-t)w(1-l)+T \ge c+(1+\tau)d$$ where choose $c-$ denotes consumption of non-durable goods, $d$-consumption of durable goods, and $l$- denotes labor supply. There are two agents in the economy, high skilled and low skilled (denoted by $X_h$ and $X_l$, respectively), so solving for each of them will yield the demand functions: $$c_l (t,\tau,T), c_h (t,\tau,T), d_l(t,\tau,T), d_h (t,\tau,T)$$ and the supply functions: $$l_l (t,\tau,T), l_h (t,\tau,T)$$ This part I can calculate myself but the next part is where I'm struggling. Given these demand and supply functions, the government needs to choose the tax parameters ($t,T,\tau$) that maximize the overall welfare: $\max_{t,\tau,T} p\ln(c_l)+p\ln(c_h)+2(1-p)\ln(\frac{c_l +c_h }{2})+\ln(d_l)+\ln(d_h)+\ln(l_l)

machine learning - One Hot Encode columns with categorical data

I have a couple of survey datasets that I am loading into Mathematica to do behavioral clustering. I have columns of responses (Strings) where the users was given a fixed set of responses. The surveys are really high dimensions so I can't manually go through every question type and assign a value to each string in each one of these columns. Is there a way I could encode the responses into numbers and do this for each column that has categorical responses like this? For each column that looks like this food["apple","pear","apple","orange","pizza","pizza"] and convert it to food[1,2,1,3,4,4]

differential equations - Boundary condition setup for the region defined with basic geometry

I have a region defined like this: circle = Disk[{4.5, 3}, 0.5]; pin = Rectangle[{4, 0}, {5, 3}]; square = Rectangle[{0, 0}, {9, 9}]; region = RegionDifference[square, RegionUnion[circle, pin]]; Applying RegionPlot[region] gives this: Now I need to setup boundary conditions for this region the following way: 1) Top, left, right walls: u[x,y] == 0 2) Bottom wall 0 <= x < 4: u[x,y] == 0 3) Bottom wall 5 < x <= 0: u[x,y] == 0 4) Wall at x = 4, for 0 <= y < 3: u[x,y] == 10 5) Wall at x = 5, for 0 <= y < 3: u[x,y] == 10 6) Semicircle with the center at x = 4.5 and y = 3 (radius = 0.5): u[x,y] == 10 These boundary conditions should be applied to a Laplace equation: sol = NDSolveValue[{D[u[x, y], x, x] + D[u[x, y], y, y] == 0, bc}, u, {x, y} \[Element] region] DensityPlot[sol[x, y], {x, y} \[Element] region, Mesh -> None, ColorFunction -> "Rainbow", PlotRange -> All, PlotLegends -> Automatic] Update 1: the result should be something like this

symbolic - How do I expand StirlingS2[n, 10] in terms of elementary functions?

I know that it is possible to expand StirlingS2[n, 10] in terms of elementary functions of n . I tried FunctionExpand but it returned unevaluated: In[1]:= FunctionExpand[StirlingS2[n, 10]] Out[1]= StirlingS2[n, 10] Is there a way to do this in Mathematica ? Answer You need to specify assumptions: In[1]:= FunctionExpand[StirlingS2[n, 10], n > 0 && Mod[n, 1] == 0] Out[1]= -(1/362880) + 2^(-8 + n)/315 + 1/135 2^(-7 + 2 n) + 1/315 2^(-8 + 3 n) - 3^(-3 + n)/1120 + 1/5 2^(-7 + n) 3^(-3 + n) - 5^(-2 + n)/576 + 1/567 2^(-8 + n) 5^(-2 + n) - 7^(-1 + n)/4320 - 9^(-2 + n)/4480

functions - What has changed in the Template system in 10.3?

Bug introduced in 10.3 and fixed in 11.0.0 There are couple of issues that are breaking my code after upgrading to 10.3. I wasn't able to narrow all of them down but this is what I've found. Somethings is going wrong with evaluation: Let's put TemplateSlot inside TemplateExpression , like above, give to the former a default value and try to generate an example. In 10.2 and 10.3: gives: Have I missed something? Which one is expected result? I'd say 10.2 works as expected. Is this the case on Mac and Linux too? A support case with the identification [CASE:3522351] was created. Answer This bug was fixed with V11.0.0 release.

implicit - Plotting a function with implicitly defined variable

I have a question about plotting a function with an implicitly defined variable. I think the solution should be something similar like here: Define a function with variables linked implicitly but I quite can't get it to work. I apologize if this has been asked for, I tried doing a thorough search before asking. Anyway, I am trying to plot the following function: $$ u(x,y,t)=\text{sgn}(x+y-t+r(t))\big(e^{-\vert x+y-t+r(t) \vert }-1\big)+r(t)e^{-\vert x+y+r(t)+\ln(\frac{1}{9}r(t)^2-\frac{1}{2}r(t)+1)\vert} $$ where $r(t)$ is implicitly defined with the following equation $$ \ln\vert r(t)\vert-\frac{1}{2}\ln\vert r(t)^2-\frac{9}{2}r(t)+9\vert+\frac{3\sqrt{}{7}}{7}\tan^{-1}\big(\frac{4r(t)-9}{3\sqrt{}{7}}\big)=2t. $$ Ultimately, I would like to use Plot3D for $u(x,y)$ and use Manipulate to see the function at different time steps of $t$. Thank you in advance for your time and help. It's greatly appreciated. Edit: Here is some mathematica format to make life easier: Sign[x + y - t

functions - How to sum over a List

list = {11.5575, 11.397, 5.52734, 4.0878, 2.54815, 1.86652, 2.55028, 2.14952, 1.6242, 1.34117} I have a list of numbers. How do I make a function that creates a new list, where the first entry is equal to {list[[1]], list[[1]] + list[[2]], list[[1]] + list [[2]] + list[[3]]} etc until the end of the list. I ask because my real list is quite a bit longer than just 10 entries, and writing this out would get far too long to handle. Answer Accumulate is absolutely the most idiomatic and appropriate answer here. However since Mathematica is very powerful at list manipulation, it might be illustrative to show you couple of other ways of doing the same thing, just so you learn to think outside of mainstream procedural ways. 1. Using FoldList : This is a functional way of doing exactly what you wrote by hand, and probably the first option you should be thinking of, if Accumulate were not available. Rest@FoldList[Plus, 0, list] The advantage of knowing this method, is that you can use it f

list manipulation - Failure in integrating from an interpolating function!

Consider a list like below: ttable={{0, 2.6596 - 66.137 I}, {1/9, 2.45339 - 65.3148 I}, {2/9, 1.82053 - 62.8922 I}, {1/3, 0.720006 - 58.9982 I}, {4/ 9, -0.911205 - 53.8382 I}, {5/9, -3.15056 - 47.6797 I}, {2/ 3, -6.08057 - 40.8346 I}, {7/9, -9.77826 - 33.6382 I}, {8/ 9, -14.3047 - 26.4282 I}, {1, -19.6947 - 19.5216 I}}` by defining "f" as interpolating function we'll have: f = Interpolation[ttable] now we define ff as the following integration: ff[\[Xi]_]:=NIntegrate[(f[rr]) Cos[rr \[Xi]], {rr, 0, 1}] the first problem is that this function can not be calculated and I have no idea why the followoing error happens: In[87]:= ff[.1] During evaluation of In[87]:= NIntegrate::inumr: The integrand Cos[rr \[Xi]] InterpolatingFunction[{{0.,1.}},{4,15,0,{10},{4},0,0,0,0,Automatic,{},{},False},<<1>>,{ Developer`PackedArrayForm,{0,<<10>>},{2.6596 -66.137 I,<<8>>,-19.6947-19.5216 I}},{Automatic}][rr] has evaluated to non-numerical values fo

front end - Mathematica notebook autocompletion completely disappears

Just as what is described in the title, the notebook behaves as if it were originally designed to not have the autocompletion functionality at all. Neither Ctrl + K nor F2 works. Furthermore, reinstalling Mathematica does not help, either. What measures could be taken that possibly help to recover the autocompletion functionality? I suspect that some items in "Option Inspector" might be responsible but I can not find them. It seems that quite a few people encounter this problem recently. But, for now, the " $UserBaseDirectory deletion / renaming methods" cannot thoroughly settle this issue, can they? Answer PacletUpdate["EntityFramework"] should resolve the issue at this point.

plotting - Why Plot3D does not accept Epilog option

I am trying to visualize 3D points with Plot3D using the option Epilog. If you check the options of Plot3D ( Options[Plot3D] ), it can be seen that Epilog is one of the options of Plot3D. But when implementing this option not result as expected. for example: data = Flatten[ Table[{i, j, i^2 + j^2}, {i, -2, 2, .5}, {j, -2, 2, .5}], 1]; Plot3D[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2}, Epilog -> {PointSize[Large], Point[data]}, PlotRange -> All] Of course there is another ways (like using Show ), but the question is why Plot3D does not accept its own option? Answer Why does Plot3D not accept its own option? But it does accept it just fine, as Kuba's comment shows: Plot3D[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2}, Epilog -> {PointSize[Large], Point[{.5, .5}]}, PlotRange -> All] I guess you mean to ask, Why does Plot3D not accept 3D graphics in Epilog ? Because Epilog is for drawing things in front of the plot, just as Prolog is for drawing things behind

numerical integration - Is it possible to set a variable as a positive one in the whole notebook?

I'm having issues during integration due to the fact that Mathematica doesn't know if an undefined variable is positive or not (it gives me complexes which bothers me in the end). For example I do this: yy[x_, t_] = aa[t]*(Cos[0.1*x]-Cosh[0.1 x]-Sin[0.1 x]+Sinh[0.1 x]) Integrate[D[yy[x, t], t]^2, {x, 0, 18}] gives me: (10.1601 + 0.I) aa'[t]² while the 0.I shouldn't be here. By using: Integrate[D[yy[x, t], t]^2, {x, 0, 18}, Assumptions -> aa[t] > 0] I get rid of the imaginary part but this has to be done cell by cell. Then comes my questions, is it possible to define, in that case, aa[t] as a posivite variable in the whole notebook and not cell by cell? Note that in this expample the I is not bothering at all, but with concrete numbers it messes everything up, even by using Chop . Answer You can modify the global system variable $Assumptions , to get the effect you want: $Assumptions = aa[t] > 0 Then Integrate[D[yy[x, t], t]^2, {x, 0, 18}] 10.1601 Derivati

plotting - Printing problem: PDF output has a plot error

In my Mathematica file I have several plots that I put together in a grid. One of the plots is coded with the following code: gr1 = ListPlot[baseplateTemp2, Joined -> True, ImagePadding -> {{110, 30}, {5, 42}}, ImageSize -> Full, AspectRatio -> .18, Frame -> {Left, Top, Right}, PlotRange -> {{first, last}, {-40, 80}}, FrameTicks -> {{Automatic, Automatic}, {Automatic, topaxis}}, BaseStyle -> {FontSize -> 14}, FrameLabel -> {{"Baseplate\n Temperature, \[Degree] C", ""}, { "", "Time Offset, Days"}}, GridLines -> {botax, Automatic}, Axes -> None] and is then grouped with another set of plots within a Grid : Grid[{{gr1}, {grf10M}, {gr9}}] The problem that ensues is the following: my typical output would look something like this on screen: However, whenever I export the Mathematica slide show (by the way, I save a series of slides together— with similar cells as those shown in the first picture, as a pdf) as a pdf v

plotting - Region rotated about the line y=2

Could a few people share the best way to display the image created by rotating the region bounded by $y=x^4$ and $y=1$ about the line $y=2$? Thanks. Update: I took JasonB's hint and tried this: Show[ RevolutionPlot3D[x^4 - 2, {x, -1, 1}, RevolutionAxis -> {1, 0, 0}, AxesLabel -> {"x", "z", "y"}], RevolutionPlot3D[-1, {x, -1, 1}, RevolutionAxis -> {1, 0, 0}] ] Which gave this image: How can I change the ticks on the y-axis to run from 0, 1, 2, 3, and 4? Thanks. Second Update: Looks like I found an answer to my tick question. Manipulate[ RevolutionPlot3D[{{x^4 - 2}, {1 - 2}}, {x, -1, 1}, {\[Theta], 0, tau}, RevolutionAxis -> "X", PlotRange -> {{-1, 1}, {-2, 2}, {-2, 2}}, AxesLabel -> {"x", "z", "y"}, PerformanceGoal -> "Quality", Ticks -> {Automatic, Automatic, {{-2, 0}, {-1, 1}, {0, 2}, {1, 3}, {2, 4}}}], {{tau, 0.1}, 0, 2 \[Pi]}]