text:
# Debugging

Dealing with bugs is an unavoidable part of coding optimization models in any framework, including JuMP. Sources of bugs include not only generic coding errors (method errors, typos, off-by-one issues), but also semantic mistakes in the formulation of an optimization problem and the incorrect use of a solver.

This tutorial explains some common sources of bugs and modeling issues that you might encounter when writing models in JuMP, and it suggests a variety of strategies to deal with them.

Tip

This tutorial is more advanced than the other "Getting started" tutorials. It's in the "Getting started" section to give you an early preview of how to debug JuMP models. However, if you are new to JuMP, you may want to briefly skim the tutorial, and come back to it once you have written a few JuMP models.

julia> using JuMPjulia> import HiGHS

## Getting help

Debugging can be a frustrating part of modeling, particularly if you're new to optimization and programming. If you're stuck, join the community forum to search for answers to commonly asked questions.

Before asking a new question, make sure to read the post Make it easier to help you, which contains a number of tips on how to ask a good question.

Above all else, take time to simplify your code as much as possible. The fewer lines of code you can post that reproduces the same issue, the faster someone can answer your question.

## Debugging Julia code

Read the Debugging chapter in the book ThinkJulia.jl. It has a number of great tips and tricks for debugging Julia code.

## Solve failures

When a solver experiences an issue that prevents it from finding an optimal solution (or proving that one does not exist), JuMP may return one of a number of termination_statuses.

For example, if the solver found a solution, but experienced numerical imprecision, it may return a status such as ALMOST_OPTIMAL or ALMOST_LOCALLY_SOLVED indicating that the problem was solved to a relaxed set of tolerances. Alternatively, the solver may return a problematic status such as NUMERICAL_ERROR, SLOW_PROGRESS, or OTHER_ERROR, indicating that it could not find a solution to the problem.

Most solvers can experience numerical imprecision because they use floating-point arithmetic to perform operations such as addition, subtraction, and multiplication. These operations aren't exact, and small errors can accrue between the theoretical value and the value that the computer computes. For example:

julia> 0.1 * 3 == 0.3false
Tip

Read the Guidelines for numerical issues section of the Gurobi documentation, along with the Debugging numerical problems section of the YALMIP documentation.

### Common sources

Common sources of solve failures are:

• Very large numbers and very small numbers as problem coefficients. Exactly what "large" is depends on the solver and the problem, but in general, values above 1e6 or smaller than 1e-6 cause problems.
• Nonlinear problems with functions that are not defined in parts of their domain. For example, minimizing log(x) where x >= 0 is undefined when x = 0 (a common starting value).

### Strategies

Strategies to debug sources of solve failures include:

• Rescale variables in the problem and their associated coefficients to make the magnitudes of all coefficients in the 1e-4 to 1e4 range. For example, that might mean rescaling a variable from measuring distance in centimeters to kilometers.
• Try a different solver. Some solvers might be more robust than others for a particular problem.
• Read the documentation of your solver, and try settings that encourage numerical robustness.
• Set bounds or add constraints so that all nonlinear functions are defined across all of the feasible region. This particularly applies for functions like 1 / x and log(x) which are not defined for x = 0.

## Incorrect results

Sometimes, you might find that the solver returns an "optimal" solution that is incorrect according to the model you are trying to solve (perhaps the solution is suboptimal, or it doesn't satisfy some of the constraints).

Incorrect results can be hard to detect and debug, because the solver gives no hints that there is a problem. Indeed, the termination_status will likely be OPTIMAL and a solution will be available.

### Common sources

Common sources of incorrect results are:

• A modeling error, so that your JuMP model does not match the formulation you have on paper
• Not accounting for the tolerances that solvers use (for example, if x is binary, a value like x = 1.0000001 may still be considered feasible)
• A bug in JuMP or the solver.

The probability of the issue being a bug in JuMP or the solver is much smaller than a modeling error. When in doubt, first assume there is a bug in your code before assuming that there is a bug in JuMP.

### Strategies

Strategies to debug sources of incorrect results include:

• Print your JuMP model to see if it matches the formulation you have on paper. Look out for incorrect signs + instead of -, and off-by-one errors such as x[t] instead of x[t-1].
• Check that you are not using exact comparisons like value(x) == 1.0; always use isapprox(value(x), 1.0; atol = 1e-6) where you manually specify the comparison tolerance.
• Try a different solver. If one solver succeeds where another doesn't this is a sign that the problem is a numerical issue or a bug in the solver.

## Debugging an infeasible model

A model is infeasible if there is no primal solution that satisfies all of the constraints. In general, an infeasible model means one of two things:

• Your problem really has no feasible solution
• There is a mistake in your model.

### Example

A simple example of an infeasible model is:

julia> model = Model(HiGHS.Optimizer);julia> set_silent(model)julia> @variable(model, x >= 0)xjulia> @objective(model, Max, 2x + 1)2 x + 1julia> @constraint(model, con, 2x - 1 <= -2)con : 2 x ≤ -1.0

because the bound says that x >= 0, but we can rewrite the constraint to be x <= -1/2. When the problem is infeasible, JuMP may return one of a number of statuses. The most common is INFEASIBLE:

julia> optimize!(model)julia> termination_status(model)INFEASIBLE::TerminationStatusCode = 2

Depending on the solver, you may also receive INFEASIBLE_OR_UNBOUNDED or LOCALLY_INFEASIBLE.

A termination status of INFEASIBLE_OR_UNBOUNDED means that the solver could not prove if the solver was infeasible or unbounded, only that the model does not have a finite feasible optimal solution.

Nonlinear optimizers such as Ipopt may return the status LOCALLY_INFEASIBLE. This does not mean that the solver proved no feasible solution exists, only that it could not find one. If you know a primal feasible point, try providing it as a starting point using set_start_value and re-optimize.

### Common sources

Common sources of infeasibility are:

• Incorrect units, for example, using a lower bound of megawatts and an upper bound of kilowatts
• Using + instead of - in a constraint
• Off-by-one and related errors, for example, using x[t] instead of x[t-1] in part of a constraint
• Otherwise invalid mathematical formulations

### Strategies

Strategies to debug sources of infeasibility include:

• Iteratively comment out a constraint (or block of constraints) and re-solve the problem. When you find a constraint that makes the problem infeasible when added, check the constraint carefully for errors.
• If the problem is still infeasible with all constraints commented out, check all variable bounds. Do they use the right data?
• If you have a known feasible solution, use primal_feasibility_report to evaluate the constraints and check for violations. You'll probably find that you have a typo in one of the constraints.
• Try a different solver. Sometimes, solvers have bugs, and they can incorrectly report a problem as infeasible when it isn't. If you find such a case where one solver reports the problem is infeasible and another can find an optimal solution, please report it by opening an issue on the GitHub repository of the solver that reports infeasibility.
Tip

Some solvers also have specialized support for debugging sources of infeasibility via an irreducible infeasible subsystem. To see if your solver has support, try calling compute_conflict!:

julia> compute_conflict!(model)
ERROR: ArgumentError: The optimizer HiGHS.Optimizer does not support compute_conflict!

In this case, HiGHS does not support computing conflicts, but other solvers such as Gurobi and CPLEX do. If the solver does support computing conflicts, read Conflicts for more details.

### Penalty relaxation

Another strategy to debug sources of infeasibility is the relax_with_penalty! function.

The penalty relaxation modifies constraints of the form $f(x) \in S$ into $f(x) + y - z \in S$, where $y, z \ge 0$, and then it introduces a penalty term into the objective of $a \times (y + z)$ (if minimizing, else $-a$), where $a$ is a penalty.

julia> map = relax_with_penalty!(model)┌ Warning: Skipping PenaltyRelaxation for ConstraintIndex{MathOptInterface.VariableIndex,MathOptInterface.GreaterThan{Float64}}
└ @ MathOptInterface.Utilities ~/.julia/packages/MathOptInterface/NCblk/src/Utilities/penalty_relaxation.jl:289
Dict{ConstraintRef{Model, MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.LessThan{Float64}}, ScalarShape}, AffExpr} with 1 entry:
con : 2 x - _[2] ≤ -1.0 => _[2]

Here map is a dictionary which maps constraint indices to an affine expression representing $(y + z)$.

If we optimize the relaxed model, this time we get a feasible solution:

julia> optimize!(model)julia> termination_status(model)OPTIMAL::TerminationStatusCode = 1

Iterate over the contents of map to see which constraints are violated:

julia> for (con, penalty) in map
violation = value(penalty)
if violation > 0
println("Constraint $(name(con)) is violated by$violation")
end
endConstraint con is violated by 1.0

Once you find a violated constraint in the relaxed problem, take a look to see if there is a typo or other common mistake in that particular constraint.

Consult the docstring relax_with_penalty! for information on how to modify the penalty cost term a, either for every constraint in the model or a particular subset of the constraints.

When using relax_with_penalty!, you should be aware that:

## Debugging an unbounded model

A model is unbounded if there is no limit on how good the objective value can get. Most often, an unbounded model means that you have an error in your modeling, because all physical systems have limits. (You cannot make an infinite amount of profit.)

### Example

A simple example of an unbounded model is:

julia> model = Model(HiGHS.Optimizer);julia> set_silent(model)julia> @variable(model, x >= 0)xjulia> @objective(model, Max, 2x + 1)2 x + 1

because we can increase x without limit, and the objective value 2x + 1 gets better as x increases.

When the problem is unbounded, JuMP may return one of a number of statuses. The most common is DUAL_INFEASIBLE:

julia> optimize!(model)julia> termination_status(model)DUAL_INFEASIBLE::TerminationStatusCode = 3

Depending on the solver, you may also receive INFEASIBLE_OR_UNBOUNDED or an error code like NORM_LIMIT.

### Common sources

Common sources of unboundedness are:

• Using Max instead of Min
• Omitting variable bounds, such as 0 <= x <= 1
• Using + instead of - in a term of the objective function.

### Strategies

Strategies to debug sources of unboundedness include:

• Double check whether you intended Min or Max in the @objective line.
• Print the objective function with print(objective_function(model)) and verify that the value and sign of each coefficient is as you expect.
• Add large bounds to all variables that are free or have one-sided bounds, then re-solve the problem. Because all variables are now bounded, the problem will have a finite optimal solution. Look at the value of each variable in the optimal solution to see if it is at one of the new bounds. If it is, you either need to specify a better bound for that variable, or there might be a mistake in the objective function associated with that variable (for example, a + instead of a -).

If there are too many variables to add bounds to, or there are too many terms to examine by hand, another strategy is to create a new variable with a large upper bound (if maximizing, lower bound if minimizing) and a constraint that the variable must be less-than or equal to the expression of the objective function. For example:

julia> model = Model(HiGHS.Optimizer);julia> set_silent(model)julia> @variable(model, x >= 0)xjulia> # @objective(model, Max, 2x + 1)
@variable(model, objective <= 10_000)objectivejulia> @constraint(model, objective <= 2x + 1)-2 x + objective ≤ 1.0julia> @objective(model, Max, objective)objective

This new model has a finite optimal solution, so we can solve it and then look for variables with large positive or negative values in the optimal solution.

julia> optimize!(model)julia> for var in all_variables(model)
if var == objective
continue
end
if abs(value(var)) > 1e3
println("Variable \$(name(var)) may be unbounded")
end
endVariable x may be unbounded

Tip


text:
# Tag Info

Accepted

• 464

### Fair d5 with as few faces as possible

Surely will suffice for all n > 2. Consider a symmetrical cone with an n-sided regular polygon as its base. If we take a "stubby" one (of a shortish height) and a "pointy" one (...
• 71.5k
Accepted

### Wizard of subsets

Unless I'm missing something
• 2,440

### Wizard of subsets

Move those marked l to the left, then the rs right and then the us up.
• 16.3k

### Wizard of subsets

Very similar to @loopy-walt solution, but still OC :)
• 651
Accepted

### What's the most distant chess position?

This question was asked on Chess Stack Exchange a couple of years ago: Which chess position requires the most moves to reach? Just like @loopywalt here in the comments, I remembered Tim Krabbé's diary ...
• 27.3k

### What's the most distant chess position?

I will open the bidding at I won’t offer a series of moves, but describe the position as To see that this would take at least as many moves as claimed, note that In fact
• 2,440

### Most polyominoes in an 8x8 grid

If polyominoes of the same color can share an edge and polyominoes of different colors are considered distinct, the maximum is Under the intended interpretation (polyominoes of the same color cannot ...
• 10.2k

### Boxeslayers to the rescue

Here is one way to do it, showing the pattern along with its mirror image. The rectangular area is 83 x 24 units, or 1992 square units. And the two combined, to show that this is a safe stacking ...
• 11.3k

### Mixing liquids in bottles

Note a couple of lemmata. Also Now, Now From this point onwards Informally I suspect
• 2,440
Accepted

### Fair d5 with as few faces as possible

By "symmetric", I mean that there should exist symmetries of the polyhedron mapping each of the five stable faces to each other. Sets of independent symmetry elements The symmetry of a ...
Accepted

### Mixing liquids in bottles

I have no proof that this is the best possible. After the following steps Then you end up with the following in bottle 1: For comparison, I'll divide by $4$ litres to get the composition fractions.
• 47.3k

### How much money can we make?

Well I am a bit late to the party, but I did manage to find another solution that gives the same amount as the accepted answer: giving the final amounts: For the 7 person version of the problem my ...
• 28.9k

### Fair d5 with as few faces as possible

I think 6 sides would suffice. Make it fairly tall compared to the pentagon at the base, and "roll" it by spinning it like a top. If, by some miracle of fate, it manages to balance on the ...
• 131

### Mixing liquids in bottles

Nearest Attempt so far If we do the following steps Then you end up with the following in bottle 1 Of course, if we remove the last two steps from the procedure then bottle 1 contains the following
• 130k

### Boxeslayers to the rescue

(This is not an answer to the 183 problem asked here) High efficiency packing (arbitrary close to 100%) for far larger numbers of boxes
• 6,847
1 vote

### Attacking Hyenas

We can slightly rephrase this question as "For a given number of attacked hyenas, what is the maximum number of unattacked hyenas we can have?" Particularly, since hyenas can be divided into ...
• 6,932
1 vote

### Attacking Hyenas

The following presents the maximum number of unattacked hyenas alongside their corresponding ratio: and here is the representation of this; and here is a better representation with the right ...
• 29.6k

Only top scored, non community-wiki answers of a minimum length are eligible

format: plain


text:
### Home > PC > Chapter 7 > Lesson 7.1.1 > Problem7-13

7-13.

The sine does not need a horizontal shift.
The cosine needs to be shifted π to the left.

$\text{The sine needs to be shifted } \frac{\pi}{4} \text{ to the left.}$

The cosine needs to be flipped.


text:
# Line segment circle minimal vector before collision

• Let this problem be in 2D cartesian plane.
• Let 'Collision' of two objects be $$<=>$$ they are not touching and they have atleast one intersection point.
• Let $$C$$ be a circle with centre $$O$$ and radius $$R$$.
• Let $$L$$ be a line segment defined by two points, $$A$$, $$B$$.
• Let $$Vm$$ be vector defining the movement of $$C$$.

Suppose, that we move $$C$$ using vector Vm and on the path, the circle will collide $$L$$.

• Let Vc be vector.
• Let $$C'$$ be circle $$C$$ moved using $$Vc$$. (definition and explanation below)

I am tying to find $$Vc$$.

If we move $$C$$ by $$Vm$$ and on the movement path, and $$C$$ would collide $$L$$, then $$Vc$$ is vector such as $$C'$$ will touch L and length of $$Vc$$ $$\lt$$ $$Vm$$.

If $$C$$ during movement mentioned above would not collide $$L$$, then $$Vc=Vm$$

Illustration of the problem

On paper this can be solved by look and see, however, I am looking for idea on how to solve this algorithmically. Result will be used in computer code.

I solved most of cases by:

1. finding $$L2$$ orthogonal to $$L$$ such as $$O$$ lies on $$L2$$
2. calculating $$X$$ intersection point of $$L$$ and $$L2$$
3. calculating distance $$|XO|$$
4. subracting $$|XO|$$ from length of $$Vm$$ to get $$Vc$$ (reducing its length by $$|XO|$$)

This, however, does deal only with some cases of the problem. Not, for example, the first one displayed in illustration.

Thank you for any help

Node: I would like to avoid having for loop and checking for collision during all the movement steps

• Unfortunatelly, this is not going to work for all cases – Jan Glaser Dec 20 '18 at 1:31

So finally I am answering my own question after months of work. The entire problem is quite complicated, but worth solving, since the final collision handling is really worth it.

This explanation is copied here from my webpage, where the math solution is more detailed and supported with more images plus wolfram mathematica notebooks.

This describes how the collision between the objects in the game is being handled.

Circle - Line collision

If collision between circle and line segment (which is line limited on interval <a,b> is resolved, then, using line segment, other geometrical shapes can be created (such as triangle or polygon), and thus, the collision between them and circle is already solved.

Definitions
• Term line reffers to infinite line, not line segment
• Let $$C$$ be circle with centre $$C_s = (c_x, c_y)$$ that we want to move
• Let $$L_s$$ be Line Segment defined by 2 points, $$A, B$$. $$L$$ might collide circle $$C$$
• Let $$L$$ be Line defined also by 2 points, $$A, B$$
• Let $$v=(v_x, v_y)$$ be vector, defining the movement of the circle $$C$$
• Let $$v'$$ be the final movement vector (the result)
• $$L_s$$ touches $$C \Leftrightarrow C$$ and $$L_s$$ have exactly $$1$$ intersection point
• $$L_s$$ collides $$C \Leftrightarrow C$$ and $$L_s$$ have exactly $$2$$ intersection points
• Objective

Imagine, that being given movement vector $$v$$, the circle $$C$$ would collide $$L_s$$ during movement, if we move $$C$$ by $$v$$.

The objective is to determine vector $$v'$$ such as, when moving $$C$$ by vector $$v'$$, then $$C$$ will collide $$L_s$$ in exactly one point.

Mathematical solution

The problem is divided to 6 cases, all of them will be discussed below.

• If $$C$$ does not touch nor collides line $$L_s$$ before movement begins
• Case1: $$C$$ will collide $$L_s$$ during movement at one of points $$A$$ or $$B$$, where $$A$$, $$B$$ are points defining the line $$L_s$$ Case2: $$C$$ will collide $$L_s$$ during movement at point $$P$$. Let $$M$$ be, set of all points on line $$L_s$$. Then, for $$P$$ applies: $$P \in \{M\} / \{A, B\}$$ Case3: $$C$$ will not collide $$L_s$$ during movement at all
• If $$C$$ touches $$L_s$$ before movement begins
• Case4: $$C$$ will collide $$L_s$$ during movement Case5: $$C$$ will not collide $$L_s$$ during movement
Case6: $$C$$ collides $$L_s$$ before movement begins

Circle - Line segment intersection relationship

To solve all the cases, we need to first check for relation between $$C$$ and $$L$$ (do they collide each other? Or touch?)

Circle touches Line segment

For this, following statements apply:

• Let $$P$$ be set of all intersection points between $$C$$ and $$L$$. Applies $$|P| \in \{0,1,2\}$$
• If $$|P|=0$$, then $$C$$ does not touch $$L_s$$
• If $$|P|=1 \wedge P \in L$$, then $$C$$ touches $$L_s$$
• If $$|P|=2 \wedge P_x,P_y \in P: P_x = B \wedge P_y \notin L_s \wedge |A C_s| >= r$$, then $$C$$ touches $$L_s$$
• If $$|P|=2 \wedge P_x,P_y \in P: P_x = A \wedge P_y \notin L_s \wedge |B C_s| >= r$$, then $$C$$ touches $$L_s$$
• To explain the math above in plain words:

• If $$C$$ and $$L$$ have 0 intersection points, then they do not touch.
• If $$C$$ and $$L$$ have 1 intersection point, then they touch.
• If $$C$$ and $$L$$ have 2 intersection points:
• If one of the intersection points is $$A$$, and the other intersection point does not lie on the line segment $$L_s$$ and the B point lies outside the circle, then they touch
• If one of the intersection points is $$B$$, and the other intersection point does not lie on the line segment $$L_s$$ and the A point lies outside the circle, then they touch

Circle collides Line segment

For this, following statements apply:

• Let $$P$$ be set of all intersection points between $$C$$ and $$L$$. Applies $$|P| \in \{0,1,2\}$$
• If $$|P| \in \{0,1\}$$, then $$C$$ does not collide $$L_s$$
• If $$|P|=2 \wedge P_x,P_y \in P: P_x \in L_s \wedge P_y \in L_s$$, then $$C$$ collides $$L_s$$
• If $$|P|=2 \wedge P_x,P_y \in P: P_x = A \wedge |B C_s| >= r$$, then $$C$$ collides $$L_s$$
• If $$|P|=2 \wedge P_x,P_y \in P: P_x = B \wedge |A C_s| >= r$$, then $$C$$ collides $$L_s$$
• To explain the math above in plain words:

• If $$C$$ and $$L$$ have 0 r 1 intersection points, then they do not collide.
• If $$C$$ and $$L$$ have 2 intersection points:
• If both intersection points lie on $$L_s$$, then they collide
• If one of the intersection points is $$A$$, and the other intersection point does not lie on the line segment $$L_s$$ and the $$B$$ point lies inside or on the circle, then they collide
• If one of the intersection points is $$B$$, and the other intersection point does not lie on the line segment $$L_s$$ and the $$A$$ point lies inside or on the circle, then they collide

Case 1: $$C$$ will collide $$L_s$$ during movement at one of points $$A$$ or $$B$$, where $$A$$, $$B$$ are points defining the line $$L_s$$

To solve this, similar mathematical approach is used as in case2.
It is strongly recomended to read that first, and then come back here for better understanding...

By taking circle equation and line equation and combining them together, the point A (later also B) is plugged into the equations. If there is solution, and the final movement vector $$v$$ matches criteria (smaller than original movement vector, etc...for more details, read through case2), then the circle is considered to be colliding line segment at point A (or B, respectivelly).

Case 2: $$C$$ will collide $$L_s$$ during movement at point $$P$$. Let $$M$$ be, set of all points on line $$L_s$$. Then, for $$P$$ applies: $$P \in \{M\} / \{A, B\}$$

Let's reiterate, that $$L$$ is line, not a line segment. For simplicity, I will explain the solution on LINE, understanding that narrowing the solution down for line segment involves limitation on interval and adding few other edge cases to entire solution.

Let's start by having the equation of circle $$C$$:

$$(x-c_x)^2+(y-c_y)^2=r^2$$

Now, we perform translation of the centre by vector $$v$$:

$$(x-(c_x+v_x))^2+(y-(c_y+v_y))^2=r^2$$

However, we do not know how far to move the circle to get exactly one intersection point with $$L$$. Therefore, we use parameter $$t$$:

$$(x-(c_x+v_x*t))^2+(y-(c_y+v_y*t))^2=r^2$$
The equation above describes all circles, that are moved on the line defined by movement vector $$v'$$

Now, we will solve system of 2 equations:

$$(x-(c_x+v_x*t))^2+(y-(c_y+v_y*t))^2=r^2$$ $$a*x+b*y+c=0$$

Where the second equation is the equation of $$L$$ in general form

We express $$x$$ from the line equation (alternativelly, $$y$$ must be expressed in some cases to avoid diving by 0):

$$x=\frac{-b*y-c}{a}$$

That value is plugged into the circle equation to get:

$$(\frac{-b*y-c}{a}-(c_x+v_x*t))^2+(y-(c_y+v_y*t))^2=r^2$$

Now, considering $$t$$ as the polynom variable, if discriminant equals 0, then there is exactly one solution (circle collides line in one point only)

$$Discriminant[(\frac{-b*y-c}{a}-(c_x+v_x*t))^2+(y-(c_y+v_y*t))^2-r^2,y]=0$$

The discriminant is then:

$$D=-(\frac{1}{a^2})* 4 *(c^2 + 2 a c c_x + a^2 c_x^2 + 2 b c c_y + 2 a b c_x c_y + b^2 c_y^2 - a^2 r^2 - b^2 r^2 + 2 a c t v_x + 2 a^2 c_x t v_x + 2 a b c_y t v_x + a^2 t^2 v_x^2 + 2 b c t v_y + 2 a b c_x t v_y + 2 b^2 c_y t v_y + 2 a b t^2 v_x v_y + b^2 t^2 v_y^2)$$

Considering some input values for circle centre, movement vector, radius, etc., this would be more readable result:

$$D=-4(28-36*t+9t^2$$

The thing left is to compute the $$t$$, which is the movement vector multiplier.
Final solution vectors (if the solutions exist) will be:

$$v'_1 = (v_x * t_1, v_y * t_1)$$
$$v'_2 = (v_x * t_2, v_y * t_2)$$

Of course, the final vectors $$v'_1, v'_2$$ might not face in same direction as $$v'$$.
In that case, the solution is discarted.
Moreover, if $$|t_1| > 1 \lor |t_2| > 1)$$, then $$t_1$$, respectivelly $$t_2$$ is discarted.
That is because we require final vector to have same or smaller length then the original move vector

Case 3: $$C$$ will not collide $$L_s$$ during movement at all

If none of Case1 or Case2 holds and yields a solution, then the circle will not collide line segment at all during movement.

Case 4 and 5: $$C$$ touches $$L_s$$ before movement begins, and $$C$$ will (or not) collide $$L_s$$ during movement

For this one, imagine following figure:

• Let $$t$$ be tangent to $$C$$ in point $$P$$, which is touch point of $$C$$ and $$L_s$$ (in this example, $$P=A$$)
• Let $$u=|AE|$$, $$v=|AD|$$ be two movement vectors, where we position them to begin in touch point $$P=A$$
• $$u=|AE|$$ represents movement that would be allowed, whereas $$v=|AD|$$ represents movement that would NOT be allowed

In general case, imagining vector $$u=|AD|$$, then movement of $$C$$ using vector $$u$$ is valid $$\iff D$$ is on same side of line $$t$$ as centre of circle $$C$$ or $$D \in t$$

Case 6: $$C$$ collides $$L_s$$ before movement begins

Trivial case, when is done check for whether $$C$$ collides $$L_s$$, and if so, then no movement is done...

• You’ve clearly put a lot of thought and work into this, but the analysis seems a bit more complex than it needs to be. A collision will involve either an endpoint coinciding with the moving circle or the segment being tangent to the moving circle. Each of these possible events generates a quadratic equation in $t$. Solve them all and after a bit of culling, take the least $t\in[0,1]$. – amd Dec 20 '18 at 10:12
• I am not sure about the tangent idea still. Imagine Circle with centre (0,0), radius 2. Then Limited line defined by 2 points(0, -50) and (0, - 900). Movement vector would be (0, -8000). Now in this case, tangents to circle in direction of movement vector do not help. Moreover, (as this is case when it would collide at edge point of line segment), case when it would not involve edge points would be Circle at (0, 0), r=50, limited line defined by (-5, -10), (5, 10), move vector=(0, -9000). Here, tangents to circle wont help, and edge points of line segment are not involved – Jan Glaser Dec 20 '18 at 23:06
• Forget that old suggestion. I hadn’t read the question carefully. The interesting tangents to examine are ones parallel to the line segment. They’re the key to a relatively simple solution. – amd Dec 20 '18 at 23:42

You’ve clearly put a lot of thought and effort into this. I believe that there are far fewer cases to consider than you think, though.

I’m a bit lazy, so for problems like this one, I often find that it’s easier to overgenerate potential solutions and then winnow them down (cf. moving rectangle collision). In that spirit, let’s find all of the contacts between the line segment and a circle moving along the straight line defined by $$\mathbf v$$ regardless of when they occur. If we take $$\mathbf v$$ as defining a unit time step, as you’ve done, then we’re looking for the leading-edge contact that occurs first within the open time interval $$(0,1)$$, if any.

There are two types of contact of interest: when either endpoint lies on the moving circle and when the line segment is tangent to the moving circle. The times of all of these events are described by simple quadratic equations. To reduce clutter, assume that the center of the circle is at the origin at time $$t=0$$; you can always translate the points to make it so, and it doesn’t affect the solution. The position of the center of the circle can therefore be parameterized as $$C(t) = t\mathbf v$$. The point $$A$$ lies on the moving circle when $$\|A-C(t)\|=r$$ and similarly for $$B$$. The lesser of the solutions to this quadratic equation represents the leading-edge contact time. If this is $$\le0$$, discard the event (but see below).

The line through $$A$$ and $$B$$ is tangent to the circle when the distance between it and the center of the circle is equal to $$r$$. This can be expressed using a variation of the standard point-line distance formula: $$\left(\det\begin{bmatrix}A&B&C(t)\\1&1&1\end{bmatrix}\right)^2 = r^2\|A-B\|^2.$$ The determinant on the left-hand side can be derived using homogeneous coordinates: Let $$\mathbf a$$ and $$\mathbf b$$ be homogeneous coordinate vectors of the two points, which can be obtained by appending a $$1$$ to their Cartesian coordinates. The line through these points can be represented by the homogeneous vector $$\mathbf l=\mathbf a\times\mathbf b$$ (every point $$\mathbf p$$ on the line satisfies $$\mathbf l\cdot\mathbf p=0$$) and the distance of a point $$\mathbf p$$ to the line is given by $${|\mathbf l\cdot\mathbf P|\over\|l_1^2+L_2^2\|}$$. This overgenerates solutions, though, since we have a line segment instead of the entire line. For the line segment to be tangent, the endpoints can’t be on the same side of the perpendicular at the point of tangency. This perpendicular is the line (again in homogeneous vector representation) $$\mathbf m=[A-B; -(A-B)\cdot C(t)]$$ and the points $$A$$ and $$B$$ are on the same side of this line if the signs of $$\mathbf m\cdot\mathbf a$$ and $$\mathbf m\cdot\mathbf b$$ agree. Expanding the first of these dot products, we have $$\mathbf m\cdot\mathbf a = (A-B)\cdot A-(A-B)\cdot C(t) = (A-B)\cdot(A-C(t))$$ and similarly for $$B$$. Discard any of the up to two tangent contacts that don’t pass this filter.

Select the least nonnegative contact time less than $$1$$ among the surviving solutions to the above quadratics. If there is such a time $$t$$, then $$\mathbf v'=C(t)$$.

This approach requires computing three square roots, two of which might turn out to be irrelevant. That’s a relatively expensive operation, but we can improve the efficiency by noting that if there is a tangent contact with the leading edge of the circle, then neither of the segment endpoints can contact the leading edge sooner than that. So, solve for the tangent contact times first, and if the earlier one survives both filters, you’re done. Otherwise, proceed with computing the endpoint contacts.

I’ve assumed in the above that the segment and circle don’t already intersect at $$t=0$$. If you want to detect this as well, that’s pretty easy to do: if the lesser of any of the $$t$$ value pairs computed above are $$\le0$$, then the figures are potentially in contact at start. Examine the other $$t$$ value of the pair: if it’s $$ge0$$, this means that the trailing-edge contact has not yet occurred, so the figures currently overlap. Again, you’ll need to take a bit of extra care with the tangent contacts: both of the contacts must be real, per the criterion described earlier (most other cases in which only one contact is real are subsumed in endpoint overlaps, but take a careful look at $$t=0$$).

It’s possible to compute the contact points (and hence times) without directly solving the quadratic equations from above, but I don’t believe that doing so will be any more efficient. It might make the code a bit easier to understand, though, since those calculations are essentially geometric constructions with points and lines instead of complicated formulas that involve a pile of coordinates. It’s also relatively easy to work out the possible points of contact on the leading edge of the circle and then turn the problem into one of computing three segment-segment intersections, for which there are known efficient algorithms, but I’m not sure that doing so result in more efficient code, either.


text:
#### Vol. 10, No. 7, 2016

 Recent Issues
 The Journal About the Journal Editorial Board Subscriptions Editors' Interests Submission Guidelines Submission Form Editorial Login Ethics Statement ISSN: 1944-7833 (e-only) ISSN: 1937-0652 (print) Author Index To Appear Other MSP Journals
Arithmetic invariant theory and 2-descent for plane quartic curves

### Appendix: Tasho Kaletha

Vol. 10 (2016), No. 7, 1373–1413
##### Abstract

Given a smooth plane quartic curve $C$ over a field $k$ of characteristic 0, with Jacobian variety $J$, and a marked rational point $P\in C\left(k\right)$, we construct a reductive group $G$ and a $G$-variety $X$, together with an injection $J\left(k\right)∕2J\left(k\right)↪G\left(k\right)\setminus X\left(k\right)$. We do this using the Mumford theta group of the divisor $2\Theta$ of $J$, and a construction of Lurie which passes from Heisenberg groups to Lie algebras.

##### Keywords
arithmetic geometry, descent, invariant theory
Primary: 11D25
Secondary: 11E72


text:
Courses
Courses for Kids
Free study material
Free LIVE classes
More

# Concept of (Heat Capacity) CP and CV of Gas for JEE

## Introduction to Heat Capacity

Last updated date: 18th Mar 2023
Total views: 72.6k
Views today: 1.51k

Every time a body absorbs heat, the body's temperature rises as a result. The temperature also drops when heat is withdrawn. The temperature of an object can be used to calculate the total kinetic energy of the constituent parts that make up that object. As a result, when heat is absorbed by a substance, it is transformed into the kinetic energy of the particles, raising the substance's temperature. As a result, the relationship between temperature change and heat transmission is linear.

The body's temperature rises when heat is absorbed by it. Additionally, the temperature drops when heat is lost. The total kinetic energy of the particles that make up an object is measured by its temperature. In other words, when heat is absorbed by an object, it is converted into the kinetic energy of the particles, which raises the temperature. As a result, the relationship between temperature change and heat transmission is linear.

The specific heat capacity can be written mathematically as:

$Q=mc\Delta T$

where $Q=$ heat energy, m= mass, c= specific heat capacity, and $\Delta T$ is the change in temperature.

## Specific Heat of Gas

The amount of energy needed to increase the temperature of one unit mass (1 g) of gas by one-degree celsius at constant pressure is known as the specific heat of a gas.

## Definition of Molar Heat Capacity

The molar heat capacity (C) of a substance is the total amount of heat energy required to raise the temperature of 1 mole of that substance by 1 unit. The kind, quantity, and makeup of the substance in the system also have a big role.

$q=nC\Delta T$

where n is the amount in moles, and q is the amount of heat that is supplied or required to cause a change in temperature (T) in 1 mole of any given substance. The molar heat capacity of the given substance's body is represented by the constant C.

## What is CV?

The amount of heat energy that a substance absorbs or releases (per unit mass) in response to a change in temperature when no volumetric change occurs is known as CV. In other words, it is the quantity of thermal energy that is transmitted from one system to another without causing any changes to the system's volume.

The quantity of internal energy that a system has is described by this term. A system's total potential and kinetic energy make up its internal energy. A system's ability to absorb or release energy into the environment depends on the temperature of the system. It is known as the heat capacity at constant volume if this change in internal energy takes place while the volume stays constant (CV).

${{C}_{V}}=dU/dT$

where CV is the heat capacity at a constant volume (or a constant temperature) and dU is the change in internal energy. The temperature change is represented by the symbol dT.

## What is CP?

The sign CP stands for heat capacity at constant pressure. It is the amount of energy that a unit mass of a substance produces or absorbs when the substance's temperature varies while the pressure stays constant. In other words, it is the energy that is transferred when a system is continuously under pressure between the system and its surroundings.

This expression has to deal with the enthalpy of a certain system. An enthalpy is a unit of measurement for energy that is either received or released. It is described as the total internal energy plus a small amount of additional energy plus the product of pressure and volume. This is because the total amount of energy a system takes in or expels equals the sum of the energy it already possesses (internal energy) and the number of changes the system undergoes (PV). The enthalpy of the system will change as the system's temperature varies. The following can be provided as a consequence.

CP = $\frac{dH}{dT}$

where the temperature change is marked by the symbol dT, the enthalpy change is denoted by the symbol dH, and the heat capacity at constant pressure is given by the sign CP.

## Relationship Between CP and CV of an Ideal Gas

From the equation $q=nC\Delta T$, we can say

We have at constant pressure P

${{q}_{P}}=n{{C}_{P}}\Delta T$

This amount corresponds to the change in enthalpy, so

${{q}_{P}}=n{{C}_{P}}\Delta T=\Delta H$

Similarly, we have at constant volume V

${{q}_{V}}=n{{C}_{V}}\Delta T$

The change in internal energy is represented by this value, hence,

${{q}_{V}}=n{{C}_{V}}\Delta T=\Delta U$

For one mole (n=1) of an ideal gas, we are aware that

$\Delta H=\Delta U+\Delta (pV)=\Delta U+\Delta (RT)=\Delta U+R\Delta T$

Therefore, $\Delta H=\Delta U+R\Delta T$

Substituting the values of ∆H and ∆U from above in the former equation,

${{C}_{P}}\Delta T={{C}_{V}}\Delta T+R\Delta T$

CP =CV +R

CP – CV = R

## Heat Capacity Ratio

In thermodynamics, the heat capacity ratio or ratio of heat capacities (CP:CV) is also known as the adiabatic index. It is the ratio of two heat capacities, Cp and CV, and is given by:

The Heat Capacity at Constant Pressure (CP) / Heat capacity at Constant Volume(CV)

The heat capacity ratio is also known as the isentropic expansion factor that is also denoted for an ideal gas by $\gamma$ (gamma). Therefore, the ratio between CP and CV is the heat ratio, $\gamma$.

$\gamma =\frac{{{C}_{P}}}{{{C}_{V}}}$

Table: Gamma values for monoatomic, diatomic, and triatomic gases

 Gases Gamma Value Monoatomic 1.33 Diatomic 1.40 Triatomic 1.66

## Conclusion

The amount of heat needed to raise the temperature of a given quantity of a substance by one-degree Celsius is known as the substance's heat capacity. The thermodynamic characteristics of substances are specific heats. These characteristics give explanations for how a substance's or system's behaviour changes when the system's temperature changes. For ideal gases, the idea of specific heat holds valid, but when applied to real gases, it frequently needs to be changed. This is due to the fact that temperature and pressure often affect how gases behave.

Competitive Exams after 12th Science

## FAQs on Concept of (Heat Capacity) CP and CV of Gas for JEE

1. List the uses of specific heat.

Specific heat's practical use:

• Tiny-specific heat-capacity materials are excellent choices for cooking implements like pots, kettles, and frying pans because they quickly heat up when a small quantity of heat is applied.

• Specific heat is applicable when building oven lids, insulators, and kettle handlers due to the fact that a large amount of heat will only slightly alter the temperature.

• Water is used to put out fires. It absorbs a lot of heat because of its high specific heat without significantly raising its temperature.

• Oceans help to temper the climates by transferring heat away from equatorial regions.

2. Distinguish between molar heat capacity and specific heat capacity.

The primary distinction between specific heat and molar specific heat is that whereas the former refers to a substance's heat capacity at a given mass, the latter relates to a substance's heat capacity at a given number of molas. Additionally, whereas molar specific heat is independent of the substance's phase in the system, specific heat depends on it. Three variables affect a substance's specific heat: temperature change, Nature of the substance in the system, and the phase of the substance. The three following factors affect a substance's molar specific heat: the substance's nature, it's temperature, and the conditions in which heat is applied.


text:
# General

### User Name and Initials

 Citavi uses your name and initials exclusively for logging changes to projects, and for printing various lists. This helps you organize your work and is useful if you work in a team or share bibliographic information with others. The User name is used to identify the initials used throughout Citavi. Citavi automatically generates Initials from the first and last name of the user name. If you work in a team, make sure the initials are unique.

### Open Last Project when Citavi Starts (Skip Welcome Screen)

 Select this option to automatically reopen the last project you worked on when you start Citavi. The welcome screen is skipped.

### Generate Core Statements Automatically

 Select this option to automatically use the first few words of a new quotation as the core statement.

### TeX Support

 Select this option if you are using TeX and want to insert BibTeX keys and quotations into TeX documents using the Publication Assistant. After you have selected this option, click Customize to edit the template Citavi uses to generate BibTeX keys. For more information, see Creating a Publication with TeX.

### Citation Key Support

 Select this option to use citation keys in your publications. Citation keys are used in certain disciplines, such as chemistry or computer science. For example, the citation key "Kor06" might refer to the reference "Kornberg 2006". When you have selected this option, click Customize to change the template Citavi uses to generate citation keys.

### Reset Warnings

 Some Citavi warnings include an option to not show the warning again. Click Reset warnings to display all warnings again.

### Publication Assistant: Default Word Processor

 Select the word processing program that you want to use with Citavi. The Publication Assistant inserts references, quotations and thoughts directly into the active document in the selected program.

### Publication Assistant: Double-Click Refrence and Double-Click Knowledge Item

Select what the Publication Assistant does when you double click a reference or knowledge item. You can choose among:

 Option Result Copy Copies the placeholder and/or quotation with placeholder to the Clipboard Copy or insert with options Opens the option menu so that you can apply an option before copying or inserting a placeholder Insert in Microsoft Word (or other selected default word processor) Inserts the placeholder and/or quotation with placeholder in your word processor Insert in Microsoft Word as footnote (or in other selected default word processor) Inserts the placeholder and/or quotation with placeholder as a footnote in your word processor Show reference / Edit knowledge item Open the reference or knowledge item for editing

### Publication Assistant: Insert Sequence Number

 When formatting a publication, Citavi searches a document for placeholders (text in braces). If there is a sequence number within the braces (for example, #134) Citavi can positively identify the reference. If there is no sequence number, Citavi will attempt to identify the reference by author and year. This option should usually be turned on. You should turn off this option if you are working with multiple Citavi projects where the same references likely have different sequence numbers.

### When Using TeX Support: Cite Command

 The \cite command is used by LaTeX to insert a BibTeX citation. If necessary, you can enter multiple commands here for quick access in the Publication Assistant. For example, for the natbib package, enter: \citet; \citep; \citealt.

### When Using TeX Support: Quote Command

 The "quote" command is used by LaTeX to insert a quotation. Replace quote with quotation to indent the first line of the quotation. If the quotation is a poem, replace quote with verse to preserve line breaks. If necessary, you can enter multiple commands here for quick access in the Publication Assistant. Separate the commands with semicolons. quote; quotation; verse.

### When Using TeX Support: Line Break Command

 Configure how Citavi encodes line breaks when exporting TeX (for example, in longer quotations). Common commands are \newline and \par.

### When Using TeX Support: LaTeX Project Folder

 Select the folder where your LaTeX editor saves LaTeX projects. When you insert an image quoation from Citavi into your LaTeX editor, Citavi copies the image file to this folder.


text:
# What are examples of Kraus operators describing the process of control error?

Noise, such as photon loss or dephasing, is often described with Kraus operators.

Are there examples of Kraus operators describing the process of control error?

• what do you mean exactly with "the process of control error"?
– glS
Jun 20 at 9:23
• For example, in interferometer, the photon loss can be described by Kraus operators: $$K_{0}=\left(\begin{array}{cc} 0 & 0 \\ 0 & 0 \\ 0 & \sqrt{1-\eta} \end{array}\right), K_{1}=\left(\begin{array}{cc} 0 & 0 \\ 0 & 0 \\ \sqrt{1-\eta} & 0 \end{array}\right), K_{2}=\left(\begin{array}{cc} \sqrt{\eta} & 0 \\ 0 & \sqrt{\eta} \\ 0 & 0 \end{array}\right) .$$ But can control error, e.g. the phase in laser is not as expected or the measurement direction is not so precise and so on, also be described by Kraus operators? Jun 20 at 9:28
• so when you say "control error" you are referring to situations in which the parameters defining a setup are only known up to some error? I don't know specific examples, but just to note: Kraus operators are but a way to describe a quantum channel; if these "control errors" can be modeled with a quantum channel, then yes they can be described via Kraus operators
– glS
Jun 20 at 9:33

## Control errors

The term control error is generally used to refer to errors due to imperfections of the qubit control system. Hardware devices that control qubit evolution have a number of knobs that the control system sets to various values. In the process known as calibration we learn the settings of the knobs that correspond to each of the supported gates. Denoting by $$U(\theta)$$ the evolution resulting from setting the knobs to $$\theta$$ and with $$U_1, U_2, \dots, U_k$$ the supported gates, calibration aims to find $$\theta_1, \theta_2, \dots, \theta_k$$ such that

$$U_1 = U(\theta_1) \\ U_2 = U(\theta_2) \\ \dots \\ U_k = U(\theta_k).$$

We generally find the values $$\theta_i$$ by optimization, e.g. by maximizing the entanglement fidelity $$F_e$$. Optimization generally terminates when it finds a solution $$\tilde{\theta_i}$$ that is considered sufficiently good, e.g. when $$F_e(U(\theta_i), U(\tilde{\theta_i})) \ge 1-\epsilon$$ where $$\epsilon$$ is a tolerance setting. Consequently, we know the settings of the control knobs necessary to execute any particular gate up to some finite accuracy. Moreover, even if we knew $$\theta_i$$ exactly, the control knobs generally have finite precision, resulting for example from finite word-width of digital-to-analog converters.

The upshot is that whenever the qubit control system is asked to execute the gate $$U_i = U(\theta_i)$$, it actually executes the gate $$V_i=U(\tilde{\theta_i})$$. Thus, for the input state $$|\psi\rangle$$ we obtain $$V_i|\psi\rangle$$ instead of $$U_i|\psi\rangle$$. Notice that

$$V_i|\psi\rangle = V_iU_i^\dagger U_i|\psi\rangle = E_iU_i|\psi\rangle$$

where we defined the unitary control error $$E_i = V_iU_i^\dagger$$. Thus, we can think of the output state as resulting from the execution of the ideal gate $$U_i$$ followed by a unitary control error $$E_i$$.

## Kraus representation of control errors

The channel which applies a unitary operator $$U$$ has a simple Kraus representation

$$\rho \mapsto \mathcal{U}(\rho) = U\rho U^\dagger$$

where the unitary $$U$$ is the sole Kraus operator. Applying this to the unitary control error $$E_i = V_iU_i^\dagger$$ we get

$$\rho \mapsto \mathcal{E}_i(\rho) = E_i\rho E_i^\dagger = V_iU_i^\dagger\rho U_iV_i^\dagger.$$

## Simple example

Suppose we wish to execute $$S\equiv R_z \left(\frac{\pi}{2}\right)$$, where $$\equiv$$ denotes equality up to global phase, but due to control error end up actually executing $$S':=R_z \left(\frac{\pi}{2}\cdot (1 + 10^{-4})\right)$$ instead. The unitary control error is

$$E = S'S^\dagger = R_z \left(\frac{\pi}{2}\cdot 10^{-4}\right)$$

and its Kraus representation is

$$\rho \mapsto \mathcal{E}(\rho) = R_z \left(\frac{\pi}{2}\cdot 10^{-4}\right)\rho R_z \left(-\frac{\pi}{2}\cdot 10^{-4}\right).$$