calculus and analysis – Solving integral involving absolute value of a vector

enter image description hereI am trying to integrate the following in mathematica:
$int_0^r frac{exp(-k_d(|vec{r}-vec{r_j}|+|vec{r}-vec{r_i}|)}{|vec{r}-vec{r_j}|times|vec{r}-vec{r_i}|}r^2dr$.
I have first defined, the following functions,
$vec p(x,y,z)= (x-x_j)hat i + (y-y_j)hat j+(z-z_j)hat k$
Similarly,
$vec q(x,y,z)= (x-x_i)hat i + (y-y_i)hat j+(z-z_i)hat k$.
And,
$vec r(x,y,z)=xhat i + yhat j+zhat k $
Then I clicked the integration symbol in the classroom assistant panel and typed the integrand in the $expr$ portion. While typing this, I have used $Abs$ to take modulus of the functions $vec p(x,y,z)$ and $vec q(x,y,z)$ . I have included the limits as $0$ to $Abs(r)$ and the $var$ as $r$ in the integration symbol.
But when I press( Shift + Enter ) no output value is shown . Can anyone tell me where I have made mistake ?

Time Complexity of inserting a vector to a vector of vectors in C++

I was solving a question on LeetCode, where I had to generate all possible subsets of a given set of numbers.

Although, the solution makes sense to me, I am unable to understand the derivation of time complexity for those solutions.

A solution I found there was:

class Solution {
public:
    vector<vector<int>> subsets(vector<int>& nums) {
        vector<vector<int>> subs = {{}};
        for (int num : nums) {
            int n = subs.size();
            for (int i = 0; i < n; i++) {
                subs.push_back(subs(i));  <---- LINE X
                subs.back().push_back(num); <---- LINE Y
            }
        }
        return subs;
    }
}; 

It is an iterative solution to solve the problem.
What I don’t understand is the time complexity of the given solution and more importantly, the complexities of Line X and Line Y.

Does copying subs(i) take O(n) time and then pushing back take another O(n) time, or is it an O(1) step?

nt.number theory – In how many ways to generate a vector with odd/even entries

Let $bar v=(k_1, ldots k_n)$ be a vector with entries $k_i$ from ${0, ldots, K}$ with $K in N$ and such that $sum_{i=1}^n k_i=K.$

Find in how many ways we can generate vector $bar v$ so that:

  1. it contains even number of odd values of $k_i$; odd number of even values of $k_i$
  2. it contains even number of odd values of $k_i$ equal to each other.

data structures – What is the difference between python list and c++ vector?

Both python list and c++ vector are implemented as dynamic arrays (https://en.wikipedia.org/wiki/Dynamic_array).
(Essentially arrays that get reallocated when they are too small.)
Now the important difference between the python and c++ version don’t come from the data structures themselves, but rather from the language. In c++ you can store structs, primitive data types pointers etc. in a vector. But in python everything is a pointer in the sense that an e.g. an integer is stored in the heap and it has an annotation attached to it that says “i am an integer”. That’s required because python has a dynamic type system. And the elements stored in the list are only pointers to the actual elements. This mechanism also allows python to store different data types in the same list. This is another reason why python is kinda slow.

c++ – problems with for and vector in the optimization

I have created a program where I first set the size of the array and
how many times I will look for consecutive values, then I fill in the
array and finally I insert the consecutive values, it should look for
the least consecutive value it finds in the array.

consecutive value means the sum of the elements in the array
consecutively.

example:

7 4 // Array size and consecutive values

6 4 2 7 10 5 1 // arrangement

1 3 4 2 // Consecutive values

Answer = 1,12,19,6

Explanation

The lowest element of the array is the one in the last position which
is 1, the answer is equal to 1.

the lowest segment is the one furthest to the left 6 4 2, the sum of
which equals 12.

the answer is obtained by choosing segment 6 4 2 7, which equals 19.

there are two segments with a minimum cost equal to 6, segments 4 2
and 5 1.

How can it be improved?

#include<iostream>
#include<vector>
using namespace std;

vector<int>recorrido, base;
int suma_elementos(int elemento);
int consecutivo;

int main() {
    int a, b, valor, final = 9999999, total = 0;
    cin >> a >> b;

    for (int i = 0; i < a; i++)
    {
        cin >> valor;
        recorrido.push_back(valor);
    }

    for (int i = 0; i < b; i++)
    {
        cin >> valor;
        base.push_back(valor);
    }



    for (int i = 0; i < b; i++)
    {
        suma_elementos(base(i));

        for (int j = 0; j < consecutivo; j++)
        {
            for (int c = 0; c < base(i); c++)
            {
                total += recorrido(c + (j));
            }

            if (total < final)
            {
                final = total;
            }
            total = 0;
        }
        cout << final << " ";
        //reset
        consecutivo = 0;
        final = 99999999;
        total = 0;
    }

    return 0;
}

//Suma de elementos
int suma_elementos(int elemento)
{

    int proporcion = recorrido.size();

    while (proporcion >= elemento)
    {
        proporcion--;
        consecutivo++;
    }
    //cout << consecutivo << " ";
    return 0;
}

linear algebra – Reference on classifying real subspaces of complex vector spaces (based on restricted complex structure)

Every complex vector space can also been seen as real vector space. If we now choose a real subspace, it may not be a complex subspace (in particular, if it is of odd real dimension).

If the complex vector space was equipped with an inner product (for example, a Hilbert space), we can restrict the imaginary unit (also known as linear complex structure) to any real subspace using the orthogonal projection. We can then classify the types of real subspaces based on the spectrum of this “restricted complex structure”. In particular, if the restricted complex structure squares to minus identity, i.e., is itself a complex structure, the real subspace is also a complex subspace. In general, the spectrum encodes how being a complex subspace is violated.

I worked this out for myself, but I’m confident that this is standard material in linear algebra of complex vector spaces. However, the standard introductory text books that I checked do not discuss real subspaces of complex vector spaces and their classification in the above way.

Do you know of a standard reference that I could cite when discussing this (in particular, the above mentioned classification based on the spectrum of the restricted complex structure)?

at.algebraic topology – Realizing Stiefel-Whitney classes via vector bundles

Let $X$ be a CW complex. If $E$ is a vector bundle over $X$, then it’s well-known that the Stiefel-Whitney classes $w_j(E) in H^j(X,mathbb F_2)$ of $E$ are determined from the classes $w_{2^k}(E)$ (for $2^k leq j$) via the Wu formula, using the cup product and the action of the Steenrod algebra.


Question 1: Does the Wu formula imply any further relations? This is a purely algebraic question which I make more precise in (a) and (b) below.

That is, let $H$ be a nonnegatively-graded $mathbb F_2$-algebra with an unstable action of the Steenrod algebra satisfying the Cartan formula and $Sq^{|x|}(x) = x^2$ for all homogenenous $x in H$. Let $W$ be the set of sequences $(w_j in H^j)_{j in mathbb N}$ with $w_0 = 1$ and satisfying the Wu formla.

(a) For any sequence $(v_{2^k} in H^{2^k})_{k in mathbb N}$, does there exist $w in W$ (necessarily unique) with $w_{2^k} = v_{2^k}$ for all $k in mathbb N$?

Presumably (i) the Whitney sum formula and (ii) the universal formula for the Stiefel-Whitney classes of a tensor product of vector bundles are compatible with the Wu formula, so that $W$ is a commutative ring using (i) for addition and (ii) for multiplication.

(b) Is $W$ a polynomial algebra on whichever generators from (a) do exist?


Question 2: What restrictions beyond the Wu formula are there restricting the Stiefel-Whitney classes of a vector bundle $E$ on a CW complex $X$? This is a genuinely topological question.

Over here Mark Grant describes one such restriction, but ideally I’d like a more systematic discussion.


If it simplifies matters to assume that $X$ is finite, or even a compact manifold, then that’s fine.

c – Formar ascendente de un vector

tengo un pequeño error con el método de la burbuja que no está ordenando de formar correcta los números, de forma mayor a menor no tengo problema pero de menor a mayor sí.

Ya revise los for y no veo el error, gracias.

int FomraDes(int mat(), int a)
{
    int i,j,d;
    a = 0;
    for (i = 0; i <(a-1); ++i)
    {
        for (j = 0 ; j < (a-i-1); ++j)
        {
            if (mat(d) > mat(d+1))
            {
                a=mat(d);
                mat(d)=mat(d+1);
                mat(d+1) = a;
            }
        }
    }
}

int EscribirMat (int mat(), int a)
{
    int i;
    for (i = 0; i < a; ++i)
    {
        printf("%i", mat(i));
        printf("n");
    }
}

programming challenge – C++, sort integers using knowledge of entire vector

I am solving the “Sort” problem on Kattis.

Mirko is a great code breaker. He knows any cipher in the world can be broken by frequency analysis. He has completely the wrong idea what frequency analysis is, however.
He intercepted an enemy message. The message consists of N
numbers, smaller than or equal to C.
Mirko belives freqency analysis consists of sorting this sequence so that more frequent numbers appear before less frequent ones.
Formally, the sequence must be sorted so that given any two numbers X
and Y, X appears before Y if the number of times X appears in the original sequence is larger than the number of time Y does. If the number of appearances is equal, the number whose value appears sooner in the input should appear sooner in the sorted sequence.
Help Mirko by creating a “frequency sorter”.
Input
First line of input contains two integers, N (1≤N≤1000), the length of the message, and C (1≤C≤1000000000), the number from the task description above.
The next line contains N positive integers smaller than or equal to C, the message itself.

Basically, the problem is as follows. Let xs be a nonempty vector of positive integers. There are only few integers in this vector, but they have a big range. (The maximum value c is given in the problem, but my code does not use the information.) Sort the integers according to the following criteria.

  1. For any two elements x and y of xs, if x occurs more often than y, then x appears first; if y appears more often, y appears first.
  2. If x and y appear equally often, then x occurs first if the very first occurrence of x is earlier than that of y.

I use a comparison sort (provided by the C++ runtime) with a smart comparator. This comparator knows the frequency and the index of the first appearance of every element. This information is not inherent to the integers. Rather, it depends entirely on their location within the vector. This contextual information is generated when a comparator is created for a given vector. Upon application on elements x and y, it returns true if x must appear before y.

I have used custom comparators before, but never have I used anything that contains state. In the disassembly with -Os I see many copy and move constructors called under sort(vector<unsigned> &). The code passes all tests, and it’s not slow.

But I wonder why the disassembly reveals so many copy and move calls, and whether this pattern of using heavy comparators is discouraged in C++. If this looks like a known pattern, I want to know its name. I appreciate general comments and insights.

#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <iostream>

typedef std::vector<unsigned> vector;

/// Comparison based on knowledge of the entire vector
struct compare {
    std::multiset<unsigned> bag;
    std::map<unsigned, size_t> indices;

    /// Extract frequency and initial index of every element.
    explicit compare(vector const &xs) {
        for (size_t i = 0u; i < xs.size(); ++i) {
            unsigned const x = xs(i);
            bag.insert(x);
            if (!indices.count(x)) {
                indices(x) = i;
            }
        }
    }

    /// True if `x` must go before `y`.
    ((nodiscard)) bool operator()(unsigned x, unsigned y) const {
        return bag.count(x) > bag.count(y)
               || (bag.count(x) == bag.count(y) && indices.at(x) < indices.at(y));
    }
};

static void sort(vector &v) {
    compare c(v);
    std::sort(v.begin(), v.end(), c);
}

int main() {
    vector v;
    {
        // Get `n` unsigned integers from console.
        // Unused: `c` (upper bound for integers)
        unsigned n, c;
        std::cin >> n >> c;
        v.reserve(n);
        while (n--) {
            unsigned x;
            std::cin >> x;
            v.push_back(x);
        }
    }
    // Sort according to the problem description
    sort(v);
    // Print all
    for (unsigned const x : v) {
        std::cout << x << ' ';
    }
    return 0;
}

I will Draw Vector art for your photo for $5

Dear sir madam,
Thanks for visit. I will Draw Vector art for your photo.

Basic Order > Vector Art ” only face” + High Quality + unlimited revisionHave a nice day

by: Kvnish
Created: —
Category: Art & Design
Viewed: 173


.