how to define unit vectors in mathematica

I’m struggling a little bit trying to understand how to address this problem, I would like to do this in mathematica: problem is just that I don’t know how to do the dot product between J and ay because I don’t know how to define the unit vector ay, is it possible to do this in mathematica? thanks in advance!

number representation – How would one add Hyperreals as a new type to Mathematica?

Hyperreals are an extension to the real numbers; they formalise the concepts of infinities and infinitestimals as numbers, rather than the named limit points outside of the system of reals and form the basis of non-standard analysis.

Hyperreals area analogous to Complex numbers in that a hyperreal can be be expressed as a pair {r, h} where r is the Real part and h the hyperreal part, e.g. {1, $epsilon$}, {1, $omega$}, {1, 2 $omega$}, {1, $omega^2$}, etc.

A search suggests that there is currently no support for hyperreals in Mathematica, either from Wolfram directly or as a user demonstration or other package.

How would one go about defining the hyperreals, arithmetic operations, relations (<, >, =, !=, etc.), etc. so that they could be handled like any other number kind, and in particular sorted, so that given the list ${1, epsilon, epsilon^2, omega -1, omega -2 }$ the result of sorting it would be ${0, epsilon^2, epsilon, 1, omega -2, omega -1 }$?

I believe that any function of the reals can be extended straightforwardly to the hyperreals (in which context Łoś’ theorem and the transfer principle are referenced, but I am not mathematically sophisticated enough to assert their relevance).

To be specific:

  • How would one define the symbols $epsilon$ and $omega$?
  • How would one extend the definitions of basic arithmetic functions (+, -, *, /, ^) to handle hyperreals?
  • How would one extend magnitude and equality relationships accordingly?

(I would ask whether, alternatively, the scope of application is so great, e.g. as arguments in exponentials, polynomials, calculus, etc. that only Wolfram could do such a thing – but that would be largely a matter of option, so I won’t.)

Wolfram Mathematica is not showing this matrix operation in matrix form

I hope you can help me with this.
I’ve defined two matrix, i and T, and I want to operate them this way:

enter image description here

but, as you may see, it simply shows the sum of the two matrices.

I don´t know what could it be.

How can I use "find selection" in mathematica?

I want to use find selection functionality in Mathematica and I found some articles saying it could be accessed by Ctrl + E. However, nothing happens when I try Ctrl + E. The normal find by Ctrl + F does work.
I searched for a while, but I couldn’t find the solution, for everyone does not seem to have the problem as such.
How can I use find selection in Mathematica?

I use Mathematica version 12.0.0 and Windows 10.

Any information would be appreciated.

factorization – Can Mathematica factor multivariate polynomials with 4 or more variables? And with high degrees (>10)

The Mathematica documentation clearly states

the Wolfram Language routinely factors degree-100 polynomials in 3 variables

I’m interested in factoring systems of polynomials in as many as 10 or 20 variables. The systems I have are sparse in the sense that if there are 20 variables then likely no more than 3-6 variables will appear per equation and there will likely only be two terms per equation. I’ve used Solve to test on some small systems with success. To be clear, we don’t actually need to factor the polynomials necessarily. If we factor them, then we have what we need. What we really want are the roots to the system with respect to the symbolic coefficients. Solve worked for some small test systems. Factor would also work for a single polynomial, but we need a system of polynomials and I don’t see that Factor will take a system.

I’ve looked at papers by searching and it seems our problem is a solved problem in mathematics. Algorithms seem to exist for such a problem, but I’m even unclear on this since the papers are too densely packed with math for me to easily understand.

Any help would be appreciated.

Convert Pascal to Mathematica?

Need help to transfer a program from to Wolfram Mathematica. Can anybody translate this code to Mathematica?

conversion – Python to Mathematica code bug

I have an assignment in Mathematica, which I’ve already solved using Python and it’s a bit hard to convert the code. Here’s what I have done so far:

def sigmoid(x): # define the sigmoid function
    return 1/(1+np.exp(-x))

def pos_list(node): # returns the neighborhood of node, A is a matrix of adjacency
    return np.nonzero(A(node))(1)  

def neg_list(node): # returns nodes that are not neighbors
    return np.where(A(node)==0)(1)

I have these in Mathematica:

sigmoid(x_) := 1 / (1 + Exp(-x))
M := AdjacencyMatrix(undirectedEdges) (* this is A from above*)
posList(n_) := M((n))("NonzeroPositions")
negList(n_) := Flatten(Position(Normal(M((n))), x_Integer /; x = 0))

Now there is a longer function:

def next_choice(v,t,p,q):
    positive = pos_list(v)
    li = np.array(())
    for pos in positive:
        if pos==t:
            li = np.append(li,1/p)
        elif pos in pos_list(t):
            li = np.append(li,1)
        else :
            li = np.append(li,1/q)
    prob = li/li.sum()
    return np.random.choice(positive,1,p=prob)(0)

So I am stuck here. This is what I’ve written:

nextChoice(v_, t_, p_, q_) := 
 Module({li, vpositive, tpositive, len, i, prob},
  li = List();
  vpositive = posList(v);
  tpositive = posList(t);
  len = Length(vpositive);
  For(i = 1, i <= len, i++,
   If(vpositive((i))((1)) == t, AppendTo(li, 1/p), 
     If(Length(AnyTrue(tpositive, # == vpositive((i))((1)) &) > 0), 
      AppendTo(li, 1), AppendTo(li, 1/q)));
  prob = li/Total(li);
  Return(RandomChoice(prob -> vpositive, 1)((1)))

This list li only has one element and I cannot figure out why it doesn’t go through all the if statements. any ideas?

numerical integration – Mathematica can’t seem to handle Truncated BinormalDistribution when there is non-zero correlation coefficient

I would like to use Mathematica to analyze (e.g., compute moments, plot, etc) a truncated bivariate normal distribution. For example:

d = BinormalDistribution({0,0},{.5,1},.5);
dTruncated = TruncatedDistribution({{-.5,Infinity},{0,2}},d)

When I run this code, though, Mathematica begins evaluating and never stops (I ran it all night and nothing). I don’t get any error messages. Same when I try to plot the PDF of dTruncated or sample points from the distribution.

I’m running Mathematica v 11.2 with Windows 10.0 on a 4.6GHz Intel i9 processor with 64Gb RAM, so I don’t think it’s a processing speed issue.

The problem only seems to occur when the correlation coefficient is non-zero. When I run the same code as above but just make the correlation coefficient in BinormalDistribution = 0, it works fine:

d = BinormalDistribution({0,0},{.5,1},0);
dTruncated = TruncatedDistribution({{-.5,Infinity},{0,2}},d)

This immediately spits out an answer. I have tried numerous combinations of parameter values, and it only ever works when the correlation coefficient equals 0. Unfortunately, that’s not very helpful for me.

There is an R package that does this easily (see here and here) in a few lines of code:

> library(tmvtnorm)
> mu <- c(0, 0)
> sigma <- matrix(c(.5, .5, .5, 1), 2, 2)
> a <- c(-0.5, -Inf)
> b <- c(0, 2)
> moments <- mtmvnorm(mean=mu, sigma=sigma,
> lower=a, upper=b)

Any assistance with this would be very much appreciated!

Grid alignment syntax – Mathematica Stack Exchange

This is a simple question, but I just cannot understand the explanation given in the Grid documentation page for how to set different alignments for different parts of a grid. I have a grid with two rows with four columns each, and I would like the top row to be bottom aligned and the bottom row to be top aligned. Or, in general, I want to specify one alignment per row (again, for a two row grid). How do I do this?

coordinate transformation – How to troubleshoot TransformedField functionality in Mathematica?

I list up this method to transform a complex function to Cartestian form, which can be used on virtually any function:

such as:

u0(r_, phi_) := Sum(I^(-n) BesselJ(n, r) Exp(I n phi), {n, -5, 5});

TransformedField("Polar" -> "Cartesian",  u0(r, phi), {r, phi} -> {x, y})

which yields:

  u0(x_, y_) := 
 BesselJ(0, Sqrt(x^2 + y^2)) + 
  1/(x^2 + y^2)^(5/2)
    2 (-I x (x^2 + y^2)^2 BesselJ(1, Sqrt(x^2 + y^2)) + 
      Sqrt(x^2 + y^2) (-x^4 + y^4) BesselJ(2, Sqrt(x^2 + y^2)) + 
      I x^5 BesselJ(3, Sqrt(x^2 + y^2)) - 
      2 I x^3 y^2 BesselJ(3, Sqrt(x^2 + y^2)) - 
      3 I x y^4 BesselJ(3, Sqrt(x^2 + y^2)) + 
      x^4 Sqrt(x^2 + y^2) BesselJ(4, Sqrt(x^2 + y^2)) - 
      6 x^2 y^2 Sqrt(x^2 + y^2) BesselJ(4, Sqrt(x^2 + y^2)) + 
      y^4 Sqrt(x^2 + y^2) BesselJ(4, Sqrt(x^2 + y^2)) - 
      I x^5 BesselJ(5, Sqrt(x^2 + y^2)) + 
      10 I x^3 y^2 BesselJ(5, Sqrt(x^2 + y^2)) - 
      5 I x y^4 BesselJ(5, Sqrt(x^2 + y^2)))


a Hankel and Bessel function together:

u(r_, phi_) :=  Piecewise({{BesselJ(1.5 r, 5)*Exp(I 5 phi), 
0 < r < 1/2}, {(BesselJ(3 r, 5) + BesselY(3 r, 5))*Exp(I 5 phi), 
1/2 < r < 1}, {HankelH1(r, 5)*Exp(I 5 phi), r > 1}})

which yields:


which yields the respective given plots, when plotted:




However, my supervisor thinks these plots look “strange”.

How can I verify that the TransformedField command did the right job – for such extended functions?

In other words, how to trobleshoot TransformedField?