Items tagged with translation

Hello;

Maple can't translate this valid Mathematica expression, it gives error

restart;
with(MmaTranslator):
eq:=FromMma(`x^2(a+y[x])^2 y'[x]==(1+x^2)(a^2+y[x]^2)`);

Error, (in MmaTranslator:-FromMma) The form, a^b^c, is found in the expression. It means either (a^b)^c or a^(b^c). Please use parentheses to clarify the meaning


But there is nothing wrong with the above expression. It is valid Mathematica expression. I found why Maple is confused. It needed a SPACE after the first x^2. So the following works in Maple

eq:=FromMma(`x^2 (a+y[x])^2 y'[x]==(1+x^2)(a^2+y[x]^2)`);

And now the error went away.  But a space not needed in Mathematica. It works either way.

Maple 2016.1 on windows.

 

 

Let us consider 

MmaTranslator:-FromMma(" Table[0,{n=10},{m=2}]");

[seq([seq(0,i=1..(m := 2))],j=1..(n := 10))]

The above result is syntactically incorrect in Maple language. The translation should be 

Matrix(10,2)
#or
[seq([seq(0,i=1.. 2)],j=1..10)]

up to the Mmma's result

Table[0, {n = 10}, {m = 2}]

{{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0,0}, {0, 0}}

Another bug is as follows.

MmaTranslator:-FromMma("Sinc[x]");

Sinc(x)

whereas the expected result is piecewise(x=0,1,sin(x)/x) up to http://reference.wolfram.com/language/ref/Sinc.html

In general, the MmaTranslator package is outdated. It often returns working Mma's commands as incorrect (Concrete examples are long and need a context. These may be exposed on demand.). The question arises about the quality of other Maple translations. 

how to translate python code which use scipy, numpy to maple code

 

 

import numpy as np
from scipy.sparse.linalg import svds
from functools import partial


def emsvd(Y, k=None, tol=1E-3, maxiter=None):
    """
    Approximate SVD on data with missing values via expectation-maximization

    Inputs:
    -----------
    Y:          (nobs, ndim) data matrix, missing values denoted by NaN/Inf
    k:          number of singular values/vectors to find (default: k=ndim)
    tol:        convergence tolerance on change in trace norm
    maxiter:    maximum number of EM steps to perform (default: no limit)

    Returns:
    -----------
    Y_hat:      (nobs, ndim) reconstructed data matrix
    mu_hat:     (ndim,) estimated column means for reconstructed data
    U, s, Vt:   singular values and vectors (see np.linalg.svd and 
                scipy.sparse.linalg.svds for details)
    """

    if k is None:
        svdmethod = partial(np.linalg.svd, full_matrices=False)
    else:
        svdmethod = partial(svds, k=k)
    if maxiter is None:
        maxiter = np.inf

    # initialize the missing values to their respective column means
    mu_hat = np.nanmean(Y, axis=0, keepdims=1)
    valid = np.isfinite(Y)
    Y_hat = np.where(valid, Y, mu_hat)

    halt = False
    ii = 1
    v_prev = 0

    while not halt:

        # SVD on filled-in data
        U, s, Vt = svdmethod(Y_hat - mu_hat)

        # impute missing values
        Y_hat[~valid] = (U.dot(np.diag(s)).dot(Vt) + mu_hat)[~valid]

        # update bias parameter
        mu_hat = Y_hat.mean(axis=0, keepdims=1)

        # test convergence using relative change in trace norm
        v = s.sum()
        if ii >= maxiter or ((v - v_prev) / v_prev) < tol:
            halt = True
        ii += 1
        v_prev = v

    return Y_hat, mu_hat, U, s, Vt

Construction of arabesques of melodic line BACH

Elena, Liya "Construction of arabesques of melodic line BACH", Kazan, Russia, school#57
       
> restart:
> with(plots):with(plottools):

      The setting and visualization of line BACH: B - note b-flat, A - note la, C - note do, H - note si.
> p0:=plot([[0,1],[2,0],[4,1.5],[6,1]],thickness=4,color=cyan,scaling=constrained);
>
>   p0 := PLOT(
>
>         CURVES([[0, 1.], [2., 0], [4., 1.500000000000000], [6., 1.]])
>
>         , SCALING(CONSTRAINED), THICKNESS(4), AXESLABELS( ,  ),
>
>         COLOUR(RGB, 0, 1.00000000, 1.00000000),
>
>         VIEW(DEFAULT, DEFAULT))
>
> plots[display](p0);
> r_i:=seq(rotate(p0,i*Pi/4),i=1..8):
> p1:=display(r_i,p0):plots[display](p1,scaling=constrained);

> c1:=circle([0,0],6,color=blue,thickness=2):
> plots[display](c1,p1,scaling=constrained);
> p_c:=plots[display](c1,p1,scaling=constrained):

> pt_i_2:=seq(translate(p1,0,2*6*i),i=0..4):
> plots[display](pt_i_2,scaling=constrained);
> pt_i_22:=seq(translate(p1,0,6*i),i=0..4):
> plots[display](pt_i_22,scaling=constrained);
> pt_i_222:=seq(translate(p1,0,1/2*6*i),i=0..4):
> plots[display](pt_i_222,scaling=constrained);

> pr:=rotate(p1,Pi/8):
> plots[display](pr,scaling=constrained);
> plots[display](p1,pr,scaling=constrained);
> pr_i:=seq(rotate(p1,Pi/16*i),i=0..8):
> plots[display](pr_i,scaling=constrained);


> pt_1:=translate(p1,0,2*6):
> pr_1_i:=seq(rotate(pt_1,Pi/3.5*i),i=0..6):
> plots[display](pr_1_i,scaling=constrained);
> pr_11_i:=seq(rotate(pt_1,Pi/5*i),i=0..10):
> plots[display](pr_11_i,scaling=constrained);
> pr_111_i:=seq(rotate(pt_1,Pi/6.5*i),i=0..12):
> plots[display](pr_111_i,scaling=constrained);


Elena, Liya "Designing of islamic arabesques", Kazan, Russia, school #57


> restart:
      At the theorem of cosines  c^2 = a^2+b^2-2*a*b*cos(phi);
      In our case  c=a0 ,  a=1 ,  a=b , phi; - acute angle of a rhombus (the tip of the kalam).
      s0 calculated at theorem of  Pythagoras.
     (а0 - horizontal diagonal of a  rhombus, s0 - vertical diagonal of a  rhombus)
> a:=1:phi:=Pi/4:
> a0:=sqrt(a^2+a^2-2*a^2*cos(phi));

                       a0 := sqrt(2 - sqrt(2))

> solve((s0^2)/4=a^2-(a0^2)/4,s0);

                sqrt(2 + sqrt(2)), -sqrt(2 + sqrt(2))


      The setting of initial parameters : the size of the tip of the pen-kalam and  depending on its - the main module size - point
       (а0 - horizontal diagonal of a  rhombus, s0 - vertical diagonal of a  rhombus)
> a0:=sqrt(2-sqrt(2)):
> s0:=sqrt(2+sqrt(2)):
      Connection the graphical libraries Maple
> with(plots):with(plottools):
      Construction of unit of measure (point) - rhombus - the tip of the kalam
> p0:=plot([[0,0],[a0/2,s0/2],[0,s0],[-a0/2,s0/2],[0,0]],scaling=constrained,color=gold,thickness=3):
> plots[display](p0);

The setting and construction of altitude of alif - the basis of the rules compilation of the proportions      Example, on style naskh altitude of alif amount five points
> p_i:=seq(plot([[0,0+s0*i],[a0/2,s0/2+s0*i],[0,s0+s0*i],[-a0/2,s0/2+s0*i],[0,0+s0*i]],scaling=constrained,color=black),i=0..4):
> pi:=display(p_i):
> plots[display](p_i);
The setting of appropriate circle of diameter, amount altitude of alifd0:=s0+s0*i:
> i:=4:
> d0:=d0:
> c0:=circle([0,d0/2],d0/2,color=blue):
> plots[display](p_i,c0);


Construction of flower by turning "point"r_i:=seq(rotate(p0,i*Pi/4),i=1..8):
> p1:=display(r_i,p0):plots[display](p1,scaling=constrained);

 The setting of circumscribed circlec1:=circle([0,0],s0,color=blue,thickness=2):
      Construction and the setting of flower inscribed in a circle
> plots[display](c1,p1,scaling=constrained);
> p_c:=plots[display](c1,p1,scaling=constrained):

The setting and construction of arabesque by horizontal parallel transport original flower with different stepspt_i_1:=seq(translate(p1,5*a0*i,0),i=0..4):
> plots[display](pt_i_1);
> pt_i_11:=seq(translate(p1,2*a0*i,0),i=0..4):
> plots[display](pt_i_11);
> pt_i_111:=seq(translate(p1,a0*7*i,0),i=0..4):
> plots[display](pt_i_111);

 The setting and construction of arabesque by vertical parallel transport original flower with different stepspt_i_2:=seq(translate(p1,0,2*s0*i),i=0..4):
> plots[display](pt_i_2);
> pt_i_22:=seq(translate(p1,0,s0*i),i=0..4):
> plots[display](pt_i_22);
> pt_i_222:=seq(translate(p1,0,1/2*s0*i),i=0..4):
> plots[display](pt_i_222);
 Getting arabesques by turning original flower on different anglespr:=rotate(p1,Pi/8):
> plots[display](pr);
> plots[display](p1,pr);

> pr_i:=seq(rotate(p1,Pi/16*i),i=0..8):
> plots[display](pr_i);


> pt_1:=translate(p1,0,2*s0):
> pr_1_i:=seq(rotate(pt_1,Pi/3.5*i),i=0..6):
> plots[display](pr_1_i);
> pr_11_i:=seq(rotate(pt_1,Pi/5*i),i=0..10):
> plots[display](pr_11_i);
> pr_111_i:=seq(rotate(pt_1,Pi/6.5*i),i=0..12):
> plots[display](pr_111_i);


hi

if possible to convert matlab file in to maple fie program??convert_to_maple_program.txt

thanks

 

this is the matlab is it possible to rewrite it in simple maple code

J = rand()+1e-10;

function [M, num, E] = ising(N,J)

B = 0;

M = []; % The total magnetic field of the system

E = []; % The total energy of the system

randTol = 0.1; % The tolerance, dampens the spin flip process

% First we generate a random initial configuration

spin = (-1).^(round(rand(N)));

% Then we let the system evolve for a fixed number of steps

for i=1:1000,

% Calculating the total spin of neighbouring cells

neighbours = circshift(spin, [ 0 1]) + ...

circshift(spin, [ 0 -1]) + ...

circshift(spin, [ 1 0]) + ...

circshift(spin, [-1 0]);

% Calculate the change in energy of flipping a spin

DeltaE = 2 * (J*(spin .* neighbours) + B*spin);

% Calculate the transition probabilities

p_trans = exp(-DeltaE);

% Decide which transitions will occur

transitions = (rand(N) < p_trans ).*(rand(N) < randTol) * -2 + 1;

% Perform the transitions

spin = spin .* transitions;

% Sum up our variables of interest

M = sum(sum(spin));

E = -sum(sum(DeltaE))/2; % Divide by two because of double counting

% Display the current state of the system (optional)

image((spin+1)*128);

xlabel(sprintf('J = %0.2f, M = %0.2f, E = %0.2f', J, M/N^2, E/N^2));

set(gca,'YTickLabel',[],'XTickLabel',[]);

axis square; colormap bone; drawnow;

end

% Count the number of clusters of 'spin up' states

[L, num] = bwlabel(spin == 1, 4);

############################# 

In that attached file is a multip step problem that involves graphing a right circular cylinder using transtion matrices and orthonormal basis. I have completed the hole question minus the very last part which is asking for new parametric equations for the cylinder if its center point is located at (-2, 10, 3) instead of the origin.

Any ideas on how to do this will be greatly appreciated.

 

question_4.mw

Page 1 of 1