text:
Q: C++ MSVC/GCC/Clang compilers bug I discovered what appears to be a mind breaking bug in the 3 compilers from the title. The following code compiles with the latest versions of all three compilers using both the c++11 and c++14 standards, even though it really shouldn't as the "visit_detail" function is not visible to "main".
Correction: I was stupid, not actually a bug in GCC/Clang, seems to be a bug in my MSVC version tho.
#include <utility>
#include <iostream>
#include <type_traits>

namespace bug
{
    using namespace std;
    using size_t = unsigned long long;

    namespace detail
    {
        struct visit_stop_t {};
        constexpr bug::detail::visit_stop_t visit_stop = bug::detail::visit_stop_t();

        template <typename Visitor, typename First, typename... Tail>
        void visit_detail(Visitor&& vis, First&& first, Tail&&... tail)
        {
            // code, not necessairy to recreate bug
        }
    }

    template <typename Visitor, typename... Variants>
    void visit(Visitor&& vis, Variants&&... vars)
    {
        bug::detail::visit_detail(bug::forward<Visitor>(vis), bug::forward<Variants>(vars)..., bug::detail::visit_stop);
    }

    template <typename Visitor>
    void visit(Visitor&& vis) = delete;
}

using namespace bug;

// dummy variant, used to test the code
// code is never actually used in this version
template <typename... T>
struct variant
{
    static constexpr bug::size_t size() noexcept { return sizeof...(T); }

    constexpr variant(int) noexcept {}

    template <bug::size_t I>
    constexpr int get() const noexcept { return 5; }
};

// simple example visitor
// code is never actually used in this version
struct visitor
{
    int operator()(int x) { std::cout << x << std::endl; return x; }
    double operator()(double x) { std::cout << x << std::endl; return x; }
};

int main()
{
    visitor vis;
    variant<int, double> var = 5;

    // where the trouble is:
    visit_detail(vis, var, bug::detail::visit_stop);  // ADL: http://en.cppreference.com/w/cpp/language/adl
    visit_detail(vis, var);  // fails with GCC/Clang, no error with MSVC => MSVC bug maybe

    std::cout << "Press enter to continue . . . ";
    std::getchar();
    return 0;
}

A: What you're experiencing is a C++ feature called argument-dependent lookup, or ADL for short. Basically, if you invoke a function f without explicitly qualifying it, the compiler will look for f in the namespaces of the arguments that you've passed.
This is what allows operator<< for IO streams to work without requiring qualifications:
std::cout << 100; // finds std::operator<<(std::ostream&, int);

In your particular case, the argument bug::detail::visit_stop is making the compiler look for visit_detail inside the bug::detail namespace.


text:
Q: Drawing a return path in a simple flow chart with Tikz This is my first attempt at drawing anything Tikz, so bear with me:
I'm trying to draw a simple flowchart for a DSP algorithm, however i am stuck at properly drawing the loop return that it incorporates. As you can see below in my code example, i was only able to not make the return arrow intersect the blocks in my graph by defining a node to the left of a node in the center and drawing an arrow from bottom to that node and then from that node to the top.
Is there any way to connect the bottom and top nodes with one arrow and make it go through that node (or better yet, automatically make it avoid intersections with the existing blocks)?
As a minor note:
I was not able to get rid of the gap in the start and end points of the arrows, any help with that would also be appreciated.
Also, since i used linebreaks in the box text, the spacing between the boxes was off and i resorted to manually spacing them. Is there a better way to do this?

\documentclass[12pt, a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,calc}
\begin{document}
\tikzstyle{block} = [draw, rectangle,
minimum height=3em, minimum width=20em]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]

\begin{tikzpicture}[auto, node distance=2cm,>=latex']

\node [input, name=input] {};
\node [block, below of=input, align=left] (reseter)
{$Betrag\ von\ X_{w}^{(i)}(mS, \omega)\ zur\ddot{u}cksetzen:$\\
$\hat{X}_{w}^{(i)}(mS, \omega)=|Y_{w}(mS, \omega)|\cdot
e^{j\angle X_{w}^{(i)}(mS, \omega)}$};

\node [block, below= 1cm of reseter, align=left] (estimator)
{$Signalsch\ddot{a}tzung\ von\ X_{w}^{(i)}(mS, \omega):$\\
$x^{(i+1)}(n) = \frac {\displaystyle \sum \limits_{m=-\infty}^{\infty}
w (mS-n) \cdot \hat x_w^{(i)} (mS,n) }
{\displaystyle \sum \limits_{m=-\infty}^{\infty}  w^2 (mS-n)}$};

\node [output, below=1.2cm of estimator] (output){};

\draw [->] (input) -- node {$x^{(i)}(n)$} (reseter);
\draw [->] (reseter) -- node [name=X] {$\hat{X}_{w}^{(i)}(mS, \omega)$} (estimator);
\draw [->] (estimator) -- node {$x^{(i+1)}(n)$} (output);

\node [above = 0.5cm of output] (fbs) {};
\node [below = 0.5cm of input] (fbe) {};
\node [left=5cm of X] (fb) {};
\draw [->] (fbs) -| (fb);
\draw [->] (fb) |- (fbe);
\end{tikzpicture}
\end{document}

A: This code will automatically space the blocks far enough apart to allow text between them.  One can increase this space by increasing the inner sep or outer sep on the between nodes.  I did have to fudge a little space to clear the left side of (reseter).
Note: Many of these changes are purely stylistic.  There is nothing wrong with below of= or name=, I just prefer not to use them.
\documentclass[12pt, a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,calc}
\begin{document}
\tikzset{input/.style=coordinate}
\tikzset{output/.style=coordinate}
\tikzset{block/.style={draw, rectangle,
  minimum height=3em,
  minimum width=20em}}
\tikzset{pinstyle/.style={pin edge={to-,thin,black}}}

\begin{tikzpicture}[auto, node distance=2cm,>=latex']

\node  (input) [input] {};

\node (fbe) [below right] at (input.south) {$x^{(i)}(n)$};

\node  (reseter)  [block, below, align=left] at (fbe.south west)
{$Betrag\ von\ X_{w}^{(i)}(mS, \omega)\ zur\ddot{u}cksetzen:$\\
$\hat{X}_{w}^{(i)}(mS, \omega)=|Y_{w}(mS, \omega)|\cdot
e^{j\angle X_{w}^{(i)}(mS, \omega)}$};

\node (X) [below right] at (reseter.south) {$\hat{X}_{w}^{(i)}(mS, \omega)$};

\node (estimator) [block, below, align=left] at (X.south west)
{$Signalsch\ddot{a}tzung\ von\ X_{w}^{(i)}(mS, \omega):$\\
$x^{(i+1)}(n) = \frac {\displaystyle \sum \limits_{m=-\infty}^{\infty}
w (mS-n) \cdot \hat x_w^{(i)} (mS,n) }
{\displaystyle \sum \limits_{m=-\infty}^{\infty}  w^2 (mS-n)}$};

\node (fbs) [below right] at (estimator.south) {$x^{(i+1)}(n)$};

\node (output) [output, below] at (fbs.south west) {};

\draw [->] (input) --  (reseter);
\draw [->] (reseter) --  (estimator);
\draw [->] (estimator) --  (output);

\coordinate (fb) at ($(estimator.west)+(-1em,0)$);
\draw [->] (fbs) -| (fb) |- (fbe);
\end{tikzpicture}
\end{document}

redpajama_set_name: RedPajamaStackExchange


text:
Q: Energy of static magnetic field I learned that the energy density of the magnetic field is
$$\mathcal{E}=\frac{1}{2\mu_0}\mathbf{B}\cdot\mathbf{B}$$
This can be derived by analyzing the Maxwell equation and from the procedure where the Poynting vector is derived as the energy flux. This derivation involves the whole package of Maxwell equation, namely, the electric field as well as the magnetic field.
Also, for an infinite solenoid, we know the total energy stored inside by charging it to current $I$
$$E = \frac12 LI^2 .$$
Since the magnetic field is constant in this case $B=\mu_0 n I$, and therefore for a solenoid of area $A$ of unit length $L=\frac{BnA}{I}=\mu_0n^2A$, one again obtains
$$\mathcal{E}=\frac{E}{A\cdot 1}=\frac{1}{2\mu_0}B^2 .$$
This derivation only involves static magnetic field.
However, we note this is a special case where the magnetic field is constant.
Now, in the case of electrostatics, we are able to derive the form of the energy density of the system by using essentially Coulomb's law and evaluating the work needed to move all the charge from infinity to form the distribution in question. In this context, the notion of energy of the magnetic field shall also stand regarding the static magnetic field.
My question therefore is, is it possible to derive the energy density of static magnetic field by using similar reasoning as for the case of the static electric field, employing Biot-Savart's law? Many thanks!
Edit: Regarding the derivations in the link provided by Hanting Zhang in the comment, to evaluate the energy of the magnetic field still involves the induction, and therefore electric field. In principle, is it possible to discuss the concept of energy only within the framework of the static magnetic field?


text:
Q: Scala code during compilation runs into error: recursive value info needs type I'm trying to overwrite a list variable declared before in the Scala code, but when I try to compile the JAR using it, I keep running into the compiler error:  error: recursive value info needs type
def extract_FileContent = udf((file_contents: String) => {

  val info = (file_contents.replace("\",\"", "     ")
    .replace("\"", "")
    .replaceAll("    ", "|")
    .replaceAll(" : \r\n", " : empty\r\n")
    .replaceAll("\r\n", "|")
    .replaceAll(" : ", "|")
    .replaceAll(": ", "|")
    .split("\\|")
    .map(x => x.trim.replaceAll(" -", ""))
    .filterNot(s => s == ""))
  // type info = Array[String]

  if (info.toList(42) == "Start Archive Record") {
    val info = info.take(42) ++ info.drop(50) \\ recursive error here
    }
}

A: You you define info twice. The definition inside the if statement, shadows the first defintion - basically, info on the left, and right side refer to the same (new) variable, not to the one you defined before, that's why it thinks, it's recursive.
Solution? Just give it a different name ... or, in this case, you don't actually have to name it at all:
val info = file_contents.replace ...
 ...
if (info(42) == "Start Archive Record") { // don't do `.toList` here, it's not only redundant, but actually makes things worse
  info.take(42) ++ info.drop(50)
} else info

A: Hi @aaron02 by quickly checking your code there are a couple things that are wrong, one of them the one you claim.
val keyword defines a constant, and your code is trying to override the constant "info" based on that condition... if you wanted that, you should probably use a var.
On the other one, within the if you are defining a constant based on it itself... this is the recursivity you are seeing the error for... the compiler helps you with type inference but on this case it requrires that you specify the type.
The following would work on isolation, but together on your code the compiler will tell you about your code trying to reassign a val.
val info: Array[String] = info.take(42) ++ info.drop(50)

hopefully this put some light in your coding.
update:
This snippet might be close to what you want:
def extract_FileContent = (file_contents: String) => {

  var info = file_contents.replace("\",\"", "     ")
    .replace("\"", "")
    .replaceAll("    ", "|")
    .replaceAll(" : \r\n", " : empty\r\n")
    .replaceAll("\r\n", "|")
    .replaceAll(" : ", "|")
    .replaceAll(": ", "|")
    .split("\\|")
    .map(x => x.trim.replaceAll(" -", ""))
    .filterNot(s => s == "")

  if (info.toList(42) == "Start Archive Record") {
    info = info.take(42) ++ info.drop(50) // recursive error here
  }
  info // This as last statement will mean we return the Array[String], otherwise we were returning a Unit (side effect only)
}


text:
Q: Incorrect printf format specifier compiles Compiling this MCVE
#include <stdio.h>
#include <climits>
#include <limits>

int main()
{
    unsigned long x = ULONG_MAX;
    printf( "1:=%lu - 2:=%lu 3:=%ld\n", std::numeric_limits<size_t>::max(), x, x );
}

with these gcc/clang [any version] options -Wall -Werror -pedantic does not fail.
This is the output:
1:=18446744073709551615 - 2:=18446744073709551615 3:=-1

I expected an error because I provide an unsigned int but the format specifier is signed int.
Compiling it with PowerPC gcc 4.8 fails as expected:

error: format '%lu' expects argument of type 'long unsigned int', but
  argument 2 has type 'unsigned int' [-Werror=format=]

My question is:
Why do gcc/clang compile these format specifier? For me I would say PowerPC gcc is correct because this is a serious sign/unsigned issue and the wrong format specifier displays an incorrect result.

A: As per GCC (min version 5.0) documentation,

-Wformat-signedness If -Wformat is specified, also warn if the format string requires an unsigned argument and the argument is signed and vice versa.

This setting is not default because the standard doesn't ask for it. If you want more than the standard, you need to use the correct flags. In your case, you are using -Wformat via -Wall but not -Wformat-signedness. Remember, -Wall does not switch on all warnings, just a sub-set which almost all people agree on.
Compilers do check for type safety, hence why you get a warning when you remove the long-specifier. Beyond that, if the data is not getting lost (as in sign to unsigned or unsigned to sign or promotion from int to long, etc.) they feel free to do nothing. In fact, clang doesn't have a flag for sign checking the formats (AFAIK).

A: Using printf in an inappropriate way is an instance of undefined behavior. The implementation can do very bad things (including apparently what you would dream it to do).
BTW, with C++, you'll better use std::cout and its operator << which is less error-prone.

Why do gcc/clang compile these format specifiers?

Most of the time, it does not (however, the compiler may know about printf and sometimes optimize calls to it, because your <stdio.h> header would use specific format function attributes). In your case, the compiler is probably emitting a call to the variadic printf provided by your standard C library. It is not compiling format specifiers (just passing literal constants as first argument to printf).
BTW, the control format string for size_t in printf is %zu
At last, language specifications do not define what the compiler should warn about.


text:
Q: Why does my NLOPT optimization error/fail to solve? I'm stumped. I have a problem formulated for NLOPT in R. The current problem solves for 180 variables with 28 equality constraints
The code is re-used from a simpler version of the problem, earlier in my script, with 36 variables and 20 equality constraints that solves instantly using NLOPT_LD_SLSQP as the algorithm.
The larger version of the problem with 180 variables produces the following, immediately, when using NLOPT_LD_SLSQP:
NLopt solver status: -4 ( NLOPT_ROUNDOFF_LIMITED: Roundoff errors led
to a breakdown of the optimization algorithm. In this case, the
returned minimum may
still be useful. (e.g. this error occurs in NEWUOA if one tries to
achieve a tolerance too close to machine precision.) )

This puzzled me, given that it worked on the smaller version of the problem. As well, it returns the starting values and doesn't actually complete any iterations. So I implemented, NLOPT_AUGLAG_LD_EQ as the main algorithm, and NLOPT_LD_SLSQP as the local algorithm. Now the problem fails to solve and produces this:
NLopt solver status: -1 ( NLOPT_FAILURE: Generic failure code. )

If I reduce the tolerance it just fails faster... I took the toy problem into Excel to see if I had failed to formulate properly or if it was somehow infeasible, but it solved immediately. I can give you this file if you want. I took the Excel solution values and populated the functions in R and sure enough my constraints, and objective function appear to be just fine.
I wonder if someone can help me with this problem. Here is some code that will produce the issue (tested and confirmed) for anyone in R:
library(pracma)
library(nloptr)

#My constraint function uses the following:
#RHS of the equality constraints
f.rhs <- c(590.0000,4781.0000,4414.0000,120.0000,224.0000,
849.0000,4693.0000,4374.0000,85.0000,697.0000,0.0000,
0.0000,0.0000,1092.0000,1434.0000,2251.0133,3482.9867,
2316.1813,1873.8187,1622.1450,1206.8550,1240.0000,1233.0000,
933.8532,733.1468,486.7907,395.2093,526.0000)

#matrix of constraints
#the first 10 rows are row total constraints
#the remaining 18 constraints are column total constraints
#this is a 28x180 matrix. It's sort of big to have it in this
#code window, but this code should produce the matrix for you
conmat <- c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.101385354477184,0,0,0,0,0,0,0,0,0,0,0,0,0.101385354477184,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.879602416076347,0,0,0,0,0,0,0,0,0,0,0,0,0,0.879602416076347,0,0,0,0,0,0,0,0,0,0,0,0,0,9.72187831641552,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9.72187831641552,0,0,0,0,0,0,0,0,0,0,0,0,50.825662951981,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,50.825662951981,0,0,0,0,0,0,0,0,0,0,0,61.4161196898944,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,61.4161196898944,0,0,0,0,0,0,0,0,0,0,76.5722969856399,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,76.5722969856399,0,0,0,0,0,0,0,0,0,85.0874667314792,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,85.0874667314792,0,0,0,0,0,0,0,0,70.1228611430807,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,70.1228611430807,0,0,0,0,0,0,0,72.2969630445657,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,72.2969630445657,0,0,0,0,0,0,70.9315070452785,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,70.9315070452785,0,0,0,0,0,54.6520210670868,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,54.6520210670868,0,0,0,0,44.0086494626126,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,44.0086494626126,0,0,0,20.019587567467,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20.019587567467,0,0,14.1724093345295,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14.1724093345295,0,10.4922206705268,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10.4922206705268,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3.56379085643383,0,0,0,0,0,0,0,0,0,0,0,3.56379085643383,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,36.3843642437252,0,0,0,0,0,0,0,0,0,0,0,0,36.3843642437252,0,0,0,0,0,0,0,0,0,0,0,0,0,0,208.581934690648,0,0,0,0,0,0,0,0,0,0,0,0,0,208.581934690648,0,0,0,0,0,0,0,0,0,0,0,0,0,649.993541449925,0,0,0,0,0,0,0,0,0,0,0,0,0,0,649.993541449925,0,0,0,0,0,0,0,0,0,0,0,0,620.425879840303,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,620.425879840303,0,0,0,0,0,0,0,0,0,0,0,532.113517313307,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,532.113517313307,0,0,0,0,0,0,0,0,0,0,487.289086271457,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,487.289086271457,0,0,0,0,0,0,0,0,0,355.571461649492,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,355.571461649492,0,0,0,0,0,0,0,0,370.187737611463,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,370.187737611463,0,0,0,0,0,0,0,377.604110342457,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,377.604110342457,0,0,0,0,0,0,286.391885309974,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,286.391885309974,0,0,0,0,0,230.617639447808,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,230.617639447808,0,0,0,0,150.901768695456,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,150.901768695456,0,0,0,106.827457261503,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,106.827457261503,0,0,102.516716725934,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,102.516716725934,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,478.206023100627,0,0,0,0,0,0,0,0,0,0,478.206023100627,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,656.900445375174,0,0,0,0,0,0,0,0,0,0,0,656.900445375174,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,835.409246572897,0,0,0,0,0,0,0,0,0,0,0,0,835.409246572897,0,0,0,0,0,0,0,0,0,0,0,0,0,0,913.757767618374,0,0,0,0,0,0,0,0,0,0,0,0,0,913.757767618374,0,0,0,0,0,0,0,0,0,0,0,0,0,483.249080637494,0,0,0,0,0,0,0,0,0,0,0,0,0,0,483.249080637494,0,0,0,0,0,0,0,0,0,0,0,0,317.775206732195,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,317.775206732195,0,0,0,0,0,0,0,0,0,0,0,237.647569920133,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,237.647569920133,0,0,0,0,0,0,0,0,0,0,144.341667617821,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,144.341667617821,0,0,0,0,0,0,0,0,0,124.724396017039,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,124.724396017039,0,0,0,0,0,0,0,0,98.7489023828154,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,98.7489023828154,0,0,0,0,0,0,0,55.1727766234815,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55.1727766234815,0,0,0,0,0,0,44.4279889177619,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,44.4279889177619,0,0,0,0,0,25.9420568421214,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25.9420568421214,0,0,0,0,18.3650860591977,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18.3650860591977,0,0,0,18.8065580202466,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18.8065580202466,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.625528507812058,0,0,0,0,0,0,0,0,0,0.625528507812058,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.14682340323878,0,0,0,0,0,0,0,0,0,0,1.14682340323878,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8.19022941749738,0,0,0,0,0,0,0,0,0,0,0,8.19022941749738,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25.5271393599384,0,0,0,0,0,0,0,0,0,0,0,0,25.5271393599384,0,0,0,0,0,0,0,0,0,0,0,0,0,0,30.1338658434231,0,0,0,0,0,0,0,0,0,0,0,0,0,30.1338658434231,0,0,0,0,0,0,0,0,0,0,0,0,0,33.325484734614,0,0,0,0,0,0,0,0,0,0,0,0,0,0,33.325484734614,0,0,0,0,0,0,0,0,0,0,0,0,34.6159582253122,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,34.6159582253122,0,0,0,0,0,0,0,0,0,0,0,25.9425263509155,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25.9425263509155,0,0,0,0,0,0,0,0,0,0,28.6721543150432,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28.6721543150432,0,0,0,0,0,0,0,0,0,24.6001930717219,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24.6001930717219,0,0,0,0,0,0,0,0,19.4063381820094,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,19.4063381820094,0,0,0,0,0,0,0,15.6269927027328,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15.6269927027328,0,0,0,0,0,0,7.86354283325046,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7.86354283325046,0,0,0,0,0,5.56681537403581,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5.56681537403581,0,0,0,0,4.09245697782775,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,4.09245697782775,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.0478232804137659,0,0,0,0,0,0,0,0,0.0478232804137659,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.4097388469824,0,0,0,0,0,0,0,0,0,0.4097388469824,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.18088960908956,0,0,0,0,0,0,0,0,0,0,1.18088960908956,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2.13050439017778,0,0,0,0,0,0,0,0,0,0,0,2.13050439017778,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2.88537630873373,0,0,0,0,0,0,0,0,0,0,0,0,2.88537630873373,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4.47104432861129,0,0,0,0,0,0,0,0,0,0,0,0,0,4.47104432861129,0,0,0,0,0,0,0,0,0,0,0,0,0,6.7066648766379,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6.7066648766379,0,0,0,0,0,0,0,0,0,0,0,0,7.21292740479352,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7.21292740479352,0,0,0,0,0,0,0,0,0,0,0,13.2288618280058,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,13.2288618280058,0,0,0,0,0,0,0,0,0,0,17.7096180695658,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17.7096180695658,0,0,0,0,0,0,0,0,0,32.1794159026695,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32.1794159026695,0,0,0,0,0,0,0,0,25.9125391288607,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25.9125391288607,0,0,0,0,0,0,0,39.9666473126856,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,39.9666473126856,0,0,0,0,0,0,28.293474255415,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28.293474255415,0,0,0,0,0,71.410473393917,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71.410473393917,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.182608374202251,0,0,0,0,0,0,0,0.182608374202251,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2.83538237187642,0,0,0,0,0,0,0,0,2.83538237187642,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,19.2609656330223,0,0,0,0,0,0,0,0,0,19.2609656330223,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,80.7233037904926,0,0,0,0,0,0,0,0,0,0,80.7233037904926,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,85.6477154102395,0,0,0,0,0,0,0,0,0,0,0,85.6477154102395,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,99.9589781355406,0,0,0,0,0,0,0,0,0,0,0,0,99.9589781355406,0,0,0,0,0,0,0,0,0,0,0,0,0,0,111.246861310206,0,0,0,0,0,0,0,0,0,0,0,0,0,111.246861310206,0,0,0,0,0,0,0,0,0,0,0,0,0,95.4680594823716,0,0,0,0,0,0,0,0,0,0,0,0,0,0,95.4680594823716,0,0,0,0,0,0,0,0,0,0,0,0,110.647972395614,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,110.647972395614,0,0,0,0,0,0,0,0,0,0,0,121.020177240488,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,121.020177240488,0,0,0,0,0,0,0,0,0,0,82.2865998682753,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,82.2865998682753,0,0,0,0,0,0,0,0,0,63.071831445587,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,63.071831445587,0,0,0,0,0,0,0,0,28.5766379506572,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28.5766379506572,0,0,0,0,0,0,0,26.2025287609293,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26.2025287609293,0,0,0,0,0,0,24.3533348857096,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24.3533348857096,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6.77378361061052,0,0,0,0,0,0,6.77378361061052,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,66.8658893692034,0,0,0,0,0,0,0,66.8658893692034,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,301.030835688858,0,0,0,0,0,0,0,0,301.030835688858,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,790.527770127371,0,0,0,0,0,0,0,0,0,790.527770127371,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,571.353574962507,0,0,0,0,0,0,0,0,0,0,571.353574962507,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,465.451417348464,0,0,0,0,0,0,0,0,0,0,0,465.451417348464,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,385.48085698754,0,0,0,0,0,0,0,0,0,0,0,0,385.48085698754,0,0,0,0,0,0,0,0,0,0,0,0,0,0,298.799798756715,0,0,0,0,0,0,0,0,0,0,0,0,0,298.799798756715,0,0,0,0,0,0,0,0,0,0,0,0,0,305.715022425598,0,0,0,0,0,0,0,0,0,0,0,0,0,0,305.715022425598,0,0,0,0,0,0,0,0,0,0,0,0,296.891932828816,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,296.891932828816,0,0,0,0,0,0,0,0,0,0,0,189.45276364351,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,189.45276364351,0,0,0,0,0,0,0,0,0,0,145.213592426377,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,145.213592426377,0,0,0,0,0,0,0,0,0,62.942694262135,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,62.942694262135,0,0,0,0,0,0,0,0,57.7134986817454,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,57.7134986817454,0,0,0,0,0,0,0,35.5644312539887,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,35.5644312539887,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,600.919741246423,0,0,0,0,0,600.919741246423,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,664.169162623053,0,0,0,0,0,0,664.169162623053,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,847.398221128337,0,0,0,0,0,0,0,847.398221128337,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,903.249824396504,0,0,0,0,0,0,0,0,903.249824396504,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,402.366866953328,0,0,0,0,0,0,0,0,0,402.366866953328,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,280.141092267195,0,0,0,0,0,0,0,0,0,0,280.141092267195,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,201.892549678482,0,0,0,0,0,0,0,0,0,0,0,201.892549678482,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,139.225117820461,0,0,0,0,0,0,0,0,0,0,0,0,139.225117820461,0,0,0,0,0,0,0,0,0,0,0,0,0,0,123.454735574923,0,0,0,0,0,0,0,0,0,0,0,0,0,123.454735574923,0,0,0,0,0,0,0,0,0,0,0,0,0,113.363999137925,0,0,0,0,0,0,0,0,0,0,0,0,0,0,113.363999137925,0,0,0,0,0,0,0,0,0,0,0,0,72.6983780508768,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,72.6983780508768,0,0,0,0,0,0,0,0,0,0,0,55.7225581581023,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55.7225581581023,0,0,0,0,0,0,0,0,0,0,31.2411980593257,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31.2411980593257,0,0,0,0,0,0,0,0,0,28.6457207488449,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28.6457207488449,
  0,0,0,0,0,0,0,0,38.4996441218375,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,38.4996441218375,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.10058560667843,0,0,0,0,1.10058560667843,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3.80905898924575,0,0,0,0,0,3.80905898924575,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18.1504505832434,0,0,0,0,0,0,18.1504505832434,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,61.5743643896698,0,0,0,0,0,0,0,61.5743643896698,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,52.0421527000771,0,0,0,0,0,0,0,0,52.0421527000771,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,53.6771028451664,0,0,0,0,0,0,0,0,0,53.6771028451664,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,54.7413143789797,0,0,0,0,0,0,0,0,0,0,54.7413143789797,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,46.2299586575942,0,0,0,0,0,0,0,0,0,0,0,46.2299586575942,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43.5728165091606,0,0,0,0,0,0,0,0,0,0,0,0,43.5728165091606,0,0,0,0,0,0,0,0,0,0,0,0,0,0,36.8659311062071,0,0,0,0,0,0,0,0,0,0,0,0,0,36.8659311062071,0,0,0,0,0,0,0,0,0,0,0,0,0,21.583566050924,0,0,0,0,0,0,0,0,0,0,0,0,0,0,21.583566050924,0,0,0,0,0,0,0,0,0,0,0,0,16.5435811193775,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16.5435811193775,0,0,0,0,0,0,0,0,0,0,0,6.42202062218569,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6.42202062218569,0,0,0,0,0,0,0,0,0,0,5.88848766417714,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5.88848766417714,0,0,0,0,0,0,0,0,0,3.34484908130525,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3.34484908130525,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.478730062097792,0,0,0,0.478730062097792,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.599532361620929,0,0,0,0,0.599532361620929,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2.08861096083086,0,0,0,0,0,2.08861096083086,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4.67685892604545,0,0,0,0,0,0,4.67685892604545,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6.66062843004317,0,0,0,0,0,0,0,6.66062843004317,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10.3325985324682,0,0,0,0,0,0,0,0,10.3325985324682,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17.4366302473174,0,0,0,0,0,0,0,0,0,17.4366302473174,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,23.9406624891688,0,0,0,0,0,0,0,0,0,0,23.9406624891688,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,47.4993402782371,0,0,0,0,0,0,0,0,0,0,0,47.4993402782371,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,75.2636287745429,0,0,0,0,0,0,0,0,0,0,0,0,75.2636287745429,0,0,0,0,0,0,0,0,0,0,0,0,0,0,120.029503824241,0,0,0,0,0,0,0,0,0,0,0,0,0,120.029503824241,0,0,0,0,0,0,0,0,0,0,0,0,0,92.0013786669861,0,0,0,0,0,0,0,0,0,0,0,0,0,0,92.0013786669861,0,0,0,0,0,0,0,0,0,0,0,0,112.914580678886,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,112.914580678886,0,0,0,0,0,0,0,0,0,0,0,103.53378703525,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,103.53378703525,0,0,0,0,0,0,0,0,0,0,216.919314868552,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,216.919314868552)

#Create the matrix from my list of values
conmat <- matrix(conmat,nrow=28,ncol=180)

#Create the constraint function so that it produces 0s
#for the equality constraints

eqn <- function(x){
z=c()
for (i in 1:length(f.rhs)){
  z[i]=x%*%conmat[i,]-f.rhs[i]
}
return(z)
}

#Function for the Jacobian of the constraint function
eqn_grad <- function(x){
jacobian(eqn,x)
}

#Create my objective function: sum of squared error
#Data for the function is in f.obj
f.obj<- c(0,0,0,0.101385354477184,0.879602416076347,9.72187831641552,50.825662951981,61.4161196898944,76.5722969856399,85.0874667314792,70.1228611430807,72.2969630445657,70.9315070452785,54.6520210670868,44.0086494626126,20.019587567467,14.1724093345295,10.4922206705268,0,0,0,3.56379085643383,36.3843642437252,208.581934690648,649.993541449925,620.425879840303,532.113517313307,487.289086271457,355.571461649492,370.187737611463,377.604110342457,286.391885309974,230.617639447808,150.901768695456,106.827457261503,102.516716725934,0,0,0,478.206023100627,656.900445375174,835.409246572897,913.757767618374,483.249080637494,317.775206732195,237.647569920133,144.341667617821,124.724396017039,98.7489023828154,55.1727766234815,44.4279889177619,25.9420568421214,18.3650860591977,18.8065580202466,0,0,0,0.625528507812058,1.14682340323878,8.19022941749738,25.5271393599384,30.1338658434231,33.325484734614,34.6159582253122,25.9425263509155,28.6721543150432,24.6001930717219,19.4063381820094,15.6269927027328,7.86354283325046,5.56681537403581,4.09245697782775,0,0,0,0.0478232804137659,0.4097388469824,1.18088960908956,2.13050439017778,2.88537630873373,4.47104432861129,6.7066648766379,7.21292740479352,13.2288618280058,17.7096180695658,32.1794159026695,25.9125391288607,39.9666473126856,28.293474255415,71.410473393917,0,0,0,0.182608374202251,2.83538237187642,19.2609656330223,80.7233037904926,85.6477154102395,99.9589781355406,111.246861310206,95.4680594823716,110.647972395614,121.020177240488,82.2865998682753,63.071831445587,28.5766379506572,26.2025287609293,24.3533348857096,0,0,0,6.77378361061052,66.8658893692034,301.030835688858,790.527770127371,571.353574962507,465.451417348464,385.48085698754,298.799798756715,305.715022425598,296.891932828816,189.45276364351,145.213592426377,62.942694262135,57.7134986817454,35.5644312539887,0,0,0,600.919741246423,664.169162623053,847.398221128337,903.249824396504,402.366866953328,280.141092267195,201.892549678482,139.225117820461,123.454735574923,113.363999137925,72.6983780508768,55.7225581581023,31.2411980593257,28.6457207488449,38.4996441218375,0,0,0,1.10058560667843,3.80905898924575,18.1504505832434,61.5743643896698,52.0421527000771,53.6771028451664,54.7413143789797,46.2299586575942,43.5728165091606,36.8659311062071,21.583566050924,16.5435811193775,6.42202062218569,5.88848766417714,3.34484908130525,0,0,0,0.478730062097792,0.599532361620929,2.08861096083086,4.67685892604545,6.66062843004317,10.3325985324682,17.4366302473174,23.9406624891688,47.4993402782371,75.2636287745429,120.029503824241,92.0013786669861,112.914580678886,103.53378703525,216.919314868552)

#Objective Function is SSE
fn <- function(x){
sum((f.obj*x-f.obj)^2)
}

#Objective Gradient
fn_grad <- function(x){
grad(fn,x)
}

#Optimization options:
#Starting Values
x0 <- c(matrix(1,1,ncol=length(f.obj)))
#Lower Bound
lb_x <- c(matrix(0,1,ncol=length(f.obj)))
#Upper Bound
ub_x <- c(matrix(2,1,ncol=length(f.obj)))

Now here is the code to solve with SLSQP:
opts_list <- list("algorithm"="NLOPT_LD_SLSQP", "xtol_rel"=1.0e-8,"maxeval"=1000)

SOLUTION <- nloptr(x0,
                eval_f=fn,
                eval_grad_f=fn_grad,
                lb=lb_x,
                ub=ub_x,
                eval_g_eq = eqn,
                eval_jac_g_eq = eqn_grad,
                opts=opts_list)

SOLUTION

And here is the code to solve with AUGLAG:
local_opts_list <- list("algorithm" = "NLOPT_LD_SLSQP","xtol_rel"=1.0e-8)
opts_list <- list("algorithm"="NLOPT_LD_AUGLAG_EQ", "xtol_rel"=1.0e-8,"maxeval"=1000, "local_opts"=local_opts_list)

SOLUTION <- nloptr(x0,
                eval_f=fn,
                eval_grad_f=fn_grad,
                lb=lb_x,
                ub=ub_x,
                eval_g_eq = eqn,
                eval_jac_g_eq = eqn_grad,
                opts=opts_list)

SOLUTION

Last, but not least, here is a feasible solution produced by Excel:
XL_Sol <- c(1,1,1,0.999840758,0.998619343,0.984736297,0.917305327,0.895766204,0.902054225,0.930449654,0.908095562,0.90555472,0.907109309,0.92775884,0.941019433,0.973119106,0.980882453,1.00818501,1,1,1,0.999277369,0.99265595,0.957137798,1.068940265,0.971466259,0.916751383,1.031659407,1.088943875,1.106986398,1.09298138,1.169120549,1.136193658,1.242584994,1.260102262,1.218743178,1,1,1,1.036812057,1.051986714,1.066969218,0.764543983,0.983061755,1.117743946,1.086522598,1.048114102,1.042021839,1.032920906,1.017781177,1.013537363,1.007869529,1.005459785,1.04562595,1,1,1,0.986367866,0.975008481,0.821522583,0.442429864,0.339768188,0.28380776,0.279905133,0.44151851,0.382930646,0.470415572,0.581960382,0.663070622,0.830426413,0.879918273,0.920434632,1,1,1,0.99976331,0.997972512,0.994156123,0.989331379,0.985345491,0.979153535,0.96871128,0.966148601,0.937972897,0.916916787,0.848764035,0.877734945,0.811485291,0.866305968,0.895221739,1,1,1,0.999728838,0.995792558,0.971414471,0.875797499,0.862210736,0.88101002,0.867466136,0.883358551,0.865529128,0.894845599,0.898520124,0.920974341,0.964087977,0.966910775,1.02107896,1,1,1,1.000481883,1.004812176,0.752446473,1.516261232,1.234618416,1.169698414,1.138623218,1.098571557,1.102118823,1.098211297,1.060360506,1.043658294,1.01881129,1.016899233,1.086075848,1,1,1,0.970757235,0.948975599,1.042336122,0.836515328,0.953263454,1.082324289,1.058181611,1.036019128,1.032395622,1.02937951,1.018031769,1.012837354,1.007153339,1.006385936,1.090482373,1,1,1,0.979339786,0.92850077,0.659360317,0,0.01800471,0.038870008,0,0.145186371,0.194368327,0.318022546,0.600269991,0.693283542,0.880910409,0.890768254,0.94507392,1,1,1,0.998868123,0.998583119,0.995062994,0.988669793,0.983388904,0.978533683,0.963729915,0.94954262,0.90018972,0.84196737,0.764585537,0.80459333,0.760693136,0.77966356,0.896573068)
#eqn(XL_Sol) should give you a vector of numbers that are pretty close to zero.

My question is: why does this model produce the errors I've reported here for each of the SLSQP, and AUGLAG algorithms implemented in the sample code?
Would love some input here. Please let me know if you need any additional information!

A: An interesting thing about your system is that conmat is rank deficient:
qr(conmat)$rank # 24 < 28 (number of rows in the system)

But the system conmat%*%x = f.rhs is actually consistent and you can find one of its solutions using the answers from this post.
That means that your constraint system has 4 redundant relations.  Sometimes issues like this can lead to numerical instability, so let's see what happens if we remove the redundant equations.  To do this, we can adapt the answer in this post:
# let's relabel
conmat_raw = conmat
f.rhs_raw = f.rhs

# append rhs as a column to conmat
augmented_matrix <- cbind(conmat, f.rhs)

# qr transform of the transpose
q <- qr(t(augmented_matrix))

# extract a set of linearly dependent rows for the original augmented matrix
reduced <- t(t(augmented_matrix)[,q$pivot[seq(q$rank)]])

# decompose augmented matrix
conmat = reduced[,1:180]
f.rhs = reduced[,181]

Now, we can run the NLOPT_LD_SLSQP solver. After 1350 iterations, I get a solution.  Let's see how it compares to the XL_Sol.
> sol = SOLUTION$solution
> fn(sol)
[1] 58404.02
> fn(XL_Sol)
[1] 317837

So we've improved against the objective.  Let's check the solutions using the original constraints:
> sum((conmat_raw%*%sol - f.rhs_raw)^2)
[1] 6.071796e-08
> sum((conmat_raw%*%XL_Sol - f.rhs_raw)^2)
[1] 2.771957e-08


text:
Q: Best approach to compare recognized speech with a known text Given a known manuscript (text) which I expect the user to read (more or less accurately), what is the best approach to recognize the user's progress within the manuscript?
While I'm searching for a particular solution on iOS, I'm also interested in a more general answer.
iOS provides a speech recognition framework called Speech that I can use to recognize any speech. My current approach is to use the string results of this framework to match them against the manuscript. However, it seems to me like this has quite some overhead and that it would save resources and increase precision when I first feed the speech recognizer with the expected words so that it "knows" what to listen for.

For example, when the next word in the manuscript is "fish", I don't
  need the speech recognizer to search the whole English language
  dictionary for a word that best matches the recorded audio – I only
  need to get a probability value how likely it is that the user just
  said "fish".

I think it's very similar to keyword spotting only that I'm not only spotting a few keywords but the words in a whole manuscript.
Unfortunately, I haven't been able to find such an API on iOS. Is there any better approach to achieve this "speech tracking" than the one described above?

A:
However, it seems to me like this has quite some overhead and that it would save resources and increase precision when I first feed the speech recognizer with the expected words so that it "knows" what to listen for.

Maybe it would, but the speech framework provides no way for you to do that, so you can't.


text:
Q: Reading XML ElementExtensions in C# Win8.1 App I'm new to both C# and Windows App development, my comes experience mostly in python but I'm trying to challenge myself to learn something new.
I've been practicing/learning c# by making windows store apps, and after doing some WinJS/HTML5 tutorials I started on this tutorial: http://msdn.microsoft.com/en-us/library/windows/apps/br211380.aspx
I've completed the tutorial (including modifying the instructions for 8.1 apps since the tutorial is behind. I'm now trying to adapt my application to handle other types of data.
I'm attempting to pull all of the media:image tags from each item in a post so that I can display them. This is the structure of my XML data from an RSS feed.
        <item>
        <title>Post with photos</title>
        <link>http://website.com/2014/07/23/post-1//</link>
        <comments>http://website.com/2014/07/23/post-1/#comments</comments>
        <pubDate>Wed, 23 Jul 2014 15:45:02 +0000</pubDate>
        <dc:creator><![CDATA[Author]]></dc:creator>
                <category><![CDATA[Post]]></category>

        <guid isPermaLink="false">http://www.website.com/p?1</guid>
        <description><![CDATA[description here]]></description>
        <wfw:commentRss>http://www.website.com/post/1/feed/</wfw:commentRss>
        <slash:comments>0</slash:comments>
        <enclosure type="image/jpeg" length="1" url="http://0.gravatar.com/avatar/" />

        <media:thumbnail url="http://www.website.com/thumbnail_urle1406130272443.jpg?w=500" />
            <media:content url="http://0.gravatar.com/avatar/" medium="image">
            <media:category>author</media:category>
        </media:content>
            <media:content url="http://www.website.com/post/1/233-e1406130272443.jpg" medium="image">
            <media:title>image-23</media:title>
                    </media:content>
            <media:content url="http://www.website.com/post/1/163.jpg" medium="image">
            <media:title>image-16</media:title>
                    </media:content>
            <media:content url="http://www.website.com/post/1/73.jpg" medium="image">
            <media:title>bimage-7</media:title>
                    </media:content>
        </item>

I implemented this in HTML5/JS and when I did I used this method:
        var thumb = post.querySelector(
            "thumbnail").attributes.getNamedItem("url").textContent;
        var postImages = post.querySelectorAll("content");

        var ImageList = [];
        for (var imgIndex = 1; imgIndex < postImages.length; imgIndex++) {
            var imgHTML = "<img src='" + postImages[imgIndex].attributes.getNamedItem("url").textContent + "'
";
            var ImageList = ImageList += imgHTML;
        }

But naturally.. that won't do in C#. I have looked at these thread in SO: Get media elements from RSS using SyndicationFeed as well as the one linked inside of it and they don't work for me. When I try to use
    var elements = rss.Feed.Items.SelectMany(s => s.ElementExtensions.Select(x => x.GetObject().Value));
I do not have a GetObject method available when I put it all together using my code. Here is my current Data model.
        private async Task<FeedData> GetFeedAsync(string feedUriString)
        {
            Windows.Web.Syndication.SyndicationClient client = new SyndicationClient();
            Uri feedUri = new Uri(feedUriString);

            try
            {
                SyndicationFeed feed = await client.RetrieveFeedAsync(feedUri);

                // This code is executed after RetrieveFeedAsync returns the SyndicationFeed.
                // Process the feed and copy the data you want into the FeedData and FeedItem classes.
                FeedData feedData = new FeedData();

                if (feed.Title != null && feed.Title.Text != null)
                {
                    feedData.Title = feed.Title.Text;
                }
                if (feed.Subtitle != null && feed.Subtitle.Text != null)
                {
                    feedData.Description = feed.Subtitle.Text;
                }
                if (feed.Items != null && feed.Items.Count > 0)
                {
                    // Use the date of the latest post as the last updated date.
                    feedData.PubDate = feed.Items[0].PublishedDate.DateTime;

                    foreach (SyndicationItem item in feed.Items)
                    {
                        FeedItem feedItem = new FeedItem();
                        if (item.Title != null && item.Title.Text != null)
                        {
                            feedItem.Title = item.Title.Text;
                        }
                        if (item.PublishedDate != null)
                        {
                            feedItem.PubDate = item.PublishedDate.DateTime;
                        }
                        if (item.Authors != null && item.Authors.Count > 0)
                        {
                            feedItem.Author = item.Authors[0].Name.ToString();
                        }
                        // Handles RSS / Atom Feed differences..
                        if (feed.SourceFormat == SyndicationFormat.Atom10)
                        {
                            if (item.Content != null && item.Content.Text != null)
                            {
                                feedItem.Content = item.Content.Text;
                            }
                            if (item.Id != null)
                            {
                                feedItem.Link = new Uri(item.Id);
                            }
                        }
                        else if (feed.SourceFormat == SyndicationFormat.Rss20)
                        {
                            if (item.Summary != null && item.Summary.Text != null)
                            {
                                feedItem.Content = item.Summary.Text;
                            }
                            if (item.Links != null && item.Links.Count > 0)
                            {
                                feedItem.Link = item.Links[0].Uri;
                            }
                        }
                        feedData.Items.Add(feedItem);
                    }
                }
                return feedData;
            }
            catch (Exception)
            {
                return null;
            }
        }

I've tried setting breakpoints and looking at the item data in my RSS2.0 syndication handler, and I can see var media = item.ElementExtensions; has an accurate acount of all the element extensions in my post, and the title of them. (NodeName "content", NodeValue is the "title" from the element. but no URI for the url tag..)
I am looking for some way to integrate some way of getting these media:content, media thumbnail, etc, into a list so that I can assemble them and use them for HTML content later in my app.
Any advice would be appreciated!
edit:
More of my code..
 public class FeedData
    {
        public string Title { get; set; }
        public string Description { get; set; }
        public DateTime PubDate { get; set; }
        public Uri Image { get; set; }

        private List<FeedItem> _Items = new List<FeedItem>();
        public List<FeedItem> Items
        {
            get
            {
                return this._Items;
            }
        }

    }

    // Holds info for a single blog post
    public class FeedItem
    {
        public string Title { get; set; }
        public string Author { get; set; }
        public string Content { get; set; }
        public DateTime PubDate { get; set; }
        public Uri Link { get; set; }
    }

    // Holds a collection of blog feeds (FeedData), and contains methods needed to retrieve
    // the feeds
    public class FeedDataSource
    {
        private ObservableCollection<FeedData> _Feeds = new ObservableCollection<FeedData>();
        public ObservableCollection<FeedData> Feeds
        {
            get
            {
                return this._Feeds;
            }
        }

        public async Task GetFeedsAsync()
        {
            Task<FeedData> feed1 =
                GetFeedAsync("http://url.com/feed");
            Task<FeedData> feed2 =
                GetFeedAsync("http://url.com/feed");
            ...
            ...

            this.Feeds.Add(await feed1);
                ...
                ...
                ...
            this.Feeds.Add(await feed15);

        }

A: I'm not familiar with phone apps but you'd be putting this data into a repeater of some sort, data grid, etc.,
yes?  Not being familiar with the Task generic object I'll still hazard a guess that you could use the C# key-value pair class with the List, then in this object in a Repeater, Grid, directly. I believe any object that implements IEnumerable (which List should) can be iterated over with a KeyValuePair
Let me know a bit more of what you want to do.  It seems to me a
foreach KeyValuePair KVP in ListObject
{
   //Access KVP.key and values with your code here ...
}

A more clear example is using a KVP to iterate over a dictionary object:
    foreach (KeyValuePair<string, string> entry in dictTestEasement)
    {
        builder.RowFormat.Height = 0.2; //force row height by text font by setting height small
        builder.InsertCell();
        builder.Font.Bold = true;
        builder.InsertHtml(entry.Key);
        builder.Font.Bold = false;
        builder.InsertCell();
        builder.InsertHtml(entry.Value);
    }

The builder in this case is a global object for document construction (Aspose Words Object) -- it's constructing a Word document.  Don't be thrown by it.
seems straightforward ... I've used such solutions before and believe that's what you're fishing for.

A: SyndicationItem has a GetXMLDocument method that takes a SourceFormat (like Rss20) and then generates an XML string that you can parse using GEtElementsByTagName (or ID). Once you have that you can iterate through duplicate tags in a loop and use Attributes.GetNamedItem() to grab named attributes of an XML tag. It seems that 'media' is lopped off when exploring the xml for media:content tags in Rss20 format, so all thats necessary is content to search for.
var allImages = item.GetXmlDocument(feed.SourceFormat).GetElementsByTagName("content");
foreach (var s in allImages)
{
Debug.WriteLine(s.Attributes.GetNamedItem("url").InnerText;)
}


text:
Q: Drawing Implicit functions in an image (Python,[OpenCV]) I need to draw a curved line based on a function in an image. Something like x^2+y^2=1, without converting it to explicit form, because not all functions I use can be converted easily in this way. For regular implicit functions, I use cv2.polylines with the x and y points for drawing the curve in my image, and I would like to know from you guys if there is a similar solution for explicit functions. All I've found so far use matplotlib to plot the graph using plt.contour. But this does not seem really useful to me. Please Help
Thanks in Advance

A: You can render it like this, sorry, I am C++ fan ) hope the idea is clear for python programmers.
// Your function
float func(float x, float y)
{
    // x * x * sin(x) + y * y = 1
    return (x * x * sin(x) + y * y - 1);
}
// render it
void plotXY()
{
    // canvas size
    int height = 800;
    int width = 800;
    // plot scale
    float scale = 0.1;
    // cavas
    cv::Mat result=cv::Mat::zeros(height, width, CV_8UC3);
    // move origin to canvas center
    float cx = (float)width / 2.0f;
    float cy = (float)height / 2.0f;
    // precompute scale
    float sx = (scale * (float)width);
    float sy = (scale * (float)height);

    // scan for zero crossings
    for (uint32_t i = 1; i < height-1; ++i)
    {
        for (uint32_t j = 1; j < width-1; ++j)
        {
            // transform screen space to real space
            float x =  ((float)j -     cx) / sx;
            float x1 = ((float)(j-1) - cx) / sx;
            float x2 = ((float)(j+1) - cx) / sx;
            float y =  ((float)i -     cy) / sy;
            float y1 = ((float)(i-1) - cy) / sy;
            float y2 = ((float)(i+1) - cy) / sy;
            // if zero crossimg along x put pixel
            if ( func(x1,y)* func(x2, y) < 0)
            {
                result.at<cv::Vec3b>(i, j) = cv::Vec3b(255, 255, 255);
            }
            // if zero crossimg along y put pixel
            if (func(x, y1) * func(x, y2) < 0)
            {
                result.at<cv::Vec3b>(i, j) = cv::Vec3b(255, 255, 255);
            }
        }
    }

    // show and save result
    cv::imshow("plot", result);
    cv::imwrite("plot.jpg", result);
    cv::waitKey();
}

The result for function x * x * sin(x) + y * y = 1 will be:


text:
Q: Transaction in Spring cloud Stream Problem:
I am trying to read a big file line by line and putting the message in a RabbitMQ.
I want to commit to rabbitMQ at the end of the file. If any record in the file is bad, then I want to revoke the messages published to the queue.
Technologies:
Spring boot,
Spring cloud stream,
RabbitMQ
Could you please help me in implementing this transition stuff.
I know how to read a file and publish to a queue using spring cloud stream.
Edit:
  @Transactional
  public void sendToQueue(List<Data> dataList) {

      for(Data data:dataList)
      {
          this.output.send(MessageBuilder.withPayload(data).build());
          counter++; // I can see message getting published in the queue though management plugin
      }
      LOGGER.debug("message sent to Q2");

  }

Here is my config:
spring:
   cloud:
      stream:
        bindings:
           # Q1 input channel
           tpi_q1_input:
            destination: TPI_Q1
            binder: local_rabbit
            content-type: application/json
            group: TPIService
            # Q2 output channel
           tpi_q2_output:
            destination: TPI_Q2
            binder: local_rabbit
            content-type: application/json
            group: TPIService
            # Q2 input channel
           tpi_q2_input:
            destination: TPI_Q2
            binder: local_rabbit
            content-type: application/json
            group: TPIService
        binders:
          local_rabbit:
            type: rabbit
            environment:
              spring:
                rabbitmq:
                  host: localhost
                  port: 5672
                  username: guest
                  password: guest
                  virtual-host: /
          rabbit:
            bindings:
                  tpi_q2_output:
                    producer:
                          #autoBindDlq: true
                          transacted: true
                          #batchingEnabled: true
                  tpi_q2_input:
                   consumer:
                        acknowledgeMode: AUTO
                        #autoBindDlq: true
                        #recoveryInterval: 5000
                        transacted: true

spring.cloud.stream.default-binder: local_rabbit

Java config
@EnableTransactionManagement
public class QueueConfig {

  @Bean
  public RabbitTransactionManager transactionManager(ConnectionFactory cf) {
    return new RabbitTransactionManager(cf);
  }
}

Receiver
@StreamListener(JmsQueueConstants.QUEUE_2_INPUT)
  @Transactional
  public void receiveMesssage(Data data) {

    logger.info("Message Received in Q2:");
  }

A: *

*Configure the producer to use transactions ...producer.transacted=true

*Publish the messages within the scope of a transaction (using the RabbitTransactionManager).
Use normal Spring transaction mechanisms for #2 (@Transacted annotation or a TransactionTemplate).
The transaction will commit if you exit normally, or roll back if you throw an exception.
EDIT
Example:
@SpringBootApplication
@EnableBinding(Source.class)
@EnableTransactionManagement
public class So50372319Application {

    public static void main(String[] args) {
        SpringApplication.run(So50372319Application.class, args).close();
    }

    @Bean
    public ApplicationRunner runner(MessageChannel output, RabbitTemplate template, AmqpAdmin admin,
            TransactionalSender sender) {
        admin.deleteQueue("so50372319.group");
        admin.declareQueue(new Queue("so50372319.group"));
        admin.declareBinding(new Binding("so50372319.group", DestinationType.QUEUE, "output", "#", null));
        return args -> {
            sender.send("foo", "bar");
            System.out.println("Received: " + new String(template.receive("so50372319.group", 10_000).getBody()));
            System.out.println("Received: " + new String(template.receive("so50372319.group", 10_000).getBody()));
            try {
                sender.send("baz", "qux");
            }
            catch (RuntimeException e) {
                System.out.println(e.getMessage());
            }
            System.out.println("Received: " + template.receive("so50372319.group", 3_000));
        };
    }

    @Bean
    public RabbitTransactionManager transactionManager(ConnectionFactory cf) {
        return new RabbitTransactionManager(cf);
    }

}

@Component
class TransactionalSender {

    private final MessageChannel output;

    public TransactionalSender(MessageChannel output) {
        this.output = output;
    }

    @Transactional
    public void send(String... data) {
        for (String datum : data) {
            this.output.send(new GenericMessage<>(datum));
            if ("qux".equals(datum)) {
                throw new RuntimeException("fail");
            }
        }
    }

}

and
spring.cloud.stream.bindings.output.destination=output
spring.cloud.stream.rabbit.bindings.output.producer.transacted=true

and
Received: foo
Received: bar
fail
Received: null


text:
Q: How can I unit test a lock statement? How would I write a unit test to ensure that a lock was acquired?
For example:
public void AddItem(object item)
{
    lock (_list)
    {
        _list.Add(item)
    }
}

Is there a way to ensure that the lock statement is run?
Edit: I'm not trying to prove thread-safety (this I would assume), just that the lock() statement is called.
For example, I might test a new object() statement by substituting it in a CreateObject() factory function.

A: Unit-testing multiple threads is always tricky and should be approached with care.
In your case I wouldn't bother testing lock keyword, for the same reason you don't write tests for new.
Assert.IsNotNull(new object());
Also, you seem to be encapsulating as thread-unsafe collection in order to make it thread-safe. Instead of reinventing the wheel consider using thread-safe collections.

A: The same way you test any other thing: write a test that fails without it.  In other words, determine why you are writing the lock in the first place, and write a test that specifies that reason.  I assume the reason is thread-safety: if so, write the multi-thread test.  If it is some other reason, right that test.
If you really, really want to test calling the lock but not the behavior the lock causes, encapsulate:
public class MyLock : IDisposable
{
    private object _toLock;

    public MyLock(object toLock)
    {
        _toLock = toLock;
        Monitor.Enter(_toLock);
    }

    public virtual void Dispose()
    {
        Monitor.Exit(_toLock);
    }
}

You'll have to make a mockable factory too, of course.  Seems like overdoing it to me, but maybe it makes sense in your context.

A: See Jon Skeet's answer to a similar question: How to test if a thread is holding a lock on an object in C#?:

I don't believe there is. There are grotty hack things you could do
  like calling Monitor.Wait(monitor, 0) and catching the
  SynchronizationLockException, but that's pretty horrible (and could
  theoretically "catch" a pulse that another thread was waiting for).
  EDIT: In .NET 4.5, this is available with Monitor.IsEntered.

A: If you've written the Lock statement (which does something similar the the System.Threading.Lock statement) then I can see why you'd want to test it.
In this scenario you'd need to have a _list class that you've implemented the .Add method for this class, this will be a lot easier if you're using Dependency Injection to inject an IList to set _list. You would need to use a dummy instance of the IList which implements the .Add() method.
If you have the dummy .Add() call sleep for a set period of time (say 5 seconds), you could test by, starting a thread to call the .AddItem() method, this thread will lock the .Add() call via the .AddItem() method, the main thread could then wait 3 seconds before calling the .AddItem method.
If the lock works, the second thread will be delayed 2 seconds before executing the .Add, if the lock doesn't work, it will call straight-away.
It's messy and non-deterministic so if you run enough times (millions) you'll get a false result.

A: You need a small program where you emulate the reading and writing with threads...
In a new thread create 10,000 items and add them, while in another thread reading and then sleeping for some time.
Then in the main wait for both threads to exit and you should have the results according to the amount of times the test called add and did not call remove...
E.g when i % 2 == 0 then remove instead of add in the producer threads... this should also effect the consumer thread...
see How to wait for thread to finish with .NET?

A: Not sure that unit testing the lock is the right approach, rather you should test that AddItem functions correctly.  Couple of things you could do, however:
1) Use reflection to obtain a reference to _list, lock it in your test, and try to call AddItem
2) Add an internal method for testing that locks _list and pauses for a reasonable amount of time (2 seconds?).  If you make your internals visible to your test assembly you can call the test method on one thread and call AddItem on another.  Keep in mind that it is not fool-proof as technically the test could be blocked for some reason long enough for the initial lock to expire.


text:
Q: Modifying Collection when using a foreach loop in c# Basically, I would like to remove an item from a list whilst inside the foreach loop. I know that this is possible when using a for loop, but for other purposes, I would like to know if this is achievable using a foreach loop.
In python we can achieve this by doing the following:
a = [1, 2, 3, 4, 5, 6, 7, 8, 9]

for i in a:
    print i

    if i == 1:
        a.pop(1)

This gives the following Output
>>>1
3
4
5
6
7
8
9

But when doing something similar in c#, I get an InvalidOperationException, I was wondering if there was a way of getting around this, without just simply using a for loop.
The code in c# that I used when the exception was thrown:
static void Main(string[] args)
  {
  List<string> MyList = new List<string>(new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9"});

  foreach (string Item in MyList)
    {
    if (MyList.IndexOf(Item) == 0)
      {
      MyList.RemoveAt(1);
      }

    Console.WriteLine(Item);
    }
  }

Thanks in advance

A: If all you need is to remove all items that satisfy a condition you could use the List<T>.RemoveAll method:
List<string> MyList = new List<string>(new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9" });
MyList.RemoveAll(item => item == "1");

Note that this modifies the initial list.

A: You can't do this. From the docs for IEnumerator<T>:

An enumerator remains valid as long as
  the collection remains unchanged. If
  changes are made to the collection,
  such as adding, modifying, or deleting
  elements, the enumerator is
  irrecoverably invalidated and its
  behavior is undefined.

Alternatives are:

*

*Build up a new list of items to remove, then remove them all afterwards

*Use a normal "for" loop and make sure you're careful about not going over the same element twice or missing any out. (You've said you don't want to do this, but what you're trying to do just won't work.)

*Build a new collection containing only the elements you want to retain

The last of these alternatives is the LINQ-like solution, where you'd typically write:
var newList = oldList.Where(x => ShouldBeRetained(x)).ToList();

(Where ShouldBeRetained is whatever logic you want, of course.) The call to ToList() is only necessary if you actually want it in a list. This leads to more declarative code which is often easier to read. I can't easily guess what your original loop is meant to do (it seems pretty odd at the moment) whereas if you can express the logic purely in terms of the item, it can be a lot clearer.

A: You definitely may not change a collection in any way when using a foreach loop on it.
You can use a for loop and manage the index for yourself or make a copy of the collection and as you are looping the original, remove items from the copy that equal the item in the original.
In both cases it's not quite as clear or convenient :).


text:
Q: Counting frequencies in two lists, Python I'm new to programming in python so please bear over with my newbie question...
I have one initial list (list1) , which I have cleaned for duplicates and ended up with a list with only one of each value (list2):
list1 = [13, 19, 13, 2, 16, 6, 5, 19, 20, 21, 20, 13, 19, 13, 16],
list2 = [13, 19, 2, 16, 6, 5, 20, 21]
What I want is to count how many times each of the values in "list2" appears in "list1", but I can't figure out how to do that without getting it wrong.
The output I am looking for is something similar to this:
Number 13 is represented 1 times in list1.
........ Number 16 is represented 2 times in list1.

A: visited = []
for i in list2:
  if i not in visited:
    print "Number", i, "is presented", list1.count(i), "times in list1"
    visited.append(i)

A: The easiest way is to use a counter:
from collections import Counter
list1 = [13, 19, 13, 2, 16, 6, 5, 19, 20, 21, 20, 13, 19, 13, 16]
c = Counter(list1)
print(c)

giving
Counter({2: 1, 5: 1, 6: 1, 13: 4, 16: 2, 19: 3, 20: 2, 21: 1})

So you can access the key-value-pairs of the counter representing the items and its occurrences using the same syntax used for acessing dicts:
for k, v in c.items():
    print('- Element {} has {} occurrences'.format(k, v))

giving:
- Element 16 has 2 occurrences
- Element 2 has 1 occurrences
- Element 19 has 3 occurrences
- Element 20 has 2 occurrences
- Element 5 has 1 occurrences
- Element 6 has 1 occurrences
- Element 13 has 4 occurrences
- Element 21 has 1 occurrences

A: Simplest, easiest to understand, no-magic-approach is to create an object(associative array) and just count the numbers in list1:
list1 = [13, 19, 13, 2, 16, 6, 5, 19, 20, 21, 20, 13, 19, 13, 16]

frequency_list = {}

for l in list1:
    if l in frequency_list:
        frequency_list[l] += 1
    else:
        frequency_list[l] = 1

print(frequency_list)

prints out this:
{
    16: 2,
    2: 1,
    19: 3,
    20: 2,
    5: 1,
    6: 1,
    13: 4,
    21: 1
}

meaning 16 is there twice, 2 is there once...

A: You don't need to remove duplicates. When you add to a dictionary, automatically, the duplicates will be considered as single values.
list1 = [13, 19, 13, 2, 16, 6, 5, 19, 20, 21, 20, 13, 19, 13, 16]
counts = {s:list1.count(s) for s in list1}
print counts

{2: 1, 5: 1, 6: 1, 13: 4, 16: 2, 19: 3, 20: 2, 21: 1}

A: You can also use operator
>>> list1 = [13, 19, 13, 2, 16, 6, 5, 19, 20, 21, 20, 13, 19, 13, 16],
>>> list2 = [13, 19, 2, 16, 6, 5, 20, 21]

>>> import operator
>>> for s in list2:
...    print s, 'appearing in :',  operator.countOf(list1, s)

A: In technical terms, list is a "type" of "object". Python has a number of built in types like strings (str), integers (int), and a few others that can be easily found on google. The reason this is important is because each object type has its own "methods". You can think of these methods as functions that complete common programming tasks and make your life easier.
Counting the number of occurrences in a list is an example of a common programing task. We can accomplish it with the count() method. For example, to count the number of times 13 appears in list1:
count_13 = list1.count(13)

We can also use a for loop to iterate over the whole list:
for x in list2:
    print(list1.count(x)) #This is for python version 3 and up

or for python versions older than 3:
for x in list2:
    print list1.count(x)


text:
Q: How to prevent iTunes from adding converted Mp3s to the library? When I use iTunes to create Mp3 files from songs I've bought, iTunes also adds them to my library and I got them twice. How can I prevent iTunes from adding converted Mp3s to the library in the first place?
EDIT:
I'm using iTunes on Mac OS X
EDIT2:
Chris Johnsen's answer is quite good and worth the bounty. However, I also tried this script Chris pointed me to, and that's even better and I'll use this from now on. Thanks folks.

A: If you are OK with temporarily having the converted tracks in your iTunes library, you could use AppleScript to convert the track, remove the reference to the converted track, and finally move the converted file where ever you like.
Plain AppleScript has little capability for smooth UI, but the following script might do what you want. Paste it into Script Editor (or AppleScript Editor on Snowy) and save it as an "application bundle" ("application" on Snowy). To use it, configured your conversion settings (Import Settings) in iTunes, select some tracks in iTunes, then drop a folder on the saved application. Note that newly converted files will overwrite pre-existing files in the dropped folder (if their names are identical). It is probably best to drop empty folders unless you are sure you want any overwrites you might get. You might even get some ID3v2 tags out of the process (I did in some testing, but it depends on what iTunes decides to do).
on run
 display dialog "Drop a folder on this application to convert iTune's selected tracks and place them the dropped folder." & return & return & "The converted files will be whatever is selected in iTunes "Import Settings"." with title "About"
 return

 -- Test invocation:
 "/tmp/convert_to_external"
 alias POSIX file result
 open {result}
end run
on open theItems
 if length of theItems is 0 then
  display dialog "No items dropped? Only a single, plain folder should be dropped." with title "Error: Drop Only a Single Folder"
  return
 end if
 if length of theItems is greater than 1 then
  display dialog "Too many items have been dropped. Only a single, plain folder should be dropped." with title "Error: Drop Only a Single Folder"
  return
 end if
 set theItem to first item of theItems
 set info to info for theItem
 if not folder of info or package folder of info then
  display dialog """ & POSIX path of theItem & "" is not a plain folder. Only a single, plain folder should be dropped." with title "Error: Drop Only a Single Folder"
  return
 else
  |convert iTunes selection into folder|(theItem)
 end if
end open
to |convert iTunes selection into folder|(folderRef)
 try
  do shell script "test -d " & quoted form of POSIX path of folderRef
 on error m
  display dialog "Destination (" & destinationForShell & ") not accessible?" & return & m
  return
 end try

 tell application "iTunes"
  set trackList to selection
  repeat with selectedTrack in trackList
   try
    set convertedTrack to my convertTrack(selectedTrack)
    set convertedFile to location of convertedTrack
    my deleteTrackReference(convertedTrack) -- only delete the iTunes ref, not the track's file
    my moveItemToFolder(convertedFile, folderRef)
   on error m
    tell me to display dialog m with title "Error During Conversion/Removal/Move" -- giving up after 30
   end try
  end repeat
 end tell
end |convert iTunes selection into folder|
to convertTrack(aTrack)
 if class of aTrack is list then error "Must pass a single track."
 using terms from application "iTunes"
  set questionTimeout to 10
  set conversionTimeout to 600
  display dialog "About to start conversion of "" & name of aTrack & "". Select a timeout in seconds for the conversion (conversion will auto-start in " & questionTimeout & " seconds):" default answer conversionTimeout with title "Conversion Time Limit" giving up after questionTimeout
  try
   set conversionTimeout to (text returned of result) as number
  end try

  set convertedTrack to missing value
  with timeout of conversionTimeout seconds -- conversion may take longer than the deafult 120 second AppleEvent RPC timeout
   try
    set convertedTrack to convert aTrack
   on error
    error "Error while converting track."
   end try
  end timeout
  if convertedTrack is not missing value then return first item of convertedTrack
  error "Abandoning track conversion after timeout." & return & m
 end using terms from
end convertTrack
to deleteTrackReference(aTrack)
 try
  tell application "iTunes" to set mainLibrary to ¬
   first library playlist of (first source whose kind is library)
 on error
  error "Unable to find main library playlist object."
 end try
 using terms from application "iTunes"
  try
   set convertedTrackInMainLibrary to ¬
    (first track of mainLibrary whose database ID is (get database ID of aTrack))
  on error
   error "Unable to find track object in main library playlist."
  end try
  try
   delete convertedTrackInMainLibrary -- deletes the reference, not the actual file
  on error
   error "Unable to delete track from main library playlist."
  end try
 end using terms from
end deleteTrackReference
to moveItemToFolder(itemRef, folderRef)
 set itemPath to POSIX path of itemRef
 set folderPath to POSIX path of folderRef
 try
  do shell script "mv " & quoted form of itemPath & " " & quoted form of folderPath
 on error m
  error "Unable to move item (" & itemPath & ") to destination (" & folderPath & "):" & return & m
 end try
end moveItemToFolder

A: As far as I know, there is no way to do this. You might want to use a different app, like Quicktime or AudialHub to do the conversion instead. Do you want to keep the original, or the new file in iTunes? You can create smart playlists to help you collect either one into a single list to remove them all from your library in one step (opt-delete in OS X).

A: Move the created MP3 files to another directory outside of the tree that iTunes will scan for new content.
I assume that you use something other than MP3 as your primary audio format, so create a batch job to move any MP3 content from your iTunes directory tree into a separate location.
For instance, use ROBOCOPY.EXE to do this:
c:\windows\robocopy c:\itunes-path c:\mp3-files *.mp3 /s /zb /mov /xo

This command will move MP3 files in all subdirectories except if the target already exists and the source is older. You can add /mot:5 to the end in order to have it repeat itself every 5 minutes.

A: Depending on how often you do this, you could export a playlist to an MP3 Disc.  You'll need to burn a disc each time but a rewriteable might solve that issue.
Steps:
1) Create a playlist of the songs you want
2) Right click on the playlist and choose "Burn playlist to Disc"
3) In options that come up, choose MP3 CD and click burn.
4) The songs will be burned to the disc in MP3 format.
5) Grab the songs from the disc when it mounts in the finder do with them what you will.
It does involve a somewhat tedious step of burning the CD but it doesn't require anything third party and is a function within iTunes.

A: Edit: I suggested some general solutions, but it seems iTunes doesn't have the necessary features for any of them, so I've removed the suggestions.


text:
Q: Drop temporary tables in a single session How to drop the temporary tables in procedures for the same session.
Because I am facing a problem regarding temporary tables in Postgres Sql. If two procedures:
A() having a temporary table say temp(id, name)
B() having a temporary table say temp(id, name, address)
then if the procedure A is called first and after that procedure B is called then the temp table remains with the structure i.e. temp(id, name) defined in the procedure A and vice versa and the column "address" as defined in procedure B is not found.

A: PostgreSQL doesn't support procedure level temporary tables, so you just cannot do it.
A usage of temporary tables in Pg is little bit different than in other db. In your case, you have to use different names.

A: Temp tables are session scoped. Meaning the same session can see it across procedure calls and SQL calls. Basically the temp table is global to your session.
So your options are this assuming A calls B:

*

*Call procedure A and create temp table within A and do what you want with it. At the end of procedure A drop the temp table.  Call B from A, you can now create the temporary table with the same name inside of B and make use of it. As a good habit explicitly drop temp table once your're done with it.

*Otherwise use two different names for the temp table.
http://www.postgresql.org/docs/9.2/static/sql-createtable.html
"TEMPORARY or TEMP
If specified, the table is created as a temporary table. Temporary tables are automatically dropped at the end of a session, or optionally at the end of the current transaction (see ON COMMIT below). Existing permanent tables with the same name are not visible to the current session while the temporary table exists, unless they are referenced with schema-qualified names. Any indexes created on a temporary table are automatically temporary as well."


text:
Q: Speed up console application, Concurrency? Parralell Programming? I have the following (simplified) console application:
DirectoryInfo d = new DirectoryInfo(@"D:\Test");
FileInfo[] Files = d.GetFiles("*.txt");
foreach(FileInfo file in Files )
{
  //Do Something
}

There are 200+ files in the filefolder. The processing of each file will take about 15 minutes.
My question is, is it possible for me to use concurrency/parallel programming to process more than on file at a time?
The kind of thing I am thinking is, to start a number of threads? and each one of them will process every 5th or so file in the files list.
All the file processing will be totally independent, so no risk of race condition.
If this is possible, are there limits to how many threads I can start, or any other limitations.
The kind of work that will be done is to load the contents of each file into a generic list, process it and iterate through the list numerous times

A: It seems like it's a good job for Parallel.ForEach. It will provide you true parallelization because it can schedule each iteration to a different CPU core.

If this is possible, are there limits to how many threads I can start,
  or any other limitations.

I wouldn't spawn hundred of threads to perform this job, because it might happen that handling a lot of threads can take even more time because your CPU and disk will be too busy.

A: Task based approach can be a solution, control your task based on available
resources.
        DirectoryInfo d = new DirectoryInfo(@"D:\Test");
        FileInfo[] Files = d.GetFiles("*.txt");
        foreach (FileInfo file in Files)
        {
           //Check items in ConcurrentDictionary, if exceeds the limit -
           //wait here

            Task t = Task.Factory.StartNew((Object o) =>
            {
              //Do your work
            }, file);

            //Add items in ConcurrentDictionary;
        }


text:
Q: How to calculate a sum of sequence e^(-x) with accuracy E=0.0001? So I can calculate a sum of sequence without accuracy E.
    int t=1, x, k;
    float sum, a, result, factorial=1, E=0.0001;
    for(k=0;k<=(n);k++){
                while(t<=n){
                        factorial*=t;
                        t++;
                }
                sum=(pow(-x,k))/factorial;
                sum+=sum;
                //while(fabs(sum-???)<E){
                //        result=sum;
                //}
    }

So I know sum of sequence sum(k). But to calculate with accurace E, I must know sum of previous elements sum(k-1). How to get sum(k-1) from for loop?
Sorry for english.

A: is this a taylor series for e ^ (-x) ?  if so you've written it out wrong.  i don't think what you've got will converge.
http://www.efunda.com/math/taylor_series/exponential.cfm
e ^ (-x) is 1 + (-x) + (-x)^2/2! + (-x)^3/3! + ...
double calculate_power_of_e(double xx, double accuracy) {
    double sum(1.0);
    double term(1.0);
    for (long kk=1; true; ++kk) {
        term *= (-xx) / kk;
        sum += term;
        if (fabs(term) < accuracy)
            break;
    }

    return sum;
}

printf("e^(-x)" = %.4f\n", calculate_power_of_e(5.0, .0001));

A: First a remark about the power formula that you apply:  according to wikipedia you should add the terms pow(-x,k)/(k!) and not pow(-x,k)/(n!).
This leads to a small optimisation of your code: as k! = k * (k-1)!  we can avoid the inner while loop and a lot of useless multiplications.
By the way, there is also an error in the way you build the sum:  you always erase the previous result, and then add a second time the current term.
Once this is corrected, you just have to take care of an additional variable:
double myexpo(double x, int n=100) {
    int k;
    double sum = 1.0, pvsum, factorial = 1.0, E = 0.0001;
    for (k = 1; k <= (n); k++){  // start with 1
        pvsum = sum;
        factorial *= k;            // don't calculate factorial for 0.
        sum += (pow(-x, k)) / factorial;

        if (k > 1 && fabs(sum - pvsum) < E) {  // check if diff is small enough
            cout << k << " iterations" << endl;
            break;     // interupt the for loop if it's precise enough
        }
    }
    return sum;   // at the end of the loop sum is the best approximation
}

You can test this function with this:
double x;
do {
    cout << "Enter number: ";
    cin >> x;
    cout << myexpo(x) << endl;
    cout << exp(-x) << endl;
} while (x > 0);

Remark:  I'd suggest to either use double or to use the f suffix for the float litterals (e.g. 0.001f), even if it works as is.

A: Check when the absolute value of the term becomes smaller than your desired accuracy.
double sum = 0, x = 1, k = 0, E = 0.0001, fact = 1;
while(true){
    double term = pow(-x, k) / fact;
    if(fabs(term) < E)
        break;
    sum += term;
    fact *= (++k);
}
printf("e^(-x) = %.4f", sum);

A: When the term is insignificant compare to 1.0, stop looping.
By using recursion, and |x| is not too big, the smallest terms are summed first.
e(x) = 1 + x/1! + x*x/2! + x*x*x/3! + ...

double my_exp_term(double x, double term, unsigned n) {
  if (term + 1.0 == 1.0) return term;
  n++;
  return term + my_exp_term(x, term*x/n, n);
}

double my_exp(double x) {
  return 1.0 + my_exp_term(x, x, 1);
}

double y = my_exp(-1);

Exponential function


text:
Q: Ordered sets. Let $(A, \le_A)$ and $(B, \le_B)$ be ordered sets. Let $(A, \le_A)$ and $(B, \le_B)$ be ordered sets.
(a) Prove or disprove: if both $A$ and $B$ are dense, then so is $A \times B$ with
the product ordering
(b) Prove or disprove: if both $A$ and $B$ are dense, then so is $A \times B$ with
the lexicographic ordering.


text:
Q: Default vue-cli build do not create css file When I build my project, I can not find any css file. Unlike the documentation says.
vue-cli-service build --target lib --name myLib ***

I have three files : umd, umd.min and common.
And un message : "Images and other types of assets omitted".
Is there a special vuecli configuration to do?
I am experiencing this problem since I add unit tests in the project

A: I had the same problem recently and the following solutions worked for me:

*

*Import the CSS file in the app entry, in my case, src/App.vue:
import './assets/scss/main.scss';

*Change the build command in the package.json file to target the entry file that imports the style:
vue-cli-service build --target lib --name index src/App.vue"

*Run npm run build or yarn run build.

*Voilà!

The CSS file will appear.


text:
Q: Backbone.js rendering delay? Im new to backbone and there is one problem I cant figure out. I use backbone with require.js. When I want to render some view for the first time (when I reload page in browser) index.html shows up immediately but then it is hidden for about 2 seconds and then showed again with rendered templates. If I then navigate between views (without hitting refresh) it works smooth, but that initial render does something wrong. Here is my code:
View:
define(['jquery','underscore','backbone', 'text!../../../templates/home/HomeView.tpl'],
function($, _, Backbone, HomeTemplate)
{
var HomeView = Backbone.View.extend(
{
    events:{
    },

    render: function ()
    {
        var template = _.template(HomeTemplate);
        this.$el.html(template);

        return this;
    }

});

return HomeView;
});

Router:
define(['jquery','underscore','backbone'],
function($, _, Backbone)
{
var container = $("#container");

var AppRouter = Backbone.Router.extend(
{
    routes:
    {
        "": "home"
    },

    home: function()
    {
        require(['views/home/HomeView'],
        function(HomeView)
        {
            var Home = new HomeView({el: container});
            Home.render();
        });
    }

});

var initialize = function()
{
    var app_router = new AppRouter();

    Backbone.history.start();
};

return { initialize: initialize };

});

I get no error in console. Is this behavior normal?

A: It is normal.
RquireJs loads the dependencies via http requests and these requests do have timeouts. Additionally in browsers there is a limit for maximum parallel downloads. These delays can easily add up to 2 seconds at startup combined with network latency.
If You want to minimize this delay, minimize the files with r.js as mentioned in RequireJS docs.
EDIT: If minify won't solve the problem, a browser profiling tool can help You.


text:
Q: Importing multi-module project into Android Studio I have a project that was made a while ago with a beta version of Android Studio. The project had two modules, one of which was an Android app, and the other an App Engine endpoints module. Both modules use gradle. The project was backed up using git.
Since I moved to another computer, I've been trying to import the project with the same structure from git into Android Studio. I can't get AS to recognise the module structure though. If I import directly from version control then AS doesn't see the gradle modules, and it's just one module with a bunch of sub packages. Then it won't let me import the modules as they already exist.
Can anyone help?


text:
Q: Google Maps won't show up I'm working on a project which involves a "Points of Interest" locator. I have a generated Google Maps API v2 key and I've added all the proper permissions to the AndroidManifest (as you'll see below), and everything compiles...except for the map itself! There's a marker that shows your current location and as well as the GPS coordinates but not the map, which needless to say is essential. Also there are no runtime erros except that the LogCat says at points "There is too much output to process". Any help would be greatly appreciated.
Android Manifest
    package="com.example.kavin_000.travelapplication" >
    <!-- suppress AndroidDomInspection -->
    <uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="19" />

    <permission
        android:name="com.example.kavin_000.travelapplication.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.example.kavin_000.travelapplication.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/nyit_icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".ow_main_page"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name=".manhattan_main_page"
            android:label="@string/title_activity_manhattan_main_page" >
        </activity>
        <activity
            android:name=".main_page"
            android:label="Travel Application" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".ow_campus_points_of_interest"
            android:label="@string/title_activity_ow_campus_points_of_interest" >
        </activity>
        <activity
            android:name=".manhattan_campus_points_of_interest"
            android:label="@string/title_activity_manhattan_campus_points_of_interest" >
        </activity>

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="MY_KEY" />

    </application>

</manifest>

Layout XML file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".ow_main_page"
    android:background="#ffffb502">

    <fragment
        android:id="@+id/googleMap"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment"
        android:layout_above="@+id/latlongLocation" />

    <TextView
        android:id="@+id/latlongLocation"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom"
        android:layout_alignParentBottom="true"
        android:background="#ff058fff"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:textColor="#ffffffff"
        android:paddingLeft="5dp"
        android:paddingRight="5dp" />

</RelativeLayout>

Java class in question
package com.example.kavin_000.travelapplication;

import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.TextView;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class ow_campus_points_of_interest extends FragmentActivity implements LocationListener {

    GoogleMap googleMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //show error dialog if GooglePlayServices not available
        if (!isGooglePlayServicesAvailable()) {
            finish();
        }
        setContentView(R.layout.activity_ow_campus_points_of_interest);
        SupportMapFragment supportMapFragment =
                (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.googleMap);
        googleMap = supportMapFragment.getMap();
        googleMap.setMyLocationEnabled(true);
        LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        Criteria criteria = new Criteria();
        String bestProvider = locationManager.getBestProvider(criteria, true);
        Location location = locationManager.getLastKnownLocation(bestProvider);
        if (location != null) {
            onLocationChanged(location);
        }
        locationManager.requestLocationUpdates(bestProvider, 20000, 0, this);
    }

    @Override
    public void onLocationChanged(Location location) {
        TextView locationTv = (TextView) findViewById(R.id.latlongLocation);
        double latitude = location.getLatitude();
        double longitude = location.getLongitude();
        LatLng latLng = new LatLng(latitude, longitude);
        googleMap.addMarker(new MarkerOptions().position(latLng));
        googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
        googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
        locationTv.setText("Latitude:" + latitude + ", Longitude:" + longitude);
    }

    @Override
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub
    }

    private boolean isGooglePlayServicesAvailable() {
        int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
        if (ConnectionResult.SUCCESS == status) {
            return true;
        } else {
            GooglePlayServicesUtil.getErrorDialog(status, this, 0).show();
            return false;
        }
    }
}

A: It sounds like there may be an issue with your authorization on Google App Engine. Did you make sure to use the SHA1 fingerprint from your debug.keystore and not from your release keystore? Additionally, make sure that you are appending ;com.example.kavin_000.travelapplication to the end of the SHA1 fingerprint.
If you have not added your SHA1 fingerprint to the list of authorized applications, that is the issue. It can be done by finding your debug.keystore file (search on Google depending on your OS), and running the following command:
keytool -list -v -keystore debug.keystore


text:
Q: String Interpolation with Text View and Textfield in Swiftui Hi I'm wondering if there's any way to have string interpolation with a textfield and Text in Swiftui. Like
Text("hi \(TextField("Enter your name", $name)")

A: You can try below code
struct ContentView: View {
    @State private var name = ""
    var body: some View {
        VStack{
            TextField("Enter your name", text: $name)
            Text("Hi \(name)")
        }
    }
}

Hope this is what you want

A: If you really want to do that you can put your statements in an Hstack like so:
import SwiftUI

struct SwiftUIView: View {
    @State var name = ""
    var body: some View {
        HStack {
            Text("Hi")
            TextField("Name", text: $name)
                .frame(width: (name.isEmpty ? 45 : 0) + CGFloat(name.count) * 9)
            Text("blabla")
        }
    }
}

Note: This gives you a dynamic change, but not a perfect one Because the size of each character is different you will get a bigger whitespace at the end. I just choose 9 here, for char width. I still think having a extra Textfield and using the variable then later, is the better option.