Items tagged with arguments

Feed App Center

Some mathematical functions and also some (not so) inert functions are implemented as objects.
For example, Perm is used to represent permutations.

p :=Perm([2,3,1,5,4]);  # ==> disjoint cycles representation
        p:=(1,2,3)(4,5);
lprint(p);
Perm([[1, 2, 3], [4, 5]])
    
Perm acts as an inert function (like RootOf) but it's an object.
Is it possible to convert it into a true inert form such as PERM([[1, 2, 3], [4, 5]]) and so, being able to extract the arguments with op?  

In this specific case we may use
convert(p, disjcyc);
       [[1, 2, 3], [4, 5]]
    
but this is possible only because Perm has a convert export.
So, is it possible to obtain the arguments directly (without convert)?
This would be useful for other situations.

I would like to add threads to this code that compiles cleanly:

RECTmatrixSEQ :=  (FD,m, n, xw, yw, tr, k, rho, dmax) ->
 
   [seq
     (seq
        # A return of 0 means there is no choice - no digit possible
        # result of a 4 means there is a choice of (-1 or 0)
        (add(RECTpred(m, n, i, j, iter1, k, rho)*(2*abs(iter1)+1), iter1 = -dmax .. dmax)
        + (2*dmax+1)*(RECTpredR(m, n, i, j, dmax, k, rho)+
        RECTpredL(m, n, i, j, -dmax, k, rho))+
        .5*RECTpredOR(m, n, i, j, dmax, k, rho)+
        .5*RECTpredOL(m, n, i, j, -dmax, k, rho),
      i = -ceil(2*dmax+2*rho)*2^m .. ceil(2*dmax+2*rho)*2^m-1),
    j = 0 .. 2^(n-yw)-1)]:

I've added thead calls like this, still no syntax errors:

RECTmatrixSEQ :=  (FD,m, n, xw, yw, tr, k, rho, dmax) ->

   CodeTools:-Usage( Threads:-Wait(
   [seq (Threads:-Create
     (seq
        # A return of 0 means there is no choice - no digit possible
        # result of a 4 means there is a choice of (-1 or 0)
        (add(RECTpred(m, n, i, j, iter1, k, rho)*(2*abs(iter1)+1), iter1 = -dmax .. dmax)
        + (2*dmax+1)*(RECTpredR(m, n, i, j, dmax, k, rho) +
        RECTpredL(m, n, i, j, -dmax, k, rho))+
        .5*RECTpredOR(m, n, i, j, dmax, k, rho)+
        .5*RECTpredOL(m, n, i, j, -dmax, k, rho),
      i = -ceil(2*dmax+2*rho)*2^m .. ceil(2*dmax+2*rho)*2^m-1),
    j = 0 .. 2^(n-yw)-1)) ] )
    ):

 

I do get a runtime error:

                 "PROC:feasibilitycheckproONCE

                   "
Error, (in CodeTools:-Usage) invalid input: too many and/or wrong type of arguments passed to Threads:-Create; first unused argument is j = 0 .. 3

Any help spotting this problem would be appreciated. Thanks in advance.

Bonnie

 

I'm trying to verify whether the result obtained from a recursive Legendre function that I defined is the same as that obtained from the function available in Maple.

The arguments for LegendreP() mentioned seem to be v,x where v is the algebraic expression's degree and x is the expression. I tried calling the function as LegendreP(6,x) since I am to obtain the value at n=6 but this statement is not giving me an output in return that I can use to compare.

Would I have to plot both functions in order to be able to compare them?

 

Hi experts

 

In a procedure with no declared parameteres I would like to return (print) the passed arguments (expecting Matrix structures) in a modified form along with the name of the symbol holding the structure passed as arguments.

 

That is, the procedure just iterates through the _passed arguments in a for-loop to display the name of the the passed argument (the symbol), a colon and then the modified matrix structure.

My problem is that when looping from i to _npassed arguments, refering to _passed[i] gives me the evaluated form.Tat is what I need to modify the structure but not to list the symbol name.

 

Say I wanted to print a transposed version of my passed matrices. Then I would call

M:=<<1,2>|<3,4>>;

myProc(M);

And the result I want would be

M: <<1,3>|<2,4>>

But I don't know if _passed holds the symbol names or just the evaluated versions of the passed arguments??

And theoretically the passed argument (assuming a matrix) could be the matrix structure put directly in the procedure call, in which case there is no symbol to refer to.

 

I hope you get my question and can help me out.

 

Thanks

Simon

 

b := 1;

h := 1;

A := b*h;

E := 210*10^9;

qr := 100;

Dp := (1/12)*E*b*h^3;

R := 20;

teta := 3;

sys1 := {(E.A+Dp/R^2)*(diff(u(t), `$`(t, 2))) = -E*A*(diff(w(t), t))/R+Dp*(diff(w(t), `$`(t, 3)))/R, -Dp*(diff(w(t), `$`(t, 4))) = E*A*(diff(u(t), t))/R-Dp*(diff(u(t), `$`(t, 3)))/R+E*A/R-100};

dsolve(sys1);

#THİS GAVE ME THE RESULTS LİKE THAT:

{u(t) = (1/4801)*_C3*(-1+sqrt(4801))^(3/2)*exp(-(1/20)*sqrt(-1+sqrt(4801))*t)-(1/4801)*_C4*(-1+sqrt(4801))^(3/2)*exp((1/20)*sqrt(-1+sqrt(4801))*t)-(1/4801*I)*_C5*(1+sqrt(4801))^(3/2)*exp(-(1/20*I)*sqrt(1+sqrt(4801))*t)-(1/4801)*_C6*(-1+sqrt(4801))^(3/2)*exp((1/20)*sqrt(-1+sqrt(4801))*t)+(1/4801)*_C3*sqrt(-1+sqrt(4801))*exp(-(1/20)*sqrt(-1+sqrt(4801))*t)-(1/4801)*_C4*sqrt(-1+sqrt(4801))*exp((1/20)*sqrt(-1+sqrt(4801))*t)+(1/4801*I)*_C5*sqrt(1+sqrt(4801))*exp(-(1/20*I)*sqrt(1+sqrt(4801))*t)-(1/4801)*_C6*sqrt(-1+sqrt(4801))*exp((1/20)*sqrt(-1+sqrt(4801))*t)-(104999999/105000000)*t+_C1, w(t) = _C2+_C3*exp(-(1/20)*sqrt(-1+sqrt(4801))*t)+_C4*exp((1/20)*sqrt(-1+sqrt(4801))*t)+_C5*exp(-(1/20*I)*sqrt(1+sqrt(4801))*t)+_C6*exp((1/20)*sqrt(-1+sqrt(4801))*t)}

#SO THERE ARE 6 UNKOWN(C1...C6) SO I NEED 6 CONDITION. MY BOUNDRY CONDITIONS:

bs := u(0) = 0, (D(u))(0) = 0, w(0) = 0, (D(w))(0) = 0, w(teta) = 0, (D(w))(teta) = 0;

> r := dsolve({bs, sys1});
%;
Error, (in dsolve) invalid arguments; expected an equation, or a set or list of them, received: {{-17500000000*(diff(diff(diff(diff(w(t), t), t), t), t)) = 10500000000*(diff(u(t), t))-875000000*(diff(diff(diff(u(t), t), t), t))+10499999900, 210043750000*(diff(diff(u(t), t), t)) = -10500000000*(diff(w(t), t))+875000000*(diff(diff(diff(w(t), t), t), t))}}
>

I tried to change the equations row. But ı dont understand where something wrong.I tried so many times. May u please find where ıt is wrong? 

 

Say I have the following loops:

for C from 1 to 10 do
    r:=[]:
    for K from 2 to 10 do
    r:=[op(r),2*K+2*C-3];
    end do:
    print(r);
end do:

for C from 1 to 10 do
    r:=[]:
    for K from 2 to 10 do
    r:=[op(r),K*C+K+C-2];
    end do:
    print(r);
end do:

I wonder how could I write a procedure, say use expressions "2*K+2*C-3" and "K*C+K+C-2" as input arguments?

so I can call up like :

 

myfun(K*C+K+C-2) or myfun("K*C+K+C-2")

myfun(2*K+2*C-3)

 

I dont care whether the output(s) are lists, tables, or matrices.

My main difficulty is to get the expression to be procedure inputs.

Though if the output can be a  10 by 9 matrix, it's better.

Thanks,

 

casper

 

Regards,

I have a very large equation which has an arctan(x,y). I need to be able to extract the arguments x,y and assign them in some variables.

I have tried the solution given here.

Unfortunately, that solution only works for constants, not equations.

For example, if I use the proc given in there with arctan(10,11) it works. But if I use something like arctan...

How would I write a procedure that extracts what is under a squareroot sign? For example given the expression 1+2*\sqrt(x+1) the procedure should return x+1.

 

Best regards,

henriqo

Hello, It is possible in Maple to change the values of the arguments passed to a procedure. For example, look at the following procedure: f := proc(x) x := 7; print(x); end; Now you can say f(y); which would print "y" and set the value of y to 7. But then subsequently executing f(y); would give an "illegal use of a formal parameter", since y evaluates to 7 (so the assignment would result in an "invalid left hand side of assignment"). Two questions:
Page 1 of 1