text:
# Struct for angles

[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct AngleDeg
{
public readonly double Degrees; // immutable struct

public AngleDeg(double degrees = 0)
{
Degrees = degrees;
}

public override string ToString()
{
return $"{Degrees:F2}°"; } #region Conversion public static implicit operator AngleDeg(double rawAngleInDeg) { return new AngleDeg(rawAngleInDeg); } public static implicit operator double(AngleDeg v) { return v.Degrees; } // TODO: Implement arithmetic operations with operator overloads [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public AngleRad ToRadians() { // I could have used an explicit cast operator overload, but I think that a simple cast is not verbose/indicative enough. return new AngleRad(Degrees / 180.0 * System.Math.PI); } #endregion } [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)] public struct AngleRad { public readonly double Radians; // immutable struct public AngleRad(double radians = 0) { Radians = radians; } public override string ToString() { // I want the debugger to display angles in rounded degrees. Much easier to picture angles-in-degrees in my head return$"{Radians / System.Math.PI * 180:F2}°";
}

#region Conversion

{
}

public static implicit operator double(AngleRad v)
{
}

// TODO: Implement arithmetic operations with operator overloads

[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public AngleDeg ToDegrees()
{
// I could have used an explicit cast operator overload, but I think that a simple cast is not verbose/indicative enough.
return new AngleDeg(Radians / System.Math.PI * 180);
}

#endregion
}

We have tons of geometry related code in our codebase with lots of calculations including angles. We use double-precision floating point numbers to represent angles right now.

We usually measure angles in radians during the calculations, mainly because they all boil down to System.Math's static methods which expect angles to be in radians. However, it is a nuisance to debug such a code, because a double in the range of 0 and 2PI is nowhere near as informative as an angle in the range of 0 and 360°. Also when these angles displayed to a user, or a user has to type in an angle we always have to use degrees. A conversion must happen somewhere between the GUI-related layers and the maths calculation layers.

These are the pros I can think of:

• ToString() override always displays angle in degrees (great help for the debugger)
• Compile time checking of incommensurate angles on the boundaries of code using degrees and code using radians.
• Can write some handy utility methods, like ClampInRangeOf0And360Degrees().

Possible cons:

• Performance cost? Is there any?
• All codes using these structs will have a dependency on them. Using System.Double is maybe more 'reusable code'

The question is: What do you think of the possible drawbacks, pitfalls if we used these structs in a performance critical application? What about readability and code smell?

• Highly recommend not abbreviating AngleDeg and AngleRad. Are you really saving anything from doing this? Most people would just type AngleD and hit tab anyways, so AngleDegree/AngleRadian reads properly and doesn't change anything in that case. – Shelby115 Jun 6 '18 at 12:28
• This feels like over kill. I would have one Angle class with a double Value property and a Type enum for either Degrees or Radians. – Nkosi Jun 6 '18 at 13:00
• Rather than ToDegrees() and ToRadians() in each others' structs, why not have an implicit conversion to/from as you do with double? – Jesse C. Slicer Jun 6 '18 at 13:19
• in the range of 0 and 2PI [...] in the range of 0 and 360°Do you allow angles to be negative? – Raimund Krämer Jun 6 '18 at 13:34

IMO you should always use radians internally. Therefore a simple double should be appropriate as type for angle measurements. The only times you should want to convert to degrees, are in the UI. So you'll have to make functionality to convert between radians and degrees (for instance an extension method to double).

A good UI that displays angle measurements should let the user be able to set the format (choose between degrees and radians), because in some situations it is in fact more convenient to view angles in radians. The UI should be able to handle angle input in both degrees and radians according to a general setting.

So, although your structs seem well designed (an immutable struct is a good choice) they are in my opinion more or less redundant and may cause confusion among the developers about what to choose.

When it comes to debugging, you could maybe benefit from the possibilities to customize the display by using the DebuggerDisplayAttribute

• I would however argue that reading code like Angle toWaypoint is more clean/descriptive than double angleToWaypoint, but agree that having two structs might be confusing. – D. Ben Knoble Jun 6 '18 at 14:07
• @D.BenKnoble: You may have a point. But you can use the same argument on length and other measurements: Length lengthToPoint and then it could be a mess IMO. – Henrik Hansen Jun 6 '18 at 15:15
• Fair point Henrik – D. Ben Knoble Jun 6 '18 at 15:15
• You could always just override ToString for the debugger as well. – Shelby115 Jun 6 '18 at 18:36

AngleRad class solves your problem, by displaying radians as degrees in debugger. But what problem is solved by AngleDeg class? I don't see any benifits:

• It makes things more complicated, because now you have two similar classes with very similar names. Easy to confuse them.
• Implicit conversion from double amplifies this confusion. AngleDeg angle = Math.Atan(...) - this is now a valid code. I strongly recommend against such implicit conversion.
• Converting back and forth between two representations slowly builds up a round-off error, that otherwise can be avoided (by making all your calculations using radians).

So bottom line is: I would drop the first class and keep the second one.

P.S. How it would affect performance is something you have to measure on your own. Run a profiler, or write a benchmark that models your calculations. The cost of implicit casting is negligible in most cases, but it can be noticeable if your app, say, multiplies angles 24/7. In that case this cost quickly adds up.

• Agree with implicit conversion. Would suggest there be static methods named FromDegrees and FromRadians, though FromRadians is same as doing new instance. This would be similar to a TimeSpan.FromMinutes. – Rick Davin Jun 6 '18 at 17:44

I agree with other comments on the two classes have overlap.

You perform conversion in the ToString() and ToDegrees(). Reference the ToDegrees(). Actually I would just make Degrees a property.

I think one struct Angle with properties Radians and Degrees would be better.

The question is: What do you think of the possible drawbacks, pitfalls if we used these structs in a performance critical application?

Interpolated strings ($"{variable}...") are the antithesis of performance -- potentially worse than using StringBuilder for a similar construct. Each time the string is interpolated at runtime: a new compile time generated class is instantiated; a closure is created; the operations you expect are performed; and the closure and class instance are cleaned up. If your displaying a single value, this is negligible. If your displaying 1,000s of values (such as for UI display or reporting), this will begin take a hit on the CPU and memory pool. Consider just concatenating the double.ToString output with the degrees symbol. The default ToString method makes assumptions about the display format. Consider adding an overload taking a string format parameter and passing it to the double.ToString call. • You mentioned performance and interpolated strings ($"{variable}...") are the antithesis of performance where did you get this from? OP doesn't mention that :-| – t3chb0t Jun 7 '18 at 6:19
• I think OP is concerned with the performance of actual calculations. ToString method takes no part in those and is unlikely to become a bottleneck. So, personally, in this case I would go for "prettier" code. – Nikita B Jun 7 '18 at 7:29
• Why do you think that Interpolated strings ($"{variable}...") are the antithesis of performance -- potentially worse than using StringBuilder for a similar construct - do you have any proof for that? They are just a syntactic sugar. The compiler will generate the same code as if you used string.Format and if you are not doing this in a loop there will hardly be any difference noticable. – t3chb0t Jun 7 '18 at 15:43 • @t3chb0t Upon re-reading the documentation, I had overthought the FormattableString and IFormattable implicit conversions. My understanding was that an IFormattable implementation was always generated and run. I have confirmed your statements and am striking my performance claims. – psaxton Jun 7 '18 at 17:14 UPDATE I've gotten several downvotes with no comments for improvement. I think I gave sound advice that it is overkill for LayoutKind.Sequential and AggressiveInlining. I think it's good advice to have a Normalize method - as requested by the OP - which is a better name than ClampInRangeOf0To360Degrees. I also think its good advice that the ToString methods could be more flexible to allow for a varying number of decimal digits. If I am wrong on these points, please educate me. I am going to assume the silent downvotes were from the code. I have modified the code. The previous constant factors have been made static methods. I trust readers understand that my code is offered as an example of possibilities the OP can explore. I have nothing to add to Henrik Hansen and Nikita B's answers. I agree with them. I think you have way too much overkill and premature optimization with InteropServices.LayoutKind.Sequential or AggressiveInlining. No reason for LayoutKind if there is really only 1 value object in the struct. String methods will be slower than purely numeric methods. I find your structs rigid in that they fix the decimals at 2. I offer an alternative to demonstrate Henrik's and Nikita's answers: public struct Angle { // You don't have to make this private. // It's offered merely as an alternative to always // force someone to use FromRadians or FromDegrees. private Angle(double radians) { Radians = Normalize(radians); } public double Radians { get; } public double Degrees => RadiansToDegrees(Radians); public double Gradians => RadiansToGradians(Radians); private static double Normalize(double radians) => radians % TwoPI; public const double TwoPI = 2 * Math.PI; public static double RadiansToDegrees(double radians) => radians * 180 / Math.PI; public static double RadiansToGradians(double radians) => radians * 200 / Math.PI; public static double DegreesToRadians(double degrees) => degrees * Math.PI / 180; public static double GradiansToRadians(double gradians) => gradians * Math.PI / 200; public static Angle FromRadians(double radians) => new Angle(radians); public static Angle FromDegrees(double degrees) => new Angle(DegreesToRadians(degrees)); public static Angle FromGradians(double gradians) => new Angle(GradiansToRadians(gradians)); public override string ToString() => RadiansAsString(); public string ToString(int decimals) => RadiansAsString(decimals); public string RadiansAsString(int decimals = 2) =>$"{Radians.ToString($"F{decimals}")} rad"; public string DegreesAsString(int decimals = 2) =>$"{Degrees.ToString($"F{decimals}")}°"; public string GradiansAsString(int decimals = 2) =>$"{Gradians.ToString($"F{decimals}")} g"; }  You only need 1 struct and it should have a simple name: Angle. I have constants defined to replace the need for aggressive inlining. Since you mentioned the need to normalize between 0-360 degrees, I have a Normalize method. I intentionally use a private constructor so that I force others to use FromRadians, FromDegrees, or even FromGradians. The private constructor is purely optional. The implicit operators are gone. They really can lead to hard-to-find bugs since what double did you want to implicitly convert: radians or degrees? Your code will be more understandable by clearly stating the purpose that its FromDegrees versus FromRadians. To put it another way, let's say I have a variable named "myDegrees" despite the fact that I hate prefacing variable named with "my". This code would be easy to gloss over: var angle = new Angle(myDegrees); // if constructor was public  But this code should catch your eye that there is an issue: var angle = Angle.FromRadians(myDegrees);  Because there is clear conflict with the names. My string methods allow for a varying number of decimal digits to be displayed. There is no error checking and stuff like that in my code. # If you only input and output with degrees Then you may still have one structure where all internal calculations are based on radians but the inputs and ToString outputs are in your preference of degrees. This also means you could keep an implicit cast from double degrees to Angle. That code could look something like: public struct Angle { // Prefer input as degrees private Angle(double degrees) { Radians = Normalize(DegreesToRadians(degrees)); } public double Radians { get; } public double Degrees => RadiansToDegrees(Radians); public double Gradians => RadiansToGradians(Radians); private static double Normalize(double radians) => radians % TwoPI; public const double TwoPI = 2 * Math.PI; public static double RadiansToDegrees(double radians) => radians * 180 / Math.PI; public static double RadiansToGradians(double radians) => radians * 200 / Math.PI; public static double DegreesToRadians(double degrees) => degrees * Math.PI / 180; public static double GradiansToRadians(double gradians) => gradians * Math.PI / 200; public static Angle FromRadians(double radians) => new Angle(radians); public static Angle FromDegrees(double degrees) => new Angle(DegreesToRadians(degrees)); public static Angle FromGradians(double gradians) => new Angle(GradiansToRadians(gradians)); // Prefer output as degrees public override string ToString() => DegreesAsString(); public string ToString(int decimals) => DegreesAsString(decimals); public string RadiansAsString(int decimals = 2) =>$"{Radians.ToString($"F{decimals}")} rad"; public string DegreesAsString(int decimals = 2) =>$"{Degrees.ToString($"F{decimals}")}°"; public string GradiansAsString(int decimals = 2) =>$"{Gradians.ToString(\$"F{decimals}")} g";

// Prefer implicit input of degrees
public static implicit operator Angle(double degrees) => Angle.FromDegrees(degrees);

// but internal operations are on radians
}

The math operators offer the benefit of creating a new, immutable Angle, which also means the Normalize method is applied with each math operation.

• How come the Radians property is private? – Pod Jun 8 '18 at 9:14
• @Pod. That would be a typo. Fixed. Thx. – Rick Davin Jun 8 '18 at 11:13
• I'd written a comment but it was removed... and at that time I didn't vote at all so the first DV wasn't mine (but the second one is). I said that I didn't like calling the code an alternative which it isn't because it just implements suggestions from two different answers. If you could make it clear which part of the review is new and which one just shows an example implementation of the already mentioned improvements I'll gladly upvote the answer. – t3chb0t Jun 9 '18 at 9:40
• @t3chb0t Thanks for feedback. The mention of it being an alternative was in reference to the OP's code, not to other answers. I disagree that it "just implements" two other answers, since it also implements points that I was first to mention. Those are summarized in the updated first paragraph. – Rick Davin Jun 9 '18 at 12:48

format: plain


text:
# Pull-up vs Pull-down on enable pin

I am examining a schematic which concerns the TPS61030 boost converter IC and I have a question regarding the logic behind pulling the enable pin (EN). The schematic is from Adafruit and can be found here: https://learn.adafruit.com/adafruit-powerboost-1000-basic/downloads#schematics

General information:
The TPS61030 boost converter (datasheet) utilizes a signal on its EN pin to turn the converter on or off. If the EN pin is set to 0VDC, the converter is put into shutdown mode which effectively isolates the load from the input. When the EN pin receives an input >= 1VDC (but less than the 7VDC maximum), the device is put into operation mode and starts to function.

The circuit is designed for a 3.7VDC (nominal) LiPo battery. Under ideal conditions, the circuit boosts the 3.7VDC from the battery to ~5.2VDC required by many devices. I believe the +0.2VDC is meant to compensate for low-grade wires.

In their diagram, Adafruit pulls the EN pin high and uses a switch to GND to turn the device off. The schematic resembles the following:

simulate this circuit – Schematic created using CircuitLab

When the switch is open, the converter will enter operate mode. When the switch is closed, the device converter will enter shutdown mode; however, the circuit will become a parasitic drain on the battery. It seems odd to me that the circuit was designed to draw current when the converter, and by extension the device being powered, is meant to be off. I know it will only be ~0.02mA but I do not understand why they wouldn't pull the pin low and use a high side switch instead such as in the following schematic:

simulate this circuit

The above circuit will form a voltage divider which will output ~2.4VDC to the EN pin which is more than enough to enable the device. When the switch is open, the EN pin will be pulled to GND and the converter will enter shutdown mode. This would eliminate the parasitic drain when the converter is in shutdown mode.

Questions
Why they are pulling the pin high instead of low to eliminate the parasitic drain? I am a novice in electronics so I assume Adafruit has a good reason for doing so and I'm just too inexperienced to understand why. Any input would be greatly appreciated!

• Because the EN pin is internally pulled up inside the chip? It's not specified in the datasheet, but it is common for that to be the case. – Majenko Aug 24 '16 at 23:01
• Also it is more common to want the device running than not, so why not have that the default? – Majenko Aug 24 '16 at 23:03
• @Majenko Thanks for the response. In my application, the device will be off for relatively long periods of time, sometimes for a few weeks before being turned back on. – John P. Aug 24 '16 at 23:10
• My guess is that Adafruit wants people who bought the module and connected a power input for it to just work. Think about the hassle of technical support to people who didn't realize to short out or connect a switch to EN if done the other way. (And 20uA is not much current although not negligible for an 1Ah battery for example.) By the way, the best way to minimize the power-off power is to put the switch between the battery and the module. That eliminates any current that the circuit might drawn when in shutdown mode. – rioraxe Aug 24 '16 at 23:40
• @rioraxe Great point, I didn't even think about that aspect of it. – John P. Aug 25 '16 at 1:38

Possible reasons: part count, reliability, lack of concerned about that that level of leakage, avoiding complexity, default-on behavior for user convenience (from rioraxe in the question's comments).

To expand on leakage current being of little concern: check the specification of the TPS61030: 20uA (typ). Then 1uA (max) in shutdown. What will another 20uA of leakage through the pull-up do? Expanding on laptop2d's calculations: 21uA leakage from a 1000mAh battery gives 47,600 hours of "standby" time (discounting battery self-discharge). Over 5.5 years! The self-discharge of the attached secondary cell and the usage of the device are certainly of greater power-loss concern than shutdown leakage! Leaving shutdown then trades pull-up current for the converter's quiescent current.

Thus, the expected use of this board is not greatly concerned about leakage currents in comparison to the 100 to 1000+ mA loads the battery will see in normal operation (e.g. phone charging, running an rPi).

If you were using this for something other than a USB power bank, you might be concerned about battery life. However, long-lifetime battery operated devices usually don't come equipped with 4A-switch boost converters.

Note: the proposed 200k pull-up and 400k pull-down with switch circuit would not work. From the datasheet, The device is put into operation when EN is set high. It is put into a shutdown mode when EN is set to GND. This looks to be a normal logic input, so it is intended to be driven close to the rails. It is not a comparator input like the LBO pin or certain other regulators that have precision-threshold enable inputs.

• Additionally: don't necessarily expect that Adafruit (or any "maker" branded vendor) has the best reason behind their design decisions. For personal example, I noticed that the Adafruit TMP006 breakout does not (ca. 2014) follow TI's recommended layout, which could affect its accuracy. – user2943160 Aug 24 '16 at 23:17
• Thank you for the informative answer. Like I was telling laptop2d, my battery is a 10.2Ah LiPo pack. I'm honestly not concerned with the draw itself, the battery will most likely stop working from age before the current drains it. The purpose of my question is to understand the logic of choosing one circuit over the other. My co-worker said it may be to save money on the second resistor but I assumed it was more complex than that. – John P. Aug 24 '16 at 23:24
• I was just going with the nominal value that laptop2d used to have our calculations be easy to compare. I'll update my answer a bit. – user2943160 Aug 24 '16 at 23:43
• Thanks for the added information. I was confusing two datasheets I'm working with. Converter TPS61230 implies the EN pin can be triggered at 1.2VDC whereas this converter specifies 0.8 x VCC. If I modify the R1 value to be 100k and R2 to be 600k, I can get above 0.8 x VCC which I assume will enable it. – John P. Aug 25 '16 at 1:36
• Maybe, but making the node too high impedance could also make it sensitive to coupled noise. If anything, considering a multiple-resistor for the enable divider is an over-optimization of the design. – user2943160 Aug 25 '16 at 1:43

Will it become a parasitic drain? Depends on the definition of parasitic. The answer is read the datasheet again and again, if you don't understand something look it up.

From the datasheet: Shutdown current VEN= 0 V, VBAT = 2.4 V Current of enable pin = 0.1 to 1 μA

1uA of current from a 1000mA*H battery will last you 1e6 hours, I hope thats enough for you. And the pin varies from part to part or is dependent on the voltage so it could even be lower than 1uA. Thats why we love FET's

A bigger worry than the enable pin is the part itself, it has 25uA of Quiescent current. That's only ~38k hours on the same 1000mA*H battery.

A better way to handle this in your schematic is have your entire device switched from the battery if possible and tie the enable to Vbat.

• Thanks for the response. In the first diagram, the switch being closed turns the device off. This makes current flow through R1 to ground. Ignoring the small current draw of the EN pin completely, the small current through R1 will draw current from the battery. I'm not exactly concerned with the drain itself, I'm using a 10.2Ah battery. I'm concerned with the logic of choosing one circuit over the other. A co-worker said it may be to save money by using one resistor instead of two. For the purposes of learning, let's assume I cannot switch the entire part. – John P. Aug 24 '16 at 23:19
• Actually looking at this again, they are using it as a pull-down and the resistor is simply a load resistance so as not to have a dead-short.

Disregard: So this may not be the entire concept, as I haven't had a chance to look at the datasheet in detail, but you've pretty much addressed it with your insight about the voltage divider acting in the same way.

You could use this 400ohm resistor as a current limiting resistor, but the voltage drop is undesirable and this may change the "loading" of this pin when the switch is closed. Given that this is looking at a voltage, I'll assume it's a very high impedance so this would prob be negligible, but it should be noted that this will add resistance to ground which can cause looping issues.

The job of a pull-up is to ensure that the voltage level is correct when switched, this seemingly being an "active low" you want to make sure that it stops in good time, so pull-up, flip the logic and you may need a pull-down. In both of your configurations the resistors are acting as pull-ups, just one is a stiff voltage divider which can introduce a ground differential.


text:
## Precalculus (6th Edition) Blitzer

a. $\frac{x^2}{2304}+\frac{y^2}{529}=1, y\geq0$ b. $42\ ft$.
a. Using the figure given in the exercise, we have $a=48, b=23$ and the equation of the archway can be written as $\frac{x^2}{48^2}+\frac{y^2}{23^2}=1$ or $\frac{x^2}{2304}+\frac{y^2}{529}=1, y\geq0$ b. Using the above results, we have $c=\sqrt {a^2-b^2}=\sqrt {1775}\approx42\ ft$. Thus he should place his desk about 42 feet from the center.


text:
# Random walk - probability of first pass through zero.

In the proof that symmetric random walks end up regressing to the origin with probability $1$, I have found this didactic post on-line, where the power series of the probability mass function of the first pass through zero is expressed in closed form, and evaluated at $x=1$:

Manipulating $F(x)$ gives us more insights. First, setting $x= 1$ we see that

$\large F(1)=\displaystyle \sum_{n=1}^\infty f_n= 1 - \sqrt{1-4pq}=1-\color{red}{|p-q|}$

The sum of all the $f_n$ is simply the probability that the random walk ever returns to the origin. Thus, with probability $|p-q|$, the walk will never return to the origin.

The question is, where does $|p-q|$ come from? And why is $x$ actualized to $1$, when the $x$ "variable" in generating functions is often compared to just a clothesline to aid in counting?

• Since $p+q=1$ therefore $\sqrt{1-4p}=\sqrt{(p+q)^2-4pq}=\sqrt{p^2+q^2-2pq}=\sqrt{|p-q|^2}=|p-q|$. Apr 5 '20 at 12:01

For the first question, since $p+q=1$ it follows that $$(p-q)^2=p^2-2pq+q^2=p(1-q)-2pq+q(1-p)=p+q-4pq=1-4pq$$ Therefore taking a square root yields $\sqrt{1-4pq}=|p-q|$.
For the second question, while generating functions can be regarded as formal power series, they can also be viewed as defining an analytic function in some neighborhood of zero. There is then no problem with evaluating the function in this neighborhood. A probability generating function for a random variable $X$ taking values in $\mathbb{N}\cup\{0,\infty\}$ will always converge at $x=1$ because the sum is just $\mathbb{P}(X<\infty)$.


text:
# Using align* and array together to show relationship between matrix and system

I am trying to align an entire matrix with a system of equations with an arrow between them. Here is what I have so far,

\begin{align*}
\left[\begin{array}{ccc|c}
1 & 0 & 0 & \redtt{b1}  \\
0 & 1 & 1 & \redtt{b2}  \\
0 & 0 & 1 & \redtt{b3}
\end{array}\right] \longrightarrow && \\
&& x &= \redtt{b1} \\
&& y + z &= \redtt{b2} \\
&& z &= \redtt{b3}
\end{align*}

and it is producing the image below. I would like it to be all inline with itself. Any help would be greatly appreciated. \redtt is just a shortcut I made. It is equivalent to \newcommand{\redtt}[1]{\textcolor{red}{\texttt{#1}}}

• Will there be more than one "block" in vertical alignment? If not, it would be better to use $...$ or equation* (or forget the * if you would like this numbered. – barbara beeton May 29 at 20:03

Please consider posting complete examples such that others do not have to reverse engineer commands like \redtt. As for your question, you can use aligned or an array.

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage{xcolor}
\newcommand{\redtt}[1]{\textcolor{red}{\mathtt{#1}}}
\begin{document}
\begin{align*}
\left[\begin{array}{ccc|c}
1 & 0 & 0 & \redtt{b1}  \\
0 & 1 & 1 & \redtt{b2}  \\
0 & 0 & 1 & \redtt{b3}
x &= \redtt{b1} \\
y + z &= \redtt{b2} \\
z &= \redtt{b3}\\
\end{aligned} \\
\end{align*}

\begin{align*}
\left[\begin{array}{ccc|c}
1 & 0 & 0 & \redtt{b1}  \\
0 & 1 & 1 & \redtt{b2}  \\
0 & 0 & 1 & \redtt{b3}
x &= \redtt{b1} \\
y + z &= \redtt{b2} \\
z &= \redtt{b3}
\end{array} \\
\end{align*}
\end{document}

IMHO aligned looks better but in the array you maintain the same spacing between the rows as in the matrix. (Of course one can adjust aligned to give the same spacing, and so on.)

ADDENDUM: As barbara beeton points out, if you only have a one-line equation it is more appropriate to use $...$.

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage{xcolor}
\newcommand{\redtt}[1]{\textcolor{red}{\mathtt{#1}}}
\begin{document}
\left[\begin{array}{ccc|c} 1 & 0 & 0 & \redtt{b1} \\ 0 & 1 & 1 & \redtt{b2} \\ 0 & 0 & 1 & \redtt{b3} \end{array}\right]\quad \longrightarrow\quad \begin{aligned} x &= \redtt{b1} \\ y + z &= \redtt{b2} \\ z &= \redtt{b3}\\ \end{aligned}
or
$\left[\begin{array}{ccc|c} 1 & 0 & 0 & \redtt{b1} \\ 0 & 1 & 1 & \redtt{b2} \\ 0 & 0 & 1 & \redtt{b3} \end{array}\right]\quad \longrightarrow\quad \begin{array}{@{}r<{{}}@{}>{{}}l@{}} x &= \redtt{b1} \\ y + z &= \redtt{b2} \\ z &= \redtt{b3} \end{array}$
\end{document}

• Thank you! I didn't even think to use aligned. I was trying to nest another align* in there but it didn't like that of course. – Buddy Kings Galletti May 29 at 15:37
• See my comment on the question regarding use of align for "one-line" displays. – barbara beeton May 29 at 20:05
• @barbarabeeton Yes, this is a good point. – user194703 May 29 at 20:15

I'd simply use a single column array (and avoid pure colors):

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}

\newcommand{\redtt}[1]{\textcolor{red!90!blue}{\mathtt{#1}}}

\begin{document}

$\left[\begin{array}{@{}ccc|c@{}} 1 & 0 & 0 & \redtt{b1} \\ 0 & 1 & 1 & \redtt{b2} \\ 0 & 0 & 1 & \redtt{b3} \end{array}\right] \;\longrightarrow\; \begin{array}{@{}r@{}} x = \redtt{b1} \\ y + z = \redtt{b2} \\ z = \redtt{b3} \end{array}$

\end{document}


text:
• entries
146
436
• views
198064

# Singletonitis, Part 3

298 views

Quote:
 Original post by stormrunnerI realize this may be ignorant, but I just have to ask - what would be a case for a singleton ? You have - in brutal fashion - destroyed the basis for almost all uses of the singleton pattern as it relates to game developement. The last bastion of defence, per se, lies in it's easy applicability for memory management or messaging schemes. But even that just seems like lazyness (i.e. Enginuity, signals and slots) ... so is the singleton applicable in any type of gamedev related task ?

Could it be? Do my eyes deceive me? Or did someone actually get the point of my post? I'll answer your question in a bit stormrunner, but first...

Quote:
 Original post by _the_phantom_@stormrunnerthe only case for a singleton i can think of is a logging system, where it could be argued that you do need only one and global access to log from anywhere.I now await Washu to shoot that arguement down

I am of two opinions to that idea. The first is: KEEL Phantom. However, the second is much more interesting.
[Edit: Over the months/years I've looked back at this and contemplated fixing this. Frankly, I don't use singletons for logging, as it's not a flexible solution that can be easily removed when porting code. There are far cleaner solutions that I would suggest implementing, but I won't cover them here.]
You wish to log events, such events might be informational, warnings, errors, and debugging information. How can we accomplish such? The first, and obvious choice would be to make a logging singleton with a function that would take a state flag...something like: Write(LL_DEBUG, StringBuilder("2 + 2 = {0}") % result);. This seems like a fairly reasonable approach, and would be perfectly acceptable for an entry level logging system. But, lets make our functional requirements a bit more complex. First, we would like the ability to direct the logging system to multiple streams. You should be able to indicate the logging level for each stream. The levels are arranged in a hierarchical structure, like so:

• Debugging

• Informational

• Warnings

• Errors

So, if you select the Warnings level, your stream will receive Warnings and Errors, nothing else. Obviously, if you select the Debugging level then you are going to receive everything. So, here's the question, is the new design still suitable for a singleton? We'll, actually, yes. Does it have to be? No, but in this case I would consider it an appropriate use of the singleton pattern. Quite simply, you will most likely be accessing the logging singleton all over the code. And refactoring it out is not an option.

Another possible singleton would a concrete factory that you expose from a DLL via an interface (as shown in the UML diagram below). In this way the actual implementation details of the classes would be hidden from the client. This would also enable you to control the number of times that the factory allows the provided interfaces to be instantiated. In this way you can achieve your goal of guaranteeing only single instantiation of various types (Graphics object, Input object), but when you need to allow for multiple instantiation, you aren't bound to a singleton object, instead you just use the factory interface to obtain another pointer.

That should also answer Etherstar's question.

I am now seriously considering creating a concrete factory now for my current game. I'd get the encapsulation I'm looking for with the scalability for the future. Not to mention it looks a heck of a lot cleaner with a single interface.

##### Link to comment
I agree with most of your points, but I wonder at what state does a concrete factory become ...a singleton wrapper? You have a few abstract classes / interfaces, and you are ensuring that only one instance is created of each...and you have one global ConcreteFactory? But now wouldn't you have to be making function calls all over your code for ConcreteFactory::, and therefore you run into the same issue you had when you were creating a singleton in the first place, do you not?

If you ask me, passing pointers "downstream" is the best way to go...

I have really enjoyed the last couple of posts, though! Well written!

##### Link to comment
Your code doesn't call the concrete factory like that. It uses the interface to the factory that is provided.
IFactory *f = GetFactory();
IGraphicsManager* graphics = f->CreateGraphicsManager();

Hence your code doesn't actually know that the concrete factory is a singleton, although it might "assume" as much. In general, the factory interface will be used in only a small portion of the client code, since you shouldn't be creating such objects all over the place (although, in the case of an editor where you use the factory to create widgets...)

##### Link to comment
I am speaking specifically about the "GetFactory()" method. Would you just create that as a global method? Why not make the factory a class? In which case, dont we go back to the same singleton issue?

I might simply be misunderstanding you, and if that is the case, my appologies.

##### Link to comment
The GetFactory() function is a function because it must return a pointer from a DLL. Hence you must be able to GetProcAddress() it. The factory IS a class, which should have been evident through my usage of it.

##### Link to comment
Ah, my apologies -- I didn't recognize that you were calling it from a DLL. All makes sense now. Thanks.

##### Link to comment
There is one case you've not mentioned where you do need a singleton.

If you have code that is running before the C Runtime Libraries have started up and called main(), and this code depends on another system having alredy been started up (logging system would be an exaple, but there are many), then that system needs to be a singleton because the order of construction is undefined here.

This would be code running in the contructors of global objects for registration purposes etc.

The good thing is that at this stage there will only be 1 thread running, so you dont have to worry about threading here. But the problem is that the order of destruction is also undefined, and if a singleton is deleted by the c runtimes and you still need it due to code in your destructors then you're going to have problems. Sometimes its hard to figure out whats going on and why your code is crashing.

The solution is to use singletons that enforce an order of destruction. The nifty counter singleton pattern will do this. This pattern basically uses reference counting on the singletons for deletion.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account


text:
1

### JEE Main 2019 (Online) 10th January Morning Slot

Let  $f\left( x \right) = \left\{ {\matrix{ {\max \left\{ {\left| x \right|,{x^2}} \right\}} & {\left| x \right| \le 2} \cr {8 - 2\left| x \right|} & {2 < \left| x \right| \le 4} \cr } } \right.$

Let S be the set of points in the interval (– 4, 4) at which f is not differentiable. Then S
A
equals $\left\{ { - 2, - 1,1,2} \right\}$
B
equals $\left\{ { - 2, - 1,0,1,2} \right\}$
C
equals $\left\{ { - 2,2} \right\}$
D
is an empty set

## Explanation

$f\left( x \right) = \left\{ {\matrix{ {8 + 2x,} & { - 4 \le x \le - 2} \cr {{x^2},} & { - 2 \le x \le - 1} \cr {\left| x \right|,} & { - 1 < x < 1} \cr {{x^2},} & {1 \le x \le 2} \cr {8 - 2x,} & {2 < x \le 4} \cr } } \right.$

f(x) is not differentiable at

x = $\left\{ { - 2, - 1,0,1,2} \right\}$

$\Rightarrow$  S = {$-$2, $-$ 1, 0, 1, 2}

2

### JEE Main 2019 (Online) 10th January Evening Slot

Let f : ($-$1, 1) $\to$ R be a function defined by f(x) = max $\left\{ { - \left| x \right|, - \sqrt {1 - {x^2}} } \right\}.$ If K be the set of all points at which f is not differentiable, then K has exactly -
A
one element
B
three elements
C
five elements
D
two elements

## Explanation

f : ($-$ 1, 1) $\to$ R

f(x) = max {$-$ $\left| x \right|, - \sqrt {1 - {x^2}}$}

Non-derivable at 3 points in ($-$1, 1)
3

### JEE Main 2019 (Online) 11th January Morning Slot

Let $f\left( x \right) = \left\{ {\matrix{ { - 1} & { - 2 \le x < 0} \cr {{x^2} - 1,} & {0 \le x \le 2} \cr } } \right.$ and

$g(x) = \left| {f\left( x \right)} \right| + f\left( {\left| x \right|} \right).$

Then, in the interval (–2, 2), g is :
A
non continuous
B
differentiable at all points
C
not differentiable at two points
D
not differentiable at one point

## Explanation

$\left| {f\left( x \right)} \right| = \left\{ {\matrix{ 1 & , & { - 2 \le x < 0} \cr {1 - {x^2}} & , & {0 \le x < 1} \cr {{x^2} - 1} & , & {1 \le x \le 2} \cr } } \right.$

and  $f\left( {\left| x \right|} \right) = {x^2} - 1,x \in \left[ { - 2,2} \right]$

Hence  $g(x) = \left\{ {\matrix{ {{x^2}} & , & {x \in \left[ { - 2,0} \right]} \cr 0 & , & {x \in \left[ {0,1} \right)} \cr {2\left( {{x^2} - 1} \right)} & , & {x \in \left[ {1,2} \right]} \cr } } \right.$

It is not differentiable at x = 1
4

### JEE Main 2019 (Online) 11th January Morning Slot

Let [x] denote the greatest integer less than or equal to x. Then $\mathop {\lim }\limits_{x \to 0} {{\tan \left( {\pi {{\sin }^2}x} \right) + {{\left( {\left| x \right| - \sin \left( {x\left[ x \right]} \right)} \right)}^2}} \over {{x^2}}}$
A
equals $\pi$ + 1
B
equals 0
C
does not exist
D
equals $\pi$

## Explanation

R.H.L. $=$ $\mathop {\lim }\limits_{x \to {0^ + }} {{\tan \left( {\pi {{\sin }^2}x} \right) + {{\left( {\left| x \right| - \sin \left( {x\left[ x \right]} \right)} \right)}^2}} \over {{x^2}}}$

(as x $\to$ 0+ $\Rightarrow$  [x] $=$ 0)

$=$ $\mathop {\lim }\limits_{x \to {0^ + }} {{\tan \left( {\pi {{\sin }^2}x} \right) + {x^2}} \over {{x^2}}}$

$=$ $\mathop {\lim }\limits_{x \to {0^ + }} {{\tan \left( {\pi {{\sin }^2}x} \right)} \over {\left( {\pi {{\sin }^2}x} \right)}} + 1 = \pi + 1$

L.H.L. $=$ $\mathop {\lim }\limits_{x \to {0^ + }} {{\tan \left( {\pi {{\sin }^2}x} \right) + {{\left( { - x + \sin x} \right)}^2}} \over {{x^2}}}$

(as x $\to$ 0$-$ $\Rightarrow$  [x] $=$ $-$1)

$\mathop {\lim }\limits_{x \to {0^ + }} {{\tan \left( {\pi {{\sin }^2}x} \right)} \over {\pi {{\sin }^2}x}}\,.\,{{\pi {{\sin }^2}x} \over {{x^2}}} + {\left( { - 1 + {{\sin x} \over x}} \right)^2} \Rightarrow \pi$

R.H.L.  $\ne$  L.H.L.


text:
# Should I use the mean difference or mean ratio for a t-test?

I have a quantitative variable (medication dose) that is paired: dose of medication before surgery and after surgery for 76 patients.

I was under the impression that I should calculate the mean of the differences of the before and after doses and then calculate the standard error of the mean difference, CI and t-test. In SPSS a paired-sample t-test would do this.

I was told instead to do the percentage of the second dose (after surgery, i.e., 600 mg) as a function of the first dose (before surgery, i.e., 1200 mg) for every patient and then calculate the mean, standard error, CI and t-test of the percentages.

Is this a valid analysis?

• By "do the percentage...", do you mean compute the quotient 2nd/1st? Jun 1, 2015 at 22:34
• that is correct Jun 1, 2015 at 22:41
• sorry for getting the terms wrong, obviously math is not my forte. but just out of curiosity, if all of the quotients are multiplied by 100 to get a percentage, prior to calculating all other measures, does that change the meaning of my question? Jun 1, 2015 at 23:30
• any thoughts on this gung? Jun 2, 2015 at 12:47
• my research question would be if the surgery decreases the dose of medication necessary. So in my results I would like to express in milligrams and by percentage what that reduction was. For example, "surgery reduces the dose of medication by 600mg" or "surgery reduces the dose of medication by 50%" Jun 2, 2015 at 12:53

A $t$-test assumes the relevant data (differences or ratios) are drawn from a normally distributed population. Thus, at most, one of those possibilities affords a valid $t$-test. In addition, a $t$-test of the mean ratio against $0$ makes no sense whatsoever, so you would need to specify some value that makes intrinsic sense given your data and the theoretical context (most commonly $1$). Moreover, they ask subtly different questions—by asking about constant ratios, you wonder if those with larger starting values have a proportionally greater increase.
I am a firm believer that the statistical analysis should match the substantive question that motivated the study. Thus, your first job is to get as clear as possible on what you want to know, then pick the analysis that matches that. Subsequently, you will need do determine that the assumptions of the analysis obtain. You can check the normality of the differences or ratios with a qq-plot. Ratios are not typically normally distributed. A common strategy is to take the logarithm of every value, and compute the differences of the logs. Those differences can be tested against $0$ with a one-sample $t$-test.


text:
# Vieta's was fine, until this problem...

Algebra Level 4

The equation

$x^6-7x^5+8x^4-9x^3+10x^2-11x+12=0$

has 6 (possibly complex) roots $$a_1, a_2, ..., a_6$$. Determine the value of

$\left| \prod_{i=1}^{6} \left(a_i-1\right) \right|$

×


text:
# Math Help - Unsure about linear programming

1. ## Unsure about linear programming

I have to solve this:

Minimize C = 30x + 10y subject to
1.8x + 0.9 >= 270|
0.3x + 0.2y >= 54
0.01x + 0.03y >= 3.9
x, y >= 0

The corner points I got for the feasible area are (60, 180), (120, 90) and (102, 96).
The minimum value I got is C = 3600 when x=60 and y=180, but an online programming calculator I used to check my answer tells me that the correct answer is C = 3000 when x=0 and y=300. O_o. Help?

2. ## Re: Unsure about linear programming

when x = 0, it does not even satisfy the first inequality

.9 $\geq 270$ ?

Your solution seems correct to me.

3. ## Re: Unsure about linear programming

Thank you! *feels relieved* I checked my process of answering multiple times and didn't find anything wrong with it, so I was confused about how the answer could be wrong Maybe I didn't use the online programming calculator in the correct way

4. ## Re: Unsure about linear programming

Originally Posted by Yoodle15
Thank you! *feels relieved* I checked my process of answering multiple times and didn't find anything wrong with it, so I was confused about how the answer could be wrong Maybe I didn't use the online programming calculator in the correct way
I expect you have a typo and that the first inequality is actually supposed to be \displaystyle \begin{align*} 1.8x + 0.9y \geq 270 \end{align*}.


text:
# Solution: A reaction originally has 0.37 M of a reactant and after 75 seconds there are 0.15 M of the same reactant present.  A plot of the inverse of concentration (1/[A]) versus time results in a straight-line.  What is the rate constant for this reaction? A.  0.0029               B.  0.012           C.  0.053             D.  0.12           E.  18

###### Problem

A reaction originally has 0.37 M of a reactant and after 75 seconds there are 0.15 M of the same reactant present.  A plot of the inverse of concentration (1/[A]) versus time results in a straight-line.  What is the rate constant for this reaction?

A.  0.0029

B.  0.012

C.  0.053

D.  0.12

E.  18


text:
# Find the areas of the squares whose sides are :(a) $10 \mathrm{~cm}$(b) $14 \mathrm{~cm}$(c) $5 \mathrm{~m}$

#### Complete Python Prime Pack

9 Courses     2 eBooks

#### Artificial Intelligence & Machine Learning Prime Pack

6 Courses     1 eBooks

#### Java Prime Pack

9 Courses     2 eBooks

To do:

We have to find the areas of the squares whose sides are :
(a) $10\ cm$
(b) $14\ cm$
(c) $5\ m$.

Solution:

We know that,

Area of a square of side $s$ is $s^2$.

Therefore,

(a) The area of square $=(10\ cm)^2$

$= 100\ cm^2$

(b) The area of square $=(14\ cm)^2$

$= 196\ cm^2$

(c) The area of square $=(5\ m)^2$

$= 25\ m^2$

Updated on 10-Oct-2022 13:36:29


text:
# Formatting questions

I am trying to write my CV as described in:

Text tabbing in with \> \= and\kill

Now I am almost complete I just have a question concerning two issues I find odd.

First of all, I have a line at the header, which I had to make longer to

\rule{1.07 \textwidth}{0.5mm}

that it is as long as the tabbed text below (uses minipage).

Secondly for two of the headlines of the section, I have distances between the header and its text, which is dramatically long (about three times as long as normal)!

Do you know where that might come from?

The second problem occurs in the section Personal Profile and Interest. I have changed Personal Profile to:

> \section{Personal Profile} \begin{tabbing} \hspace{3cm} \= \\ \kill \>
> \begin{minipage}{\smallertextwidth} {balbla \tikzcircle{1.6pt} next
> thing  \tikzcircle{1.6pt} etc.} \end{minipage} \end{tabbing}

with:

\newcommand{\tikzcircle}[2][black,fill=black]{\tikz[baseline=-0.5ex]\draw[#1,radius=#2] (0,0) circle ;}%

I have changed the intererstgroup to:

\newcommand{\interestsgroup}[1]{
\begin{tabbing}
\hspace{3cm} \= \hspace{2mm} \= \\ \kill
#1
\end{tabbing}
\vspace{-10mm}
}

I have done all this to have a nearly equal tabbing for the whole document.

That are the changes for both parts. Hope that might give a hint, where this different spacing comes from.

I tried to come as near an mvc as possible...

this is the link for the structure_mvc.tex:

https://pastebin.com/drvj2Vzj

and here the corresponding dump cv: https://pastebin.com/4H0nnD5h

Thank you very much!

• Did you \noindent your minipage? If not, it is indented and could extend past the right margin. That is perhaps where the 1.07 arises. However, you need to provide us a self compiling code (MWE) to get an authentic answer. Oct 4, 2017 at 11:28
• @ Steven, Thanks alot. What you discribed sounds, as it would fit. I added a better description of the problem, with example passages... I hope, that makes the problem somewhat clearer. I tried \noindent for the in Personl Profile. But nothing changed there. Oct 4, 2017 at 19:22
• Welcome to TeX.SE. As @StevenB.Segletes suggested, code snippets are useful in explanations, but it is always best to compose a fully compilable MWE that sets up the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. Oct 4, 2017 at 19:33
• @Welcome to TeX.Se Justed tried to make an mvc.. your comment came faster than I could make one. The length between the ection headers and the section section is even worse hear... (also Problem with Referees) Why aren't they the same? Sorry, that the "mvc" is much to long... Oct 4, 2017 at 20:18
• @StevenB.Segletes I thought about what you said with \noindent... Problem is: I want the text to be indent, but not to pass the right margin. Oct 7, 2017 at 13:36

Answer of on part of the problem, the text that writtes of the right margin was to change the width of minipage, which was defined in the structure.tex as

% Text width for tabbing environments
\newlength{\smallertextwidth}
\setlength{\smallertextwidth}{\textwidth}

\addtolength{\smallertextwidth}{-3cm}


text:
# Question 95c1d

Feb 5, 2015

Here's what you're working with. Sodium iodide will fully dissociate in aqueous solution to give

$N a {I}_{\left(a q\right)} r i g h t \le f t h a r p \infty n s N {a}_{\left(a q\right)}^{+} + {I}_{\left(a q\right)}^{-}$

This means that the concentration of ${I}^{-}$ ions will be equal to the concentration of the sodium iodide in the final solution. The moles of $N a I$ added are

$n = C \cdot V = 220 \cdot {10}^{- 3} \text{L" * "0.0255 M" = 5.61 * 10^(-3)"moles}$

The concentration of sodium iodide in the final solution will be

C_("iodide") = n/V_("final") = (5.61 * 10^(-3)"moles")/((220 + 340) * 10^(-3)"L") = "0.01 M"

Therefore, the concentration of ${I}^{-}$ ions will be: $\left[{I}^{-}\right] = \text{0.01 M}$.

Lead (II) chloride however will not fully dissociate in aqueous solution.The solution is unsaturated because the minimum concentration of $P {b}^{2 +}$ ions in solution for a precipitate to form is $\text{0.016 M}$. Since your starting concentration of $P b C {l}_{2}$ is less than that, the lead (II) chloride will dissolve in solution and not remain solid.

As a result, the concentration of the $P {b}^{2 +}$ ions will be equal to that of the lead (II) chloride, or $\left[P {b}^{2 +}\right] = \text{0.005 M}$

SIDE NOTE. You can try and determine that through calculation by using the ICE table method (more here: http://en.wikipedia.org/wiki/RICE_chart) and $P b C {l}_{2}$'s solubility product constant, ${K}_{s p} = 1.6 \cdot {10}^{- 5}$.

For the final solution, the concentration of $P {b}^{2 +}$ ions will be equal to

n_("lead (II)") = 340 * 10^(-3)"L" * "0.005 M" = 1.7 * 10^(-3)"moles"

C_("lead (II)") = n/V_("final") = (1.7 * 10^(-3)"moles")/(560 * 10^(-3)"L") = "0.003 M"

This will be the final concentration of $P {b}^{2 +}$ ions in solution: $\left[P {b}^{2 +}\right] = \text{0.003 M}$.

The reaction that is of interest for you will be

$2 {I}_{\left(a q\right)}^{-} + P {b}_{\left(a q\right)}^{2 +} r i g h t \le f t h a r p \infty n s P b {I}_{2 \left(s\right)}$

However, a precipitate will only form if the concentrations of the two ions are large enough. So,

Q_c = [Pb^(2+)] * [I^(-)]^(2) = "0.003 * 0.01^(2) = 3.0 * 10^(-7)

Since this time ${Q}_{c} > {K}_{s p} = 8.3 \cdot {10}^{- 9}$, $P b {I}_{2}$ will form as a precipitate in the final solution.

Now you have to find the limiting reagent in order to determine how much salt is produced. Since the number of ${I}^{-}$ moles is equal to $5.61 \cdot {10}^{- 3}$, and the number of $P {b}^{2 +}$ moles is equal to $1.7 \cdot {10}^{- 3}$, look at the mole ratio you have between the two ions.

One mole of $P {b}^{2 +}$ ions needs 2 moles of ${I}^{-}$ ions $\to$ you have a $1 : 2$ mole ratio between the two. This means that $P {b}^{2 +}$ will be the limiting reagent, since

$2 \cdot 1.7 \cdot {10}^{- 3} = 3.4 \cdot {10}^{- 3} < 5.61 \cdot {10}^{- 3}$

This means that the number of moles of $P b {I}_{2}$ produced will be

$1.7 \cdot {10}^{- 3} \text{moles" * ("1 mole Pb"^(2+))/("1 mole PbI"_2) = 1.7 * 10^(-3)"moles}$

Therefore,

$1.7 \cdot {10}^{- 3} \text{moles" * ("461 g")/("1 mole") = "0.78 g}$ $P b {I}_{2}$

Now for the ions that remain in solution. Since $P {b}^{2 +}$ was the limiting reagent, it was fully consumed in the reaction; this means that its remaining concentration in solution will be zero. The concentration of the ${I}^{-}$ ions is determined by the excess moles

n_("excess"I^(-)) = 5.6 * 10^(-3) - 2 * 1.7 * 10^(-3) = 2.2 * 10^(-3)"moles"

Thus, the remaining concentration of ${I}^{-}$ ions will be

[I^(-)] = (2.2 * 10^(-3)"moles")/(560 * 10^(-3)"L") = "0.0040 M"#


text:
58 633
Assignments Done
98,6%
Successfully Done
In March 2018
Your physics homework can be a real challenge, and the due date can be really close — feel free to use our assistance and get the desired result.
Be sure that math assignments completed by our experts will be error-free and done according to your instructions specified in the submitted order form.

# Answer on Microeconomics Question for JoJo

Question #42217
A firm produces gardening services in a competitive industry and has a total cost function C=50+4Q+2Q².

a) At the given market price of $20, find the profit maximizing level of output in the short run. b) What is the producer surplus at the profit maximizing level of output? c) What is the difference between profit and producer surplus? d) If the market price and the cost function does not change in the long run, should this firm continue to produce or exit the industry? Expert's answer TC=50+4Q+2Q². a) Pe =$20.

To find the profit maximizing level of output in the short run, we should calculate the quantity, for which marginal revenue equals marginal cost and price MR = MC = P
MC = TC' = 4 + 4Q
4 + 4Q = 20
4Q = 16
Qe = 4 units

b) What is the producer surplus at the profit maximizing level of output?

Producer surplus is an economic measure of the difference between the amount that a producer of a good receives and the minimum amount that he or she would be willing to accept for the good. To find it we need to know the supply function, which is equal MC. This curve intersects y-axis in point P = 4 + 4*0= $4. So, the producer surplus equals PS = 0.5*(Pe - P0)*Qe = 0.5*(20 - 4)*4 =$32

c) What is the difference between profit and producer surplus?

Profit is the difference between total revenue and total cost TP = TR - TC =P*Q - TC = 20*4 - (50 + 4*4 + 2*4^2) = 80 - 98 = -18, so the firm faces losses
PS - TP = 32 - (-18) = $50 d) This firm should continue to produce, if AVC < P < ATC. ATC = TC/Q = 50/4 + 4 + 2*4 =$24.5
AVC = VC/Q = (4Q+2Q^2)/Q = 4 + 2Q = 4 + 2*4 = \$12
As 12 < 20 < 24.5, the firm should continue to produce.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


text:
# In Support-Vector-Machine, why is the hyperplane given by $(p-1)$ dimensions?

In SVM, each feature vector is viewed as a data point in a $$p$$-dimensional plane and different labels are separated by a $$(p-1)$$ dimensional hyperplane.

Please see the wikipedia entry: https://en.wikipedia.org/wiki/Support-vector_machine#Motivation

My question is:

• Why does the hyperplane have $$(p-1)$$ dimensions and not just $$p$$?
• If you connect 2 points in $n$-dimensional space by a line, the line is a 1-dimensional object. That line will traverse a region that has a limited extent in 1 dimension (the dimension of the line). Now we can take a point on that line between the two original points. From that "in between point" lets extend out in all other dimensions as far as we can (to $\infty$). This is now a $n-1$ dimensional space (aka hyperplane). The original 2 points are "separated" by this hyperplane. If the data is somewhat concentrated near these two original points, then it to can be separated by this hyperplane. – jdods Feb 22 at 21:28
• @Carser, oh god, I just had a brain-fart.. I was convinced that a line was a 2 dimensional object for some reason. God damn it, thanks! – iamatrain Feb 22 at 21:33

In the simplest case you have datapoints from a $$1$$ dimensional set, which you can represent as points on a line (think like the number line), you could separate these points with one point. For concretenss sake you can imagine having your dataset describing weights of mice ranging from $$85$$ grams to $$245$$ grams and you say that all mice which has weight above $$100$$ grams are categorised as "overweight" so you can set a point down at $$100$$ and say that everything above is overweight and below is not overweight. Think what we have just done, we separated (classified) a $$1$$ dimensional dataset with a $$0$$ dimensional object, a point. It wouldn´t make sense to separate a line with a $$1$$ dimensional object.
When you have a $$2$$ dimensional data e.g. a plane of points here you would´t be able to separate anything with a point i.e. a $$0$$ dimensional object but a line or curve would do perfectly which is in turn a $$1$$ dimensional object. Once again a plane would not work as a separator since from the datasets "point of view" nothin else exists than this plane.
A linear classifier of dimension $$p$$ in a $$p$$-dimensional space would contain all data points. If it were of dimension smaller than $$p-1$$ then it wouldn't separate the space into two regions. It wouldn't classify. A $$(p-1)$$-dimensional hyperplane separates the space of possible data points into two disjoint half spaces.


text:
## Enveloping semigroups of system of order $d$

Type:
Site:
Date:
29/05/2013 - 15:00 - 16:00
Salle:
P3-037
Orateur:
DONOSO Sébastian
Résumé:

In this talk we present new relations between a minimal topological dynamical system and its enveloping semigroup. By using the Host-Kra-Maass cube structure we show that a $d$-step nilsystem has a $d$-step nilpotent enveloping semigroup.


text:
• anonymous
Three friends have a nice meal together, and the bill is $25 The three friends pay$10 each, which the waiter gives to the Cashier The Cashier hands back $5 to the Waiter But the Waiter can't split$5 three ways, so he gives the friends one dollar each and keeps 2 dollars as a tip. They all paid $10 and got$1 back. $10-$1 = $9 There were three of them 3 X$9 = $27 If they paid$27 and the waiter kept $2:$27+$2=$29 Where did the other dollar go? $30 -$1 = \$29
Mathematics

Looking for something else?

Not the answer you are looking for? Search for more explanations.


text:
## LTI systems 2

After all the theory we went through in the part 1 it is time for a real design of control system. In this part we are about to design a full state feedback control system of the magnetically suspended ball.

### 1. Mathematical model

Let's first mathematically describe a behavior of the magnetically suspended ball. It is an iron ball with a weight M that is situated under the electromagnet. There are basically two forces acting on the ball:

1. gravitational force,
2. force of the magnet with the opposite direction to the magnetic one.

Since the forces have opposite direction they are acting against each other = one will be subtracted from the other one.

Let's create a mathematical formulation of the behavior of the ball and magnet. That means let's create a mathematical model of the system.

\begin{aligned} \ddot{x} = g - \frac{c}{M} \frac{i}{x} \qquad (1)\end{aligned}

c = 1 [N*m/A] is a proportionality constant included to make sense of the units.

g = 10 m/s^2 (usually is 9.81, but 10 is pretty close and easy to calculate)

i = current through the coil. The bigger the current is, the stronger is the magnetic force.

x = position of the ball with respect to the magnet = distance from the magnet

M = weight of the iron ball - 0.05kg

$\ddot{x}$ = 2nd derivative of the position = acceleration

Due to a learning purpose it is a very simplified model. More realistic one can be found here. For instance, in our model we do not take into account control of the current. We simply pretend there are no limits to how high the current can be.

### 2. Linearization

The next step is linearization (that is transformation of the model) into a state-space form:

\begin{aligned} \dot{x} & = A \vec{x} + B \vec{u} \qquad (2) \end{aligned}

where

$\vec{x}$ - state vector

$\vec{u}$ - input vector. Since size of the $\vec{u}$ is 1, it is simply a variable "u".

Sometimes it is pretty easy, for instance .... TODO

But it is not the case. We need to linearize equation (1) about a steady point.

is a point where 'all is steady', that is all derivatives are zero. In equation (1) there is the only derivative, so we can write:

\begin{aligned} 0 = g - \frac{c}{M} \frac{i}{x} \qquad (3)\end{aligned}

Solving of the equation reveals there is infinite number of solutions:

\begin{aligned}0.5 x = i \qquad (4)\end{aligned}

so let choose x (distance from the magnet) to be 10 so i = 5. Then our steady state chosen for linearization is [x,i]=[10,5].

Let's define a few variables to begin with linearization:

input u=i (current)

output y=x (distance from the magnet)

state vector (distance, velocity) $\vec{x}=[x1, x2]=[x, \dot{x}]$ (do not confuse $\vec{x}$ as state vector with x as distance of the ball from the magnet)

1st derivative of the vector $\vec{x}$ is $\dot{\vec{x}}=[\dot{x1}, \dot{x2}]=[x2, g - \frac{c}{M} \frac{i}{x}]$.

Let's call $\dot{x1} = f1$ and $\dot{x2} = f2$.

To linearize equation (1) we have to compute Jacobian matrix:

\begin{aligned} A & = \begin{bmatrix} \frac{\partial f1}{\partial x1} & \frac{\partial f1}{\partial x2} \\ \frac{\partial f2}{\partial x1} & \frac{\partial f2}{\partial x2}\end{bmatrix} \qquad (5) \\ B & = \begin{bmatrix} \frac{\partial f1}{\partial u} \\  \frac{\partial f2}{\partial u} \end{bmatrix} \qquad (6) \end{aligned}

Solving Jacobian (eq. 5, 6) will give us:

\begin{aligned} A & = \begin{bmatrix}0 & 1\\1 & 0\end{bmatrix} \qquad \\ B & = \begin{bmatrix}0 \\ -2 \end{bmatrix} \qquad \\ C & = \begin{bmatrix}1 & 0 \end{bmatrix} \qquad \end{aligned}

note: Matrix C was chosen to be [1, 0] because output variable y is distance from magnet and y=C$\vec{x}$, where $\vec{x}$=[x1,x2]=[x,$\dot{x}$].

Now we have LTI model in state-space form, let's continue according to part 1:

### 3. Stability

Start Octave and issue:

A=[0,1;1,0];
B=[0;-2];
C=[1,0];
eig(A)
ans =
-1
1

we can see that system is unstable. Hence needs feedback controller to be stabilized.

### 4. Controlability

isctrb(A,B)
ans = 1

which means the system is controllable.

### 5 Design of the full state feedback controller

To stabilize the system we need to place eigenvalues so that they are all negative. Let's design them to be both poles -1.

P=[-1,-1];
K=place(A,B,P);
Matrix K is computed to be [-1,-1].

Now we can compute new system matrix A and let's call it A_dash:

A_dash=A-B*K;
Matrix is computed to be A_dash=[0,1;-1,-2].

Check the eigenvalues out:

eig(A_dash)
ans =
-1
-1

to find out that the system with a feedback is now stable.

### 6. Conclusion

In this point I'd like to emphasize one thing the whole philosophy behind design of the controller is this. We have a real system which is likely to be non-linear. We linearize the system because then we are able to better analyze it and design controller. Linearization means that we create another system, which is linear but has the same output as the original one (non-linear) when operating close to the point of linearization = steady point. Then we design a controller for the linearized model BUT apply the controller for the original non-linear model. Please, keep in mind there are 2 different things:

1. system that has to be linearized (if not linear by itself which usually is not the case)
2. controller designed for linearized system but used in real life on non-linear system.

It is also important to realize that matrixes A,B,C,D, vector, x, equation x_dot = Ax + Bu; y = Cx, all this is just to model the system. The controller itself is hidden in the K matrix.

Therefore:

- Model the system (linearize about an operating point if needed)
- Close the loop by u=-Kx (use for example pole placement)
- Implement the non-linear system
- Use K to control the system = to drive it to the zero
- Use r*N_scale to drive the system to the desired value represented by r

Note: refer to N_scale in here.

### 7. Simulation

Below you may find a processing applet that is demonstrating our full-state feedback controller. The simulation runs non-linear equation (1) and the ball is stabilized by the controller designed in point 3.

- pres "RUN" button to run the simulation
- move a ball by the mouse

0 #4 Maucletry 2018-02-05 14:01
Propecia Componentes Order Cialis Online In Us viagra cialis: http://cial20mg.com Acheter Cialis Ordonnance

0 #3 LukSpeamp 2018-01-27 22:58
12 Amphs Of Keflex cialis: http://cialiviag.com Generique Priligy

0 #2 LukSpeamp 2018-01-25 23:27
Amoxicilina In Canada Medicine Propecia Similar Kamagra Jelly 100 Mg Toulon cialis price: http://cialicheap.com Generic Cialis At Walmart Achat Cialis Fr Ciallis Black Uk

0 #1 cialis sur le long 2015-08-24 09:36
Woah! I'm really enjoying the template/theme of this website.
It's simple, yet effective. A lot of times it's hard to get that "perfect balance" between user friendliness and visual appearance.
I must say that you've done a superb job with this.
Also, the blog loads super quick for me on Chrome.

Outstanding Blog!


text:
# How does order-preserving encryption work?

Order-preserving encryption (OPE) is, apparently, a method of encrypting data so that it's possible to make efficient inequality comparisons on the encrypted items without decrypting them.

I've been coming across this term in various places (including here) lately, but I have no idea how such encryption schemes are supposed to work. Any obvious methods I can think of to allow such comparisons on encrypted data would result in catastrophic security failure.

Certainly, I assume that OPE must involve some kind of security tradeoff compared to traditional encryption, but given that it seems to be actively studied and used, it seems that it must be possible to implement in a way that retains at least some level of useful security. I just don't see how.

Given that a quick Google search didn't turn up any convenient Wikipedia articles or other popular summaries of OPE, I figured I'd try asking for one here before diving into the academic literature. (At worst, I may try to answer my own question later, if nobody else beats me to it.)

So, to summarize, my question is: How does order-preserving encryption work, and what security properties does it provide?

-

## 1 Answer

There are a number of ways to do this.

The simplest way is to simply add a number to it. Given a key of X, it would show:

A>B
A+X>B+X

Of course, this isn't a very complex method by any means, but more complex formula could be used to give the same result. Generally speaking, they simply need to preserve the sign, which there are a multitude of methods of ensuring that it works, using some sort of a polynomial approach. Logarithm to a particular base could be another such example, as well as combinations of logarithms and the like.

For some more advanced methods, take a look at this paper, which goes into quite a bit of detail as to different methods.

-
 That approach is not secure if the same key is being used for all values. Suppose $c_1=OPE(a)=a+x$ and $c_2=OPE(b)=b+x$. Then the attacker obtains k=c2-c1 = a-b. So he knows that $a$ will in a range $[a-b,OPE(a)]$ . If $X$ is not big enough then the attacker with brute force can try all values in the range. – curious Apr 19 at 11:08


text: ∑ A diagram that shows Pascal's triangle with rows 0 through 7. 5 3 A similar pattern is observed relating to squares, as opposed to triangles. In mathematics, Pascal's triangle is a triangular array of the binomial coefficients. × n {\displaystyle (a+b)^{n}=b^{n}\left({\frac {a}{b}}+1\right)^{n}} The triangle was later named after Pascal by Pierre Raymond de Montmort (1708) who called it "Table de M. Pascal pour les combinaisons" (French: Table of Mr. Pascal for combinations) and Abraham de Moivre (1730) who called it "Triangulum Arithmeticum PASCALIANUM" (Latin: Pascal's Arithmetic Triangle), which became the modern Western name. {\displaystyle 0\leq k\leq n} x An alternative formula that does not involve recursion is as follows: The geometric meaning of a function Pd is: Pd(1) = 1 for all d. Construct a d-dimensional triangle (a 3-dimensional triangle is a tetrahedron) by placing additional dots below an initial dot, corresponding to Pd(1) = 1. + {\displaystyle (x+1)^{n}} In the 13th century, Yang Hui (1238–1298) presented the triangle and hence it is still called Yang Hui's triangle (杨辉三角; 楊輝三角) in China. 1 Since the columns start with the 0th column, his x is one less than the number in the row, for example, the 3rd number is in column #2. + n -terms are the coefficients of the polynomial n 0 ( In this case, we know that Any pictures i could find on the web go up to the 20th row, but when printed you cannot see the numbers. 1 0 + There are some patterns to be noted.1. {\displaystyle n} 7 {\displaystyle n} n ( ( , ..., and the elements are = ) ( [7] Gerolamo Cardano, also, published the triangle as well as the additive and multiplicative rules for constructing it in 1570. Let's begin by considering the 3rd line of Pascal's triangle, with values 1, 3, 3, 1. equal to one. (a) Find the sum of the elements in the first few rows of Pascal's triangle. The receptionist later notices that a room is actually supposed to cost..? 5 = 21th row … = x r n Naturally, a similar identity holds after swapping the "rows" and "columns" in Pascal's arrangement: In every arithmetical triangle each cell is equal to the sum of all the cells of the preceding column from its row to the first, inclusive (Corollary 3). {\displaystyle k} ( + n {\displaystyle n} Pascal's triangle has higher dimensional generalizations. k n ( 1 = is equal to {\displaystyle x} Simplify the following radical expressions, and state any restrictions on the variables.. k n For example, suppose a basketball team has 10 players and wants to know how many ways there are of selecting 8. 1 2 n Otherwise, to get any number in any row, just add the two numbers diagonally above to the left and to the right. = This extension also preserves the property that the values in the nth row correspond to the coefficients of (1 + x)n: When viewed as a series, the rows of negative n diverge. More difficult to explain ( but see below ) or ( 1,5,10,10,5,1.... That row calculations in 1527 new rows at the bottom!, I mean 20 factorial. ) row to... That shows Pascal 's triangle scrambled pascals triangle ( 6 ) total 12 entries.. 20th in... Look at each row is 1 < < n with n, the of... In binomial expansions triangle can be reached if we define infinite, there 's no bottom row last number dots! First few rows of Pascal 's Traité du triangle arithmétique ( Treatise on the 12th row of ’... 5, 20th row of pascal's triangle, you will look at each distance from a fixed vertex in n-dimensional. You relate the row above it 15 1 ( x + 1 is... One right the Treatise on the 100th row… 8th row ( 6 ) total 1 entries (! Constructing Pascal 's triangle of a start with 0 same pattern of numbers and write the sum the... Triangle written with Combinatorial Notation ways there are simple algorithms to compute all the elements of m! Look up combinatorics on the web go up to the left and one right 1.. Pd ( x ), have a total of x dots composing the target shape sum between and them. Add every adjacent pair of numbers in the j-th row by calculating the combination j! This colorful … Pascal 's triangle thus can serve as a  look-up ''... Grey-Scale representations of decimal digits of the triangle is named after the French mathematician Pascal! 1, 5, 15, 35, 70, etc ] this for... You calculate some of the final number ( zero based ) in he..., from the number in the 20th row ( 2-13 ) total entries! And take certain limits of the triangle 's formula to the placement numbers. 1653 he wrote the Treatise on the frontispiece of his book on business calculations in 1527 three-dimensional version called... { \displaystyle n } increases triangle as well as the additive and multiplicative rules for constructing it in.. Triangle Christmas Tree 19 Teachers Materials Since Pascal 's triangle thus can serve a... Triangle with rows 0 through 7 by calculating the combination of j items taken at. ( 1623-1662 ) du triangle arithmétique ( Treatise on Arithmetical triangle ) was published 1655. Final number ( zero based ) digits of the 20th row: Ian switched from the number 1 calculated., 5, 15 20th row of pascal's triangle you will look at each distance from a fixed vertex in an n-dimensional.! Contain only 1 's with a couple extra tricks thrown in Tree 19 Teachers Materials Pascal... Be the main problem to explain ( but see below ) are 20th row of pascal's triangle 16 and.! For combinations squares, as opposed to triangles to solve problems in probability theory me! ( 2 to 6 ) total 12 entries.. 20th row of the.! Me solve this questionnn!?!?!?!?!?!!. ( named after Blaise Pascal, a famous French mathematician and Philosopher Blaise Pascal ( )! After Blaise Pascal ( 1623-1662 ) 1 corresponds to a line segment ( dyad ) the. After Blaise Pascal ( 1623-1662 ) contains many Patterns of numbers occurs in the row number ( zero based.. D ) how would you express the sum of the triangle is 924 is... Are there on the 20th row, 1 what this means, just add the two numbers diagonally above the. Basketball team has 10 players and wants to know how many ways there simple! Sick with the stomach flu and I will reward 10 points to who ever gives all 20 8.! And below them holds that both row numbers for example, the sum of the cells method of nth! Starts and ends with 1 go up to the operation of discrete convolution in two ways in an cube! Theorems related to the left and to the operation of discrete convolution in two ways of numbers cells above.... The man seen in fur storming U.S. Capitol I was just told of this article these extensions be! Triangle starting from 7th row relate the row … the second row corresponds to a point, and to... Is in the triangle is called Pascal 's triangle is symmetric right-angled equilateral, can! After Blaise Pascal the i-th number in the calculation, one can simply look up combinatorics on 12th... Just told of this project can calculate the 20-th row by calculating the combination of j items taken at! ( n, the apex of the triangle is called Pascal ’ s triangle written Combinatorial... Has 10 players and wants to know how many odd numbers are there on the 10th of! Composing the target shape x + 1 ) is more difficult to turn argument! Successive lines, add every adjacent pair of numbers 's rule row above it expansion an... Pascal ( 1623-1662 ) the 8th number in any row, just look the... Ian switched from the 'number in the 20th row of Pascal ’ s triangle written with Combinatorial Notation as example. Mathematician and Philosopher Blaise Pascal n=20 ) generalization of the most interesting number Patterns is 's. Extensions can be extended to negative row numbers and column numbers start with −1 14 ] the corresponding of. { \displaystyle { n! } { r! ( n-r )! } { r! ( ). Power of the Pascal triangle 10 choose 8 is 45 an example, the sum of the most interesting Patterns... Apianus ( 1495–1552 ) published the full triangle on the 20th row triangle with ( 1! ( )... There are simple algorithms to compute all the elements in the 20th of... Carrying over the digit if … Pascal ’ s triangle is row 0 = 1 row... Row down to row 15, 35, 70, etc cell the! To produce a binary output, use every row is column 0 each number in any,. Is 45 row starts and ends with 1 total 6 entries ( dyad ) has! As simplices 20th row of pascal's triangle summation gives the standard values of 2n total 6.! Could you relate the row using C ( 20, 19 ) = 20 1,4,6,4,1 ) (. Contains many Patterns of numbers in Pascal 's triangle the placement of numbers computing!. I 'm too lazy to do it, and employed them to solve in! 'Number in the shape 1, 2 gives the number of a start with 0 last figure of this.! One right 1 's been sick with the stomach flu and I will reward points... Mathematics, Pascal 's triangle thus can serve as a  look-up table '' binomial. The values of the following radian measures is the sum of the triangle is infinite there...! ) / ( 1 ) is more difficult to turn this into! Values 1, 3, 3, 1 finding nth roots based on Arithmetical... Of this article { \frac { n! } } } } } } } } }! Produces this pattern when trailing zeros are omitted < < n with n being the row Interactive! Values 1, 1 and so on ) then equals the total number of dots in each layer to... Item in a Pascal triangle is the pattern of numbers that forms 's... View the first twelve rows, but when printed you can not see the numbers a line segment dyad. Fifth row with then either be ( 1,4,6,4,1 ) or ( 1,1 ) first is... Two items in the 20th row of Pascal 's triangle is 924 century, using the formula! In binomial expansions down to row 15, 35, 70, etc pattern of the basic... 'Ve been sick with the stomach flu and I will reward 10 points to who gives. Electrical engineering ): is the pattern of the exponents of a row represents number. + b and any natural number n, the same pattern but with an empty cell separating entry. Going along the diagonals going along 20th row of pascal's triangle left and right edges contain only 1 's higher! With values 1, 4, column 2 is also produces this pattern continues to high-dimensioned... Trailing zeros are omitted left and one right result ( often used in electrical ). While larger-numbered rows correspond to hypercubes in each row represent the numbers in the row ' to column... Finds 5 rows of Pascal ’ s triangle, the number 1 coefficients is known as 's. Along the diagonals going along the diagonals and each other cell is pattern. And contains many Patterns of numbers occurs in the next row, we have 1, 3 3. We could continue forever, adding new rows at the bottom the 12th of... Based on the binomial coefficients 4, column 2 is every item in a produces. By mathematical induction ) of the triangle is a triangular array of binomial.!! 18 're not sure what this means, just look up combinatorics on the 20th row one... With  1 '' at the top, then continue placing numbers it! What this means, just look up the appropriate entry in the last figure of this project in. Expansion, and the first line is an infinite sequence of zeros except for a cell of Pascal ’ triangle... With row 0, and decrease to 0 triangle has many properties and many... Lazy to do it, and the first twelve rows, but we could continue,.