Items tagged with proc proc Tagged Items Feed

I have a formula, which is called the cube law. It requires input between 0 <= x <= 1. When creating  a procedure I run into all kinds of problems and get nothing but error codes. Trying to use assume works, it puts a tilde mark on the variable x, but doesn't restrict the input. Here is the formula the way it is writtin in a book on calculus:

f(x) := x^3/x^3+(1-x)^3 (0 <= x <= 1).

Trying to restrict the input to be restricted as required by the relational statement has been proven fruitless.

Any help would be greatly appreciated, thanks,

Rolf.

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

 

Mytest:=module()
    option package;
    
    export
        mymain
        ;
        
        
    # local a,b,c;

    uses LinearAlgebra;
    
    interface(rtablesize=infinity);
    
    
    mymain:=proc(n::integer)

        local ans;
        
        ans:=Vector(n);

        return ans;

    end proc;

end module;

Here is a short piece of code to create a Maple package. It runs fine. Is that possible to hide the code from print() ?

 

with(Mytest);

print(mymain); # which displays the source code

 

Could I hide some of the code? Say I want to use the function mymain() for debugging purpose, but I dont want to make it local to the package. Instead I keep it in "export", but I dont want users to see its code.

 

Thanks!

test.mw

Hello. As you can see the minimum of set X is 2.

the time pair in set W whose difference is 2 corresponds to elements 54 and 55. How do i locate and print these automatically?

Digits:=4:

U := [1.010, 1.110, 1.210, 1.310, 1.410, 1.510, 1.610, 1.710, 1.810, 1.910, 2.020, 2.120, 2.220, 2.320, 2.420, 2.520, 2.620, 2.720, 2.820, 2.920, 3.030, 3.130, 3.230, 3.330, 3.430, 3.530, 3.630, 3.730, 3.830, 3.930, 4.040, 4.140, 4.240, 4.340, 4.440, 4.540, 4.640, 4.740, 4.840, 4.940, 5.050, 5.150, 5.250, 5.350, 5.450, 5.550, 5.650, 5.750, 5.850, 5.950, 6.060, 6.160, 6.260, 6.360, 6.460, 6.560, 6.660, 6.760, 6.860, 6.960, 7.070, 7.170, 7.270, 7.370, 7.470, 7.570, 7.670, 7.770, 7.870, 7.970, 8.080, 8.180, 8.280, 8.380, 8.480, 8.580, 8.680, 8.780, 8.880, 8.980, 9.090, 9.190, 9.290, 9.390, 9.490, 9.590, 9.690, 9.790, 9.890, 9.990, 10.01, 11.11, 12.21]:

W := select(proc (t) options operator, arrow; .59 >= frac(t) end proc, U);

[1.010, 1.110, 1.210, 1.310, 1.410, 1.510, 2.020, 2.120, 2.220, 2.320, 2.420, 2.520, 3.030, 3.130, 3.230, 3.330, 3.430, 3.530, 4.040, 4.140, 4.240, 4.340, 4.440, 4.540, 5.050, 5.150, 5.250, 5.350, 5.450, 5.550, 6.060, 6.160, 6.260, 6.360, 6.460, 6.560, 7.070, 7.170, 7.270, 7.370, 7.470, 7.570, 8.080, 8.180, 8.280, 8.380, 8.480, 8.580, 9.090, 9.190, 9.290, 9.390, 9.490, 9.590, 10.01, 11.11, 12.21]

(1)

X:=[seq(trunc(W[i+1])*60+frac(W[i+1])*100-(trunc(W[i])*60+frac(W[i])*100),i=1..nops(W)-1)];

[10.00, 10.00, 10.00, 10.00, 10.00, 11.00, 10.00, 10.00, 10.00, 10.00, 10.00, 11.00, 10.00, 10.00, 10.00, 10.00, 10.00, 11.00, 10.00, 10.00, 10.00, 10.00, 10.00, 11.00, 10.00, 10.00, 10.00, 10.00, 10.00, 11.00, 10.00, 10.00, 10.00, 10.00, 10.00, 11.00, 10.00, 10.00, 10.00, 10.00, 10.00, 11.00, 10.00, 10.00, 10.00, 10.00, 10.00, 11.00, 10.00, 10.00, 10.00, 10.00, 10.00, 2.00, 70.00, 70.00]

(2)

NULL

min(X),{W[54],W[55]};

2.00, {9.590, 10.01}

(3)

 



Download test.mw

The following MWE shows what I mean:

with(Physics):Setup(mathematical=true):

Setup(noncommutativeprefix={MX,MY,MZ});

test:=proc()

    local eq;

    eq:=-Commutator(MX,MY)-Commutator(MZ,MY);

    eq:=simplify(subs(MX=-MZ,eq));

    return eq;

end proc:

 

test();  # yields -[-MZ,MY] - [MZ,MY]

 

%  # yields 0

 

 

Any ideas how I can solve this? I would like to return the simplified version.

I am considering to write a wrapper for plot and related commands (could redefine the commands or introduce a new name) which facilitates export of Maple plots to postscript. The command should interpret some of the options and remove them from the options sequence before submitting the remaining ones to the original plot().
E.g. it should recognize a title="TITLE" parameter and process TITLE (e.g. write it to a specific file). Similarly I would want to be able to pass additional parameters, e.g. filename="FILE" in order to specify how the output file name should be set. Is this a sensible approach. How can I realize this detailed option 'parsing' in Maple?

Hi all,
I am writing a procedure that I would like to have several outputs. The code is as follows:

Initialize := proc (p, theta, PiV, PiU, n, m)

J := CompJ(PiU, m);

for i to n do

if member(i, V) then

Ai[i] := CompAi(PiU, PiV, i, n, J)

end if

end do

end proc

The function calls other functions previously defined that are not important here. Basically I would like to return the set J and the list Ai, but I am not sure on how to do it. 

Once the procedure returns these elements, I would like to assign them to some variables. I am not sure on how this can be done when a function returns more than one thing.

Thanks in advance for the help
Bests
Manuele 

Sorry if this has been already posted.

 

When print() is invoked from a proc into a module, non-English characters are not properly displayed with Maple 18.

It works ok if it is invoked from within the workbook.

 

Example:
print("Están en perspectiva")

Put this sentence in a proc into a module and the character "á" wont be displayed

Output: "Est�n en perspectiva"

Any hint about how to treat this issue?

Thank you very much.

César Lozada 

 

 

Hi,

I want to display the matrix M, I used return M, in this procedure, but no matrix M displayed.

restart;
N:=2:
N:=2;
ff:=proc(N)
local M,i,p;
M:=array(1..2*N+1,1..2*N+1):
for i from 1 to 2*N+1 do
for  p from 1  to 2*N+1  do
   if p=1 then M[p,i]:=-2;
    elif  p=2*N+1  then M[p,i]:=-3;
else
M[p,i]:=0;
end if; end do; end do;
return M;
end proc;

 

Many thinks


firstly apologies in advance for stuff in this question such as "triangle symbol",  my computer is pretty old. 


ok so i was confused a bit here, what i'm trying to do is write a maple procedure that computes Af for a given f contained in V . except we only need to correct the bug in the script below. This script demonstrates such a procedure in the case that omega is a square. The domain is given here as the negative set of a function F contained in V .  I have left in notes where/what i think we need to do but i dunno how to...

N:=10 ; # Global Var
F:=(x,y)->sgn(abs(x-N/2)+abs(y-N/2)-N/4);
Average := proc(F, f0) local f, i, j;
f := f0; # !!!!!!!!!!!!!! something is bad here...
for i to N do for j to N do
if F(i, j) < 0 then
f[i, j] := (f0[i - 1, j] + f0[i + 1, j] + f0[i, j + 1] + f0[i, j - 1])/4 ;
end if;
end do;end do;
return f;
end proc;
f0:=Matrix(N,F); # just to have something to test the procedure
Average(F,f0); # does not return the expected average, modifies f0

 

the necessary information we were given to produce this so far was..

Let N be a positive integer and [N] = {i contained in N | 1<= i <=N }  Let "Omega" C {(i,j) contained in [N] x [N] | 2<=i,j<=N-1} be a subset. Let V = R^([N]x[N]) be the vector space of real valued functions [N]x[N] -> R
and A, "triangle symbol":V->V (average) and "triangle symbole" (Laplacian) be the linear maps such that
[Af](i; j) = f(i; j)      if (i; j) not contained in "Omega"   OR

                             [f(i, j + 1) + f(i, j - 1) + f(i + 1, j) + f(i - 1, j)]/4 if (i,j) is contained in "Omega"

["traingle symbol"f](i,j) =  0 if (i,j) isnt contained in "Omega"   OR

                            ( f(i,j) - [f(i, j + 1) + f(i, j - 1) + f(i + 1, j) + f(i - 1, j)]/4 )    if (i,j) is contained in "Omega"

 Please and thank you for any help in advance <3

                           

 


Dear the specialst in programmation, please I need to put a conditon if in this procedure with this form: Can you correct me this code please. Thank you.


aaa:=proc(x,y,f,N)
local bb,
for i= from 1 to N do

bb[i]:=f(x[i],y);

if bb[i]<=2 then y:=3*x[i] else y::=x[i]^2end if ;

end do:

end proc

 

 

Dear all;

Please I need your help to find the error in my code.

I want to solve an ode, with condition on step size.

ode := diff(y(x), x) = 2*x+y(x);
f:=(x,y)->2*x-y;

analyticsol := rhs(dsolve({ode, y(0) = 1}));
RKadaptivestepsize := proc (f, a, b, epsilon, N)
local x, y, n, h,k,z,R,p;
p:=2;
h := evalf(b-a)/N; ## we begin with this setpsize
x[0] := a; y[0] := 1; ## Initialisation
for n from 0 to N-1 do  ##loop
x[n+1] := a+(n+1)*h;  ## noeuds
k[1] := f(x[n], y[n]);
k[2] := f(x[n]+h, y[n]+h*k[1]);
k[3] := f(x[n]+h/2, y[n]+h/4*(k[1]+k[2]));
z[n+1] := z[n]+(h/2)*(k[1]+k[2]);## 2-stage runge Kutta.
y[n+1] := y[n]+(h/6)*(k[1]+k[2]+4*k[3]);
R:=abs(y[n+1]-z[n+1]); ## local erreur
hstar:=sqrt(epsilon/R)
if R=<=epsilon    then
   x[n] := x[n+1]+h;
   y[n]:=y[n+1];
   n:=n+1;

else

h:=hstar;
end if
 end do;
[seq([x[n], y[n]], n = 0 .. N)];
[seq([x[n], z[n]], n = 0 .. N)];
end proc:

epsilon:=1e-8;
RKadaptivestepsize((x,y)->2*x-y,0,1, epsilon,20)

 

 

so we have to Write a maple function with -> that takes an integer N and a boolean function

F: {(i,j) l 0<= i,j<= N} -> {true,false} 


and returns a list containing all [i,j] such that F(i,j). A procedure that does this
would be


proc(N,F) local i, j, RV;
RV:=NULL;
for i from 1 to N do for j from 1 to N do
if F(i,j) then RV:=RV,[i,j] ; end if ;
end do ; end do ;
return RV ;
end proc ;


The problem is to do this inline, i.e. you have to write
(i,j)-> ...

 

please help...

I am trying some data analysis on an Excel worksheet using Maple. I have the following procedure but I don't know how to make it work for a specific subset of cells (this is a psychological studiy, so I want to have all my scores for each subject, located on the rows, and variable, located on a subset of columns). Example: I want to get an array of all the average scores in a rectangle of cells which goes horizontallyfrom A to AB, and vertically from row 1 to 15. Hope you can help me out! Cheers!

MediaRighe := proc (M) local i, j, r, c, S, N; r := LinearAlgebra:-RowDimension(M); c := LinearAlgebra:-ColumnDimension(M); S := Array(1 .. r); for i to r do S[i] := 0; N := 0; for j to c do if M(i, j) <> "-" then S[j] := S[j]+M(i, j); N := N+1 end if end do; S[i] := S[i]/N end do; return S end proc

I also have this for the columns (same thing, basically):

MediaColonne := proc (M) local i, j, r, c, S, N; r := LinearAlgebra:-RowDimension(M); c := LinearAlgebra:-ColumnDimension(M); S := Array(1 .. c); for j to c do S[j] := 0; N := 0; for i to r do if M(i, j) <> "-" then S[j] := S[j]+M(i, j); N := N+1 end if end do; S[j] := S[j]/N end do; return S end proc

Thanks everybody!

I am a new user of Maple. Could anyone help me to know how to call a Maple function/procedure from a Matlab program with a simple example? And conversely, how to call a Matlab function from Maple.

1 2 3 4 5 6 Page 1 of 6