Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

Hello,
I am trying to write a program that will return a partial or complete list of points on an elliptic curve.
In order to do this using examples provided to me, the command "msqrt" was used, which would return FAIL if the conditions were not met.
However, as I am using Maple 2018, this was replcaed with "ModularSquareRoot" which returns an error message.
My question; Is there anyway to circumvent this error message, as it is really causing me a lot of headache. Thanks.

This should be pretty simple. 

    with(Units:-Standard);
    local var::Unit(kg);     #generates a warning
    var := 1;
    var;                     #-> 1 kg... alas this doesn't work (it's just 1)

In other words, I want to declare a variable with an unknown quantity and known `Unit` at the outset similar to how things are done in C-style languages, and later set the numeric value. The goal is to make it easier to manipulate functions that deal with lots of different physics unit types without having to write them each individual line. For example on lines 10-13 I manually include the units when it would be more convenient if they were already tied to the variable they're associated with.

Solving a simple physics problem to find the radius of a planet with the universal gravitational constant & known density:

I know types exists in Maple, i.e. 

    evalfr := proc(expr, iexact::integer := 0) 
      if   0 < iexact   then  return convert(evalf(expr), rational, iexact); 
      elif iexact = -1  then  convert(evalf(expr), rational, exact); 
      else                    return convert(evalf(expr), rational); 
    end if; end proc

This just being a wrapper with `iexact` typed as an `integer` setting up a set of conditionals around `evalf` to rationalize an expression when using `ScientificConstants`.

I've considered using anonymous functions to emulate this behavior with setters and getters, but that seems like overkill for something that is probably builtin. For the time being I have configured my worksheet so it references secondary variables, 

    var := var2*Unit(kg)

This strikes me as somewhat inelegant. Also trying to use the same variable name in-line (i.e. `var := var*Unit(kg)`) gives `Error, recursive assignment`.

I am curious if there is a correct Maple way to do something like this. Or would I have to implement some sort of anonymous function to get the behavior I want? Appreciate any help!

  [1]: https://i.stack.imgur.com/ovZSB.png

Dear all

I have data and a vector d. 
I would like to sum the elements of the vector d corresponding to the index  of the element data <=0.01 

Step 1: we select the index of data that corresponds to data<=0.01

step 2: we select the consecutive index corresponding to data<=0.01

Step 3 : we sum the element of d corresponding to the previous index

step 4: update d=d/number(index) ;

Please see my attached code. It's done by hand how can reformulate the code.

 

 

code_vector.mw

many thanks

 

Hi - High school teacher 

I'm using the with(Physics): Setup(mathematicalnotation=true):with(Physics[Vector]): libraries which gives elegant answers to some of the questions of elementary vector algebra. 

But I become stuck when I try to simplify a simple expression like

Equa[01]:=AC_ = AB_ + BC_:Equa[01];                            #AC_ = AB_ + BC_
Equa[02]:={AB_=2*DB_,BC_=2*BE_}:Equa[02];
Equa[03]:=subs(Equa[02],Equa[01]):Equa[03];                
#AC_ = 2*DB_ + 2*BE_
simplify(Equa[03]);                                                              #also try combine

which gives

AC_ = 2*DB_ + 2*BE_

rather than what I was hoping for

AC_ = 2*DE_

I have define a type and build a clumsy addition procedure - with no hope of overloading '+'

###########################
# TYPE VecPos (Vecteurs liés)
#
###########################
`type/VecPos`:=proc(Exp)
    local LstExp:
    LstExp:=convert(Exp,string):
   if length(LstExp)=3 and LstExp[-1]="_" then
     true
   else
     false
   fi:
 end proc:
###########################
# TYPE AddVecSub (addition de vecteur subsécants)
#
###########################
AddVectSubs:=proc(Exp)
local va,vb,a,b:
  if patmatch(2*Exp,a::realcons*va::VecPos+b::realcons*vb::VecPos,'Corr') then
    a:=subs(Corr,a)/2:                  b:=subs(Corr,b)/2:
    va:=convert(subs(Corr,va),string):  vb:=convert(subs(Corr,vb),string):
    if a < 0 then
      va:=convert(cat(va[2],va[1],va[3]),string);
      a:= -a;
    fi;
    if b < 0 then
      vb:=convert(cat(vb[2],vb[1],vb[3]),string);
      b:= -b;
    fi;  
  fi;
 
  if va[2]=vb[1] then
    if a > b then
      return b*convert(cat(va[1],vb[2..3]),symbol)
         + (a-b)*convert(va,symbol);
    elif b > a then
      return a*convert(cat(va[1],vb[2..3]),symbol)
         + (b-a)*convert(vb,symbol);
    else
      return a*convert(cat(va[1],vb[2..3]),symbol)
    fi
  elif vb[2]=va[1]  then
    if a > b then
      return b*convert(cat(vb[1],va[2..3]),symbol)
          + (a-b)*convert(va,symbol);
    elif b > a then
      return a*convert(cat(vb[1],va[2..3]),symbol)
         + (b-a)*convert(vb,symbol);
    else
      return a*convert(cat(vb[1],va[2..3]),symbol)
    fi
  else
    return Exp
  fi
end proc:

 

But I am sure that their exist a better solution - which if possible should remain within the Physics[Vector] library. It is hard enough to convince high school student to use maple. Maybe adding rule in the setep... I just don't have the required time to look around.

Any help would be appreciated.

Thank

Jean-Marc Roy

Note:

patmatch(2*AB_ + 2*BC_,a::realcons*va::VecPos+b::realcons*vb::VecPos,'Corr');Corr;Corr:='Corr':

work, but neither

patmatch(AB_ + BC_,a::realcons*va::VecPos+b::realcons*vb::VecPos,'Corr');Corr;Corr:='Corr':
patmatch(AB_ + BC_,va::VecPos+vb::VecPos,'Corr');Corr;Corr:='Corr':


return results. Which explain why I mutiply 2*Exp in the addition function.
 

 


 

Hello

I am new to maple. How do you create a transfer function of a time response response of e.g some data in excel, csv etc

Thank you.

Stay safe

Ian

Hi, I am trying to add some useful inverse Laplace transforms to Maple's integral tables. I am frustrated that these transforms will only be recognized  if they are entered in exactly the same format. For example, if I type:

restart;

with(inttrans):

addtable(invlaplace, 1/(s^y*sqrt(a + s^x)), Sum(a^n*sqrt(Pi)*t^(-1 + (1/2 + n)*x + y)/(GAMMA(1/2 - n)*GAMMA(1 + n)*GAMMA(1/2*x + n*x + y)), n = 0 .. infinity), s, t, {a, x, y}, y::Range(-infinity, infinity), x::Range(-infinity, infinity), a::Range(-infinity, infinity));

savetable(invlaplace, `InvlaplaceTable.m`):

Then:

restart;

with(inttrans):

read `InvlaplaceTable.m`:

invlaplace(1/(s^y*sqrt(a + s^x)), s, t);#Ok works for general

invlaplace(1/(s^3*sqrt(a + s^x)), s, t);# Dosen't WORK ?# For y = 3.

invlaplace(1/(s^3*sqrt(s^3 + a)), s, t);# Dosen't WORK ?# For y = 3. and x = 3

value(eval(invlaplace(1/(s^y*sqrt(a + s^x)), s, t), [y = 3, x = 3]))#Workaround !!!

Thanks.

Does anyone here have experience with exporting Maple worksheets to LaTeX?  According to help page

?Export as latex

"You can change the Mathematics Formatting Width to align multi-line displayed formulas by modifying the option in the Export tab of the Options dialog."

That setting, however, seems to have no effect.  The image below shows the result, after setting the line width to (the extremely narrow!) 2 inches.  Long lines still overflow the left and right margins of the paper, rendering the result useless.

I see that this was pointed out in 2016 but there appears to have been no improvements since.  Does anyone know a workaround?  I am running Maple 2020 on Linux, if that matters.

This zip file z.zip contains a Maple worksheet, the exported *.tex file, and the compiled PDF.  Here is what that PDF looks like.

 

 

How can I define a set generated by two degree n polynomials with binary coefficients?

For example: for n=2, I want to generate the set {(a_0*x_0+a_1*x_1)* (b_0*y_0+b_1*y_1) s.t. a_0,a_1,b_0,b_1 are binary}. 

Thank you in advance.

I'm trying to upload a file to Maple Cloud for the first time, but I am getting an error due to the way I use libraries.

The first lines of the startup code in the sheet look like this.

libname := "S:/Maple/NODE_Library", libname;
with(NODETreMaterial);
with(NODETreTverrsnitt);

The libraries are on a network drive on our server.

The question is - how can I solve this? Would it be better to somehow upload those libraries to Maple Cloud (no idea how to do that by the way), or can it be solved in a different way?

 I want to compute a function W for certain values of x < π/2. W is a ratio of 2 positive values -they are squares-computed using dsolve and that ratio seems to be negative when evalf is applied to the answer.!!!  The true answer (without the evalf) are positive. Also, applying evalf to the correct answers does not produce those silly negative answers. Any suggestions? I would prefer uplaod my file but do not know how>

Here is the file:

This worksheet has a system of ode's ( a second order and a first order), a power series solution near 0 to use for inital conditions, and a function W of the vairables that I want to compute for certain values of x < π/2. W is a ratio of 2 positive values and that ratio seems to be negative when evalf is applied to the answer.!!! The true answer (without the evalf) are positive. Also, applying evalf to the correct answers does not produce those silly negative answers.

  • >  restart;

  • >  alias(B=b(x));alias(Bp=diff(b(x),x));alias(f=F(x));alias(fp=diff(F (x),x));alias(fpp=diff(F(x),x,x));

    B B, Bp

    B, Bp, f B, Bp, f, fp

    B, Bp, f, fp, fpp

  • >  eq1 := sin(x)*(1+B*cos(x)^2)*fpp-(2*((f^2-2*B)*cos(x)^2-f^2+3*B* (1/2)-1))*cos(x)*fp+2*sin(x)*((f^2-3*B*(1/2))*cos(x)^2-f^2+(1/2)* B-1/2)*f = 0;eq2 := (-B*cos(x)^6+(B-1)*cos(x)^4+cos(x)^2)*fp^2+2*f* cos(x)*sin(x)*(cos(x)-1)*(cos(x)+1)*(1+B*cos(x)^2)*fp+cos(x)*sin(x) *Bp+B*cos(x)^6*f^2-(2*(B-1/2))*f^2*cos(x)^4+B*cos(x)^2*f^2-f^2+B = 0;

    eq1 sinx 1 Bcosx2fpp 2 f2 2Bcosx2 f2 3B 1cosxfp 2

    2sinx f2 3B cosx2 f2 B 1 f=0 222

    eq2 Bcos x 6 B 1 cos x 4 cos x 2 fp2 2fcos x sin x cos x
    1 cosx 1 1 Bcosx2 fp cosx sinx Bp Bcosx6f2 2 B

    1 2

(1)

f2cos x 4 Bcos x 2f2 f2 B=0 > f2p:=solve(eq1,fpp);

f2p

(2)

(3)

1 2sin x f3cos x 2 sin x 1 Bcos x 2

2cos x 3fpf2
3sinx fBcosx2 4cosx3fpB 2sinx f3 2cosx fpf2 sinx fB

3cosx fpB sinx f 2cosx fp

  • >  fs:=x^8*(127/604800*C+653/17010*(C^5)+2/81*(C^7)+773/1020600*(C^3)) +x^6*(17/5670*(C^3)-4/81*(C^5)+31/15120*C)+x^4*((1/9)*C^3+7/360*C)+ (1/6)*x^2*C+C:

  • >  Bs:=x^6*(20/189*(C^4)+4/315*(C^2))+4*x^4*C^2*(1/45)+2*x^2*C^2*(1/3) :

  • >  Digits:=15:

  • >  ic:=(c)->{F(1e-5)=subs([x=1e-5,C=c],fs),D(F)(1e-5)=subs([x=1e-5,C= c],diff(fs,x)),b(1e-5)=subs([x=1e-5,C=c],Bs)}:

> nans:=dsolve({eq1,eq2} union ic(c),{f,B},numeric,stiff=true,

(4)

> parameters=[c]);

nans proc x_rosenbrock ... end proc

(4)

(5) (6)

> W:=fp^2*cos(x)/f^2;

W fp2 cos x f2

> Wp:=simplify(subs(fpp=f2p,diff(W,x)));

cosxsinx 1 Bcosx2fp2 f27Bcosx4 f25B3cosx2fpcosxf2

1

1
Wp f3sin x 1 Bcos x 2 4fp 2 f 4

444

3B cosx2 f2 B 1 f2sinx 222

  • >  k:='k': for k from 4 to 5 do nans(parameters=[k]); evalf(eval([W, Wp], nans(Pi/2-1e-10)),5); end do;

    c = 4.
    482.73, 1.3965 10
    8

    c = 5.
    5.6838 10
    6, 1.4948 1013

  • >  k:='k': for k from 4 to 5 do nans(parameters=[k]); eval([W,Wp],

    nans(Pi/2-1e-10)); end do;

    c = 4. 0.0131412243081803, 1.31416436948280 108

    c = 5.
    154.729383663460, 1.54702786932958 10
    12

  • >  evalf([0.0131412243081803, -1.31416436948280*10^8],5);

    0.013141, 1.3142 108

(7)

(8) (9)

 

Hi, after solving an equation and inserting it in the original equation the result is not equal to zero!!

What is the problem?

in the attached file below I obtained 'q' and then I put it in the eq (3), but the result is not zero!!

Please help me.

555.mw

I am looking for an elegant way in which to find a vector that is perpendicular to another vector.  The attached worksheet shows one method, but this can result in a divide by zero error.  I could write a procedure to detect and avoid the divide by zero error, but this feels like a sledgehammer to crack a nut :-)

Another method might be to rotate the vector by PI/2, but I'm not sure how to do this.

Any suggestions would be gratefully received!

Perpendicular_Vectors.mw

 

 

 

Hi, 
I need do generate a large number of matrices (always with the same dimensions) whose each column is a random sample of a different random variable.
I wrote a rather simple procedure to do that (see below a notional example). Let T and S the time and the memory size required for a single execution of this procedure, then its execution N times needs a time N*T and a size N*S.
If time is not a problem, the increase in memory size is extremely constraining.
How should I write this procedure in order that N executions of it use a memory of the order of S and not N*S?
 

Download Not_Efficient.mw

 

 

First 558 559 560 561 562 563 564 Last Page 560 of 2218