Solving a second-order differential equation with both Dirichlet and Neumann boundary conditions - symbolic-math

I want to solve the Fourier’s law for the heat equation
of an isolated electrically heated rod:
with a Dirichlet boundary condition of
and a Neumann boundary condition of
where
x is the length coordinate
L is the length of the rod
K is the thermal conductivity of the material (assumed constant)
Q is the internal heat generation per unit length
q heat load from the left side
TL is the ambient temperature on the right side
To solve the differential equation I used the
eqn : 'diff(T, x, 2) + Q / k = 0;
sol : ode2(eqn, T, x);
giving the correct general form of
however when applying the boundary conditions using:
bc2(sol, x=0, 'diff(T, x)=-q/k, x=L, T=TL);
I get the wrong answer of
while what I expected to see was
I would appreciate it if you could help me know what is the problem and how I can resolve it.

In this specific case, because the Neumann boundary condition happened in the x = 0 I could use the
ic2(sol, x=L, T=TL, 'diff(T, x)=-q/k);
to get the correct result:

Related

Qubit state after this quantum circuit (Hadamard+Eigen Operator+Hadamard)

Could anyone help me with this circuit? I'm trying to walk through this exercise but failed. The first register carries a single bit and the bottom carries an n-qubit state. |ψ_0〉is an eigenstate of operator U, i.e. U|ψ_0〉= e^{2πiθ}|ψ_0〉, where 0 ≤ θ < 1.
What will the probability of measuring 0 on the top register? And what is the output state |ψ_1〉be?
I got the P(0) on the first register = 1/4 (2+cosθ), which seems really strange for me. Is it correct?
Cheers!

Question about performance for raytracing algorithm intersection test

I'm currently building a basic raytracing algorithm and need to figure out which system of handling the intersections would be best performance-wise.
In the method I'm checking for a intersection of the ray and the object I'm returning a struct with the distance of the ray traveled to the hit, the position vector of the hit and the normal vector or -1 for the distance if there is no intersection.
For the next step I have to find the shortest distance of all intersections and exclude the ones with a negative distance.
I even thought about having 2 structs, one with only negative distances and one full struct to reduce the amount of space needed, but thought this wouldn't really make a difference.
My options so far:
first go over the array of the intersections and exclude the ones with negative distances, then find the shortest distance from the remainings via a sorting algorithm (probably insertion sort due to quick implementation).
Or put them together in one algorithm and test in each sort step if the distance is negative.
typedef Point3f float[3];
typedef struct {
float distance;
Point3f point;
Point3f normal;
} Intersection;
Intersection intersectObject (Ray-params, object) {
Intersection intersection;
//...
if (hit) {
intersection.distance = distance;
intersection.point = point;
intersection.normal = normal;
} else {
intersection.distance = -1.0f;
}
return intersection;
}
//loop over screen pixel
Intersection* intersections;
int amountIntersections;
//loop over all objects
//here I would handle the intersections
if (amountIntersections) {
//cast additional rays
}
I can't really figure out what would be the best way to handle this, since this would be called a lot of times. The intersection array will probably be a dynamic array with the amountIntersections as the length variable or an array with the most expected amount of intersections which then have intersections in it with negative distances.
Here is the approach I've succesfully used for a huge number of objects. (Especially for ball-and-stick atomic models; see my Wikipedia user page for the equations I used for those.)
First, transform the objects to a coordinate system where the eye is at origin, and the projected plane is parallel to the xy plane, with center on the positive z axis. This simplifies the equations needed a lot, as you can see from the above linked page.
As an example, if you have a unit ray n (so n·n = 1) and a sphere of radius r centered at c, the ray intersects the sphere if and only if h ≥ 0,
h = (n·c)2 + r2 - (c·c)
and if so, at distance d,
d = n·c ± sqrt(h)
If you work out the necessary code, and use sensible temprary variables, you'll see that you can reject non-intersecting spheres using eight multiplications and six additions or subtractions, and that this vectorizes across objects easily using SSE2/AVX intrinsics (#include <x86intrin.h>). (That is, do not try to use an XMM/YMM vector register for n or c, and instead use each register component for a different object, calculating h for 2/4/8 objects at a time.)
For each ray, sort/choose the objects to be tested according to their known minimum z coordinate (say, cz - r for spheres). This way, when you find an intersection at distance d, you can ignore all objects with minimum z coordinate larger than d, because the intersection point would necessarily be further out, behind the already known intersection.
Similarly, you should ignore all intersections where the distance is smaller than the distance to the projection plane (which is zd / nz, if the plane is at z = zd, and only needs to be computed once per ray), because those intersections are between the eye and the projection plane. (Technically, you've "crashed into" something then, if you think of the projection plane as a camera.)

Homework - Cross product of 3 points in 2D space

I'm mostly unfamiliar with vectors, so wondered if I might get some help here.
I'm working a convex hull project in 2d space. The specific function I'm working on needs to determine if a point lies to the left of a line, to the right, or directly on the line.
I've been told to do this using a cross-product. The three points create a triangle in 2d space. Computing the cross product is supposed to give me the area of the triangle. If the area is positive, points p-> q-> r work counter-clockwise, meaning that point r lies to the left of line p-q. Likewise, if the area is negative, points p->q->r work clockwise, and point r lies to the right of line p-q. If the area is 0, r lies on line p-q.
I understand what to do with the end result, I just have no idea what formula I'm supposed to be using.
My problem is that I'm unfamiliar with the cross-product, and the research I've done doesn't clarify how to do this with 3 points. My hunch is that it's the same process as doing it with 2 vectors, but if this is the case, I have no idea how exactly to translate my 3 points into 2 vectors.
Thanks very much!
Your triangle has the sides q-p and r-p, so you have to calculate
(q - p) x (r - p)
where a x b is the determinant
a x b = (a.x * b.y - a.y * b.x)
which is sometimes called "2-dimensional cross product" (see for example
http://mathworld.wolfram.com/CrossProduct.html).

Viola jones weak classifier explanation

I have been trying to understand the paper by viola n jones on face detection. I am not totally sure what this equation's parameters mean from section 3
h(x, f, p, theta) = 1 ; if pf(x) < p theta
What I understood was feature (f) is the value that is obtained by running any of those 5 basic features explained in the beginning of the paper over integral image of x.
What I can't understand properly is the threshold 'theta' and polarity 'p'. Does this pmean positive image and negative image and can have value of +1 or -1? And how do I calculate theta. This equation is vital to boosting section so I can't go further. Please help if I am making myself clear enough.
You must understand that the weak classifier h uses a Haar-like feature f to classify an image subwindow x. The parameter p, if equal to -1, simply causes the inversion of the comparison sign of the condition if pf(x) < p theta.
The parameter theta is simply a threshold. Say, for instance, that p = +1. If f(x) < theta, then h(x, f, p, theta) = +1, i.e., the weak classifier considers x a face.

What does 'zero of the function will be found within the precision limit ϵ = 10 - 3' mean in this?

Well, the question is; "Write a C code that finds zero of a function y = ax + b, without solving the equation. The zero will be found within the precision limit ϵ = 10 - 3. You'll start at x=0, and move x in the proper direction until |y|< ϵ."
I'm a newbie, to programming, and don't know anything about this ϵ thing either.
Help me out!!
It means you have to solve the inequality |ax+b| < 10^-3 by trying different values for x.
Since this is a linear function it's easy. Start with a random number at x and then increase it or decrease it depending on the result of ax+b. I.e. if you move to one direction and the results go more away then you should follow the opposite direction.
You will have to develop an algorithm that decides the increments/decrements of x.
|y| < 10⁻³, or well, -0.001 < y < 0.001.
You must increase or decrease x (starting from 0, as you've said) in order to make y to take a value between -0.001 and 0.001.
About ϵ, a.k.a. epsilon, is used to denote a very small value. For this problem, ϵ denotes a tolerance value, as it's not needed y to take a strict value of 0.

Resources