Poisson equation with pure Neumann boundary conditions

Dear Mathematica users,

I would like to numerically solve a, as the title says, Poisson equation with pure Neumann boundary conditions

$ \nabla^2(\psi)=f$
$ \nabla(\psi)\cdot \text{n}=g$

Is it possible?

For an example I will use the demo from FEniCS project.

$ f=10\text{Exp}(-((x – 0.5)^2 + (y – 0.5)^2)/0.02)$
$ g=-\text{Sin}(5x)$

In Mathematica

f = 10*Exp[-(Power[x - 0.5, 2] + Power[y - 0.5, 2])/0.02] g = -Sin[5*x]; Needs["NDSolve`FEM`"] bmesh = ToBoundaryMesh["Coordinates" -> {{0., 0.}, {1, 0.}, {1, 1}, {0., 1}, {0.5, 0.5}},"BoundaryElements" -> {LineElement[{{1, 2}, {2, 3}, {3, 4}, {4,1}}]}]; mesh = ToElementMesh[bmesh, "MaxCellMeasure" -> 0.001];  m[x_, y_] =   NDSolveValue[{Laplacian[u[x, y], {x, y}] - f ==       NeumannValue[g, True] (*,DirichletCondition[u[x,y]==0, x==0.5&&y==0.5]*)}, u, {x, y} \[Element] mesh][x, y]  ddfdx[x_, y_] := Evaluate[Derivative[1, 0][m][x, y]]; ddfdy[x_, y_] := Evaluate[Derivative[0, 1][m][x, y]]; Show[ContourPlot[m[x, y], {x, y} \[Element] mesh, PlotLegends -> Automatic, Contours -> 50], VectorPlot[{ddfdx[x, y], ddfdy[x, y]}, {x, y} \[Element] mesh,    VectorColorFunction -> Hue, VectorScale -> {Small, 0.6, None}]] 

Trying to solve this in Mathematica gives a clear and understandable error

NDSolveValue::femibcnd: No DirichletCondition or Robin-type NeumannValue was specified; the result may be off by a constant value. 

However, the result is not so clear and understandable.

enter image description here

The answer one would like to get should look something like the following image enter image description here

I tried equation elimination from this post, i.e. using

DirichletCondition[u[x, y] == 0, x == 0.5 && y == 0.5] 

to get the result. Now it looks decent if one doesn’t care about the sink which appears.. Sadly I do care as I’m interested in the gradient of $ \psi$ so such an approach leads me nowhere.

enter image description here

enter image description here

So then the question – is it possible to numerically solve Poisson equation with pure Neumann boundary conditions with Mathematica? Can anyone suggest some steps how to do this?

To add, sadly I am not a mathematician so I lack the ability to implement some routine on my own. Maybe something can be done using the weak formulation as in the example, but before trying to implement (would it actually be possible?) that I would like to learn if there is another way.

Normalize Deflection Equation

This question is probably more math related…

I know the beam deflection equation for a clamped-clamped beam due to a point load at its center (https://ocw.mit.edu/courses/mechanical-engineering/2-080j-structural-mechanics-fall-2013/course-notes/MIT2_080JF13_Lecture5.pdf, equation 5.46b)

$ \left. w \right| _ { \text { point } } = \frac { P x ^ { 2 } } { 48 E I } ( 3 l – 4 x )$

Now, I would like to normalize it, such that:

  1. Maximum Deflection should be equal to 1:

$ a(x) = \frac{w(x)}{w(L/2)}$

  1. x should be normalized with respect to the length of the beam:

$ b(\hat{x}) = a(\hat{x} L)$

When I do this in Mathematica:

ClearAll["Global`*"] w[x_] := P*x^2/(24*Y*ii)*(3*L - 4*x); a[x_] = w[x]/w[L/2]  b[xh_] = a[xh*L] // Simplify Plot[a[xh], {xh, 0, 1}] 

enter image description here

As you can see, this is not an expected shape of a deformed beam due to a point force. Anyone knows what I am doing wrong ? Thanks!

How to graph acceleration from an equation given a sample period?

I am unfamiliar with Mathematica and the necessary syntax to approach visualize acceleration over time. I would appreciate some assistance or reference to a starting point on how to go about solving this problem. Please note that I have never used Mathematica before.

I am writing some game code that handles a third-person camera rotation that increases in speed over time (acceleration) as the left or right directional buttons are held down.

I am currently polling the directional button once every t milliseconds where sampling begins at the base and increases linearly every 100ms by a delta towards a maximum sampling rate.

So, for example (in microseconds):

TurnAccelMin = 10000.0 TurnAccelMax = 2000.0 TurnDelta = 1000.0 

Note that acceleration is based on the sample rate so a lower maximum results in more samples over time. Even though sampling is in milliseconds, acceleration is stored as microseconds to account for a finer delta.

I would like to graph this so that I can visually see how the delta affects the acceleration over time. While I can picture in my mind the linear acceleration, I want to graph this so that I can visualize how different kinds of acceleration (exponential, quadratic, etc.) affect acceleration over a sample period.

How can I graph this as a line given these values as an equation?

Currently (as linear), where x = Time between 0 and 5 seconds and y = Acceleration in milliseconds.

Ideally I would like to see a graph of points, each connected by a straight line, as well as a table of values for each point when it is polled.

Factoring 5th degree equation

I’ve got stuck on my factoring homework and it says that I need to factor this 5th degree equation with rational coefficients:

$ x^{5}-17x^{4}+105x^{3}-295x^{2}+374x-168$

How I did it was by long division and checking the terms. I first thought that $ x-5$ seems to be a factor because the $ x^{3}$ and $ x^{2}$ terms both have a factor of 5 but if I divide it looks like that it has a remainder of $ 48$ . Although, that’s not what I wanted. I then checked if I can pull out a $ x-2$ because the $ x$ term and the constant term both are even. This time there is no remainder but then it got me into a harder 4th degree factorization problem.

How could you factor the 5th degree equation in another way that’s easier to factor?

Are the following Mathematica codes correct for solving wave equation PDE?

I wanna solve the following PDE of wave equation using Mathematica.

$ u_{tt}=u_{xx}$

$ 0<x<\pi , t>0$

Initial Conditions:

$ \begin{cases}u(x,0)=sin(x) \u_{t}(x,0)=1\end{cases}$

Boundary Conditions:

$ \begin{cases}u(0,t)+u_{x}(0,t)=1\u(\pi,t)+u_{x}(\pi,t)=-1\end{cases}$

  • I know the boundary and initial conditions are inconsistent.

Are the following codes correct?

weqn = D[u[x, t], {t, 2}] == D[u[x, t], {x, 2}]; ic = {u[x, 0] == Sin[x],Derivative[0, 1][u][x, 0] == 1 }; bc = {u[0, t] + Derivative[1, 0][u][0, t] == 1,     u[Pi, t] + Derivative[1, 0][u][Pi, t] == -1}; sol = NDSolve[{weqn, ic, bc}, u, {x, 0, Pi}, {t, 0, 10}]; 

derivative with respect to dirac function: understanding equation (15) in paper “Deterministic Policy Gradient Algorithms 2014”

in http://proceedings.mlr.press/v32/silver14.pdf

equation (14) said $ J_{\beta}(\mu_{\theta}) = \int_s \rho^{\beta}(s)Q^{\mu}(s, \mu_{\theta}(s))ds$

I do not quite understand the first line of equation (15) , where it reads $ \nabla_ {\theta}J_{\beta}(\mu_0) \approx \int_s \rho^{\beta}(s) \nabla_{\theta}\mu_{\theta}(a|s)Q^{\mu}(s,a)ds\ = E_{s \sim \rho^{\beta} }[\nabla_{\theta}\mu_{\theta}(s)\nabla_{a}Q(s,a)|a=\mu_{\theta}(s)] $

  1. what does $ \mu_{\theta}(a|s)$ mean here? note that this is deterministic policy, so there is no probability distribution of actions, and in the expression, the $ a$ come out of nowhere. it is not integrated out.

  2. why the first line exactly equals the second line?

  3. does the first line in equation (15) actually should be $ \nabla_{\theta}[\int_a \delta(a-\mu_{\theta}(s))Q^{\mu}(s,a)da]$ , is so , how do i calculate the expression with dirac function $ \delta(a-\mu_{\theta}(s))$ here?

Solving a difficult differential equation

Well, I’ve to solve the following DE:

$ $ y(t)=x(t)\cdot\text{a}+\text{b}\cdot\ln\left(1+\frac{x(t)}{\text{c}}\right)+\int_0^tx(\tau)\cdot p(t-\tau)\space\text{d}\tau\tag1$ $

And I’ve no idea how to start.

Some background information: this DE describes a current in an electric circuit. For the values of $ a,b$ and $ c$ I know that they are real and positive. For $ c$ I know that $ 10^{-4}\le c\le10^{-16}$ . The function $ y(t)=k\cdot\theta\left(t-m\right)+(n-k)\cdot\theta\left(t-v\right)$ where all the values of the constants are ral and positive and $ \theta$ is the Heaviside Theta function. The function $ p(t-\tau)=\mathcal{L}_\text{s}^{-1}\left\{\frac{1}{\frac{1}{R_2+sl}+\frac{s}{sR_3+\frac{1}{z}}}\right\}_{\left(t-\tau\right)}$ where all the constants are again real and positive.

Floating point precision from rearranging equation

When I run $ x^2 – y^2$ with x=8.8888888888 and y=9.9999999999 in python, I get the following result:

>>> 8.8888888888**2 - 9.9999999999**2 -20.9876543205679 

However, if I rearrange it to $ (x-y)(x+y)$ with the same x and y values, I get:

>>> (8.8888888888 - 9.9999999999) * (8.8888888888 + 9.9999999999) -20.987654320567895 

It seems that the two equations, though logically equivalent, give varying amounts of floating point precision by a difference of 2 digits. What could be causing this?

Doubt about solution of the transport equation

Consider the following PDE (the unknown is $ u\in C^1(\mathbb{R}^{n+1},\mathbb{R})$ ):

$ \partial_tu(x,t)+\sum_{k=1}^{n} a_k\partial_k u(x,t)= cu(x,t)$

$ u(x,0)=g(x)$

where $ g \in C(\mathbb{R}^n, \mathbb{R})$ , $ a\in \mathbb{R}^n$ and $ c\in \mathbb{R}$ .

My textbook shows that if $ u$ is a solution, then we must have $ u(x,t)=g(x-ta)e^{ct}=:v(x,t)$ ; and, it says, $ v$ is a solution.

It seems to me it is assuming $ g\in C^1$ , because (here $ k=1,…,n$ ) $ \partial_k v(x,t)= \lim_{s\to 0}{e^{ct}(g(x-ta+se_k)-g(x-ta))/s }$ exists iff $ \partial_k g(x-ta)$ exists, and in that case $ \partial_k v(x,t)=e^{ct}\partial_k g(x-ta)$ so that $ v\in C^1$ iff $ g \in C^1$ .

After assuming $ g \in C^1$ I am able to verify that $ v$ solves the equation.

Am I correct in saying that $ g$ must be in $ C^1$ so that the equation can be solved?

PS Is ‘it’ the correct pronoun when referring to what the text is saying? Or should I use ‘he/she’ because it is understood that the author is saying that? (Probably a stupid question)