# Perform Integration involving vectors, in 3D?

Posted 4 months ago
570 Views
|
7 Replies
|
2 Total Likes
|
 Since I'm new to Mathematica I was looking for ways to learn vector integration and how to do them efficiently, so I came across this article where they did calculation for field in a point above a "slab" (magnetized bit) using Biot-Savart integration. To calculate following integral which is in vector form; I have problem defining parameters and variables. The integral is as following: $dH(r)= D \frac{\vec dl \times (\vec r_i' - \vec r)}{|\vec r_i' - \vec r|^3}$Once problem is defined, they end up with this integral for x direction (I assume one can difine similar for $y$ and $z$). $H(r)=\sum_{i=1}^{4} C \int_{-l/2}^{l/2} \int_{0}^{1} \frac{\frac{\partial \vec r_i'}{\partial p} \times(\vec r_i'-\vec r)}{|\vec r_i' - \vec r|^3}dt dx$In my approach I call $C$ and $D$ constants and two vectors: $\vec r$ (field point) and $\vec r_i'$ (source point), with $\vec r = x \hat x + y \hat y + z \hat z$ and $\vec r_i'$vectors: $\vec r_1' (x,t) = (x \hat x + \frac{W}{2} \hat y + \frac{T}{2}\hat z)+ (-tW \hat y) = [x \hat x + (\frac{w}{2} - tW) \hat y + \frac{T}{2}\hat z]$ $\vec r_2' (x,t) = (x \hat x - \frac{W}{2} \hat y + \frac{T}{2}\hat z)+ (-tT \hat z) = [x \hat x - \frac{w}{2}\hat y + (+ \frac{T}{2} - tT)\hat z]$ $\vec r_3' (x,t) = (x \hat x - \frac{W}{2} \hat y - \frac{b}{2}\hat z)+(tW \hat y) =[x \hat x + (- \frac{W}{2} + tW) \hat y + \frac{T}{2}\hat z]$ $\vec r_4' (x,t) = (x \hat x + \frac{W}{2} \hat y - \frac{T}{2}\hat z)+(tT \hat z) =[x \hat x + \frac{W}{2}\hat y + (+ \frac{T}{2} + tT)\hat z]$where $W$ is width of a "slab" in $y$ direction and $T$ is thickness of the slab in $z$ direction. $t$ changes from 0 to 1 and x changes from $-l/2$ to $l/2$In Mathematica, I don't know how to define variables within vectors and do the summation integration altogether. So my first attempt was to do individual form a individual piece of integral, for example for vector $\vec r_1'$ in $x$ coordinate in following way: r := {x, y, z}; r1 := {x, W/2 - t W , T/2}; r1 - r = {0, W/2 - W t - y, T/2 - z} D[r1, t] = {0, -W, 0} Cross[{0, -W, 0}, {0, W/2 - W t - y, T/2 - z}] = {-((W T)/2) + W z, 0, 0} Norm[r1 - r]^3 = (Abs[-1 + T/2]^2 + Abs[-1 + W/2 - W t]^2 + Abs[-1 + x]^2)^(3/2) then when I put pieces to the integrate function: Integrate[(-((W T)/2) + W z)/(Abs[W/2 - W t - y]^2 + Abs[T/2 - z]^2)^(3/2), {t, 0, 1}] to calculate only for $t$ variable it takes forever and gives me a conditional result. And I tried using assumption Integrate[(-((W T)/2) + W z)/((W/2 - W t - y)^2 + (T/2 - z)^2)^(3/2), {t, 0, 1}, Assumptions -> W > 0 && T>0] or generally Integrate[Cross[D[r1, t], r1] /Norm[(r1 - r)]^3, {t, 0, 1}, Assumptions -> Im[W] == 0 && Im[T] == 0] still lengthy integral. And I know doing like this is wrong, because the definitions are not correct and plus integral doesn't even have $x$ component which is basically useless to get the result similar to their. I know there must be a better way, maybe do numerical integration of vectors, or something, so I tried to search similar problems however, I couldn't find anything useful. I would really appreciate if you show me the way you would define such problems to Mathematica and solve it efficiently. If you want to look at the paper the DOI is provided below. DOI:10.1007/s00542-011-1245-7 (this problem was posted in stack exchange too)
7 Replies
Sort By:
Posted 4 months ago
 what to do depends on the answer you needvector calculus is one way to get an answer (not the only)for example, i could ask why not use a triple integral (but i know this may not be the area you wish to find ... in all cases)is this for fun or do you actually have a field application you need to meet?
Posted 4 months ago
 Let's just say I want to learn and want to follow exactly similar analytical solution. I was going to do triple integration too as you see according to my first attempt, I don't get a satisfying result from integration.
Posted 4 months ago
 Try this code. There are two typical integrals through which one can express a solution In[1]:= r0 = {x0, y0, z0}; r[1] = {x, W/2 - t*W, T/2}; r[2] = {x, -W/2, T/2 - t*T}; r[3] = {x, -W/2 + t*W, -T/2}; r[4] = {x, W/2, -T/2 + t*T}; rt = Table[D[r[i], t], {i, 1, 4}] Out[6]= {{0, -W, 0}, {0, 0, -T}, {0, W, 0}, {0, 0, T}} In[7]:= B = Sum[Cross[rt[[i]], (r[i] - r0)]/((r[i] - r0).(r[i] - r0))^(3/2), {i, 1, 4}] Out[7]= {(-((T W)/2) - T y0)/((x - x0)^2 + (-(W/2) - y0)^2 + (T/2 - t T - z0)^2)^( 3/2) + (-((T W)/2) + T y0)/((x - x0)^2 + (W/2 - y0)^2 + (-(T/2) + t T - z0)^2)^( 3/2) + (-((T W)/2) - W z0)/((x - x0)^2 + (-(W/2) + t W - y0)^2 + (-(T/2) - z0)^2)^( 3/2) + (-((T W)/2) + W z0)/((x - x0)^2 + (W/2 - t W - y0)^2 + (T/2 - z0)^2)^( 3/2), (-T x + T x0)/((x - x0)^2 + (-(W/2) - y0)^2 + (T/2 - t T - z0)^2)^(3/2) + ( T x - T x0)/((x - x0)^2 + (W/2 - y0)^2 + (-(T/2) + t T - z0)^2)^( 3/2), (-W x + W x0)/((x - x0)^2 + (-(W/2) + t W - y0)^2 + (-(T/2) - z0)^2)^( 3/2) + (W x - W x0)/((x - x0)^2 + (W/2 - t W - y0)^2 + (T/2 - z0)^2)^(3/2)} In[23]:= Integrate[Integrate[1/(p^2 + u^2 + v^2)^(3/2), u], v] Out[23]= ArcTan[(u v)/(p Sqrt[p^2 + u^2 + v^2])]/p In[9]:= Integrate[Integrate[v/(p^2 + u^2 + v^2)^(3/2), u], v] Out[9]= -ArcTanh[Sqrt[p^2 + u^2 + v^2]/u] In[10]:= I1[p_, u_, v_] := ArcTan[(u v)/(p Sqrt[p^2 + u^2 + v^2])]/p I2[p_, u_, v_] := -ArcTanh[Sqrt[p^2 + u^2 + v^2]/u] In[17]:= Bx4[x_, t_, x0_, y0_, z0_, W_, T_] := -(W/2 + y0)* I1[W/2 + y0, t*T + z0 - T/2, x - x0] + (y0 - W/2)* I1[y0 - W/2, t*T - z0 - T/2, x - x0] - (z0 + T/2)* I1[z0 + T/2, t*W - y0 - W/2, x - x0] + (z0 - T/2)* I1[z0 - T/2, t*W + y0 - W/2, x - x0] In[18]:= Bx2[x_, x0_, y0_, z0_, W_, T_] := Bx4[x, 1, x0, y0, z0, W, T] - Bx4[x, 0, x0, y0, z0, W, T] In[19]:= Bx[x0_, y0_, z0_, W_, T_, L_] := (Bx2[L/2, x0, y0, z0, W, T] - Bx2[-L/2, x0, y0, z0, W, T])/(4*Pi) In[35]:= Plot3D[-Bx[x, y, 20, 50, 20, 50], {x, -100, 100}, {y, -100, 100}, Mesh -> None, ColorFunction -> "TemperatureMap", PlotLegends -> Automatic, AxesLabel -> {"x", "y", "\!$$\*SubscriptBox[\(H$$, $$x$$]\)/\!$$\*SubscriptBox[\(H$$, \ $$c$$]\)"}, PlotRange -> All, PlotPoints -> 50, Exclusions -> None]  Attachments:
Posted 4 months ago
 This looks really nice and cool. A questions though: How did you chose the functions for $I1$ and $I2$ in lines: In[23]:= Integrate[Integrate[1/(p^2 + u^2 + v^2)^(3/2), u], v] In[9]:= Integrate[Integrate[v/(p^2 + u^2 + v^2)^(3/2), u], v] I kind of see that there is a $u$ function depends on $t$ (not in numerator of Sum) and $v$ function depends on $x$ (in the numerator Sum) but would like to know how did you define them to be $- \tanh^{-1} [ \sqrt{p^2 + u^2 + v^2}/u]$ and $\tan^{-1}[\frac{\frac{u v}{p \sqrt{p^2 + u^2 + v^2}}}{p}]$ , and how did you pick coefficients for Bx4 In[17]:= Bx4[x_, t_, x0_, y0_, z0_, W_, T_] := -(W/2 + y0)* I1[W/2 + y0, t*T + z0 - T/2, x - x0] + (y0 - W/2)* I1[y0 - W/2, t*T - z0 - T/2, x - x0] - (z0 + T/2)* I1[z0 + T/2, t*W - y0 - W/2, x - x0] + (z0 - T/2)* I1[z0 - T/2, t*W + y0 - W/2, x - x0] This is good to know because I want to evaluate $H(r)$ with respect to $y$ and $z$ as well. Thanks a lot.
Posted 4 months ago
 Mathematica is not a mathematician, it is a system with its limitations. Therefore, direct calculations often do not work. We must use the system to solve simple problems. But we must simplify the task ourselves. I have already solved analogous problems with vector integration. I know that a solution can be expressed in this form. Let's take B [[2]] By4[x_, t_, x0_, y0_, z0_, W_, T_] := -I2[W/2 + y0, t*T + z0 - T/2, x - x0] + I2[y0 - W/2, t*T - z0 - T/2, x - x0] By2[x_, x0_, y0_, z0_, W_, T_] := By4[x, 1, x0, y0, z0, W, T] - By4[x, 0, x0, y0, z0, W, T] By[x0_, y0_, z0_, W_, T_, L_] := (By2[L/2, x0, y0, z0, W, T] - By2[-L/2, x0, y0, z0, W, T])/(4*Pi) Plot3D[-By[x, y, 20, 50, 20, 50], {x, -100, 100}, {y, -100, 100}, Mesh -> None, ColorFunction -> "TemperatureMap", PlotLegends -> Automatic, AxesLabel -> {"x", "y", "\!$$\*SubscriptBox[\(H$$, $$y$$]\)/\!$$\*SubscriptBox[\(H$$, \ $$c$$]\)"}, PlotRange -> All, PlotPoints -> 50, Exclusions -> None] ![Y component ][1]  Attachments:
 Finally, let's take B[[3]] Bz4[x_, t_, x0_, y0_, z0_, W_, T_] := -I2[T/2 + z0, t*W - y0 - W/2, x - x0] + I2[z0 - T/2, t*W + y0 - W/2, x - x0] Bz2[x_, x0_, y0_, z0_, W_, T_] := Bz4[x, 1, x0, y0, z0, W, T] - Bz4[x, 0, x0, y0, z0, W, T] Bz[x0_, y0_, z0_, W_, T_, L_] := (Bz2[L/2, x0, y0, z0, W, T] - Bz2[-L/2, x0, y0, z0, W, T])/(4*Pi) Plot3D[-Bz[x, y, 20, 50, 20, 50], {x, -100, 100}, {y, -100, 100}, Mesh -> None, ColorFunction -> "TemperatureMap", PlotLegends -> Automatic, AxesLabel -> {"x", "y", "\!$$\*SubscriptBox[\(H$$, $$z$$]\)/\!$$\*SubscriptBox[\(H$$, \ $$c$$]\)"}, PlotRange -> All, PlotPoints -> 50, Exclusions -> None]  Attachments: