Items tagged with procedure procedure Tagged Items Feed

What is the best way to export/update multiple values from a single procedure? As far as I understand, a procedure does not let you update global values (the inputs), and it returns the value for the last step performed. Let's say for example, I had a procedure like this:

proc(a,b,c)

local x,y;

*series of steps that use a,b, and c to calculate x and y*

end proc

 

How do I get the results for x and y out of the procedure? 

 

Thanks

Hi, I have this procedure (from Maple 5) but I am using it in Maple 15. My problem is this program can not run. I think there is some commond incorrect, but not sure which ones. Please help me in this problem. Thanks a lot.

cocycle.mw

NULL

Cocycle := proc (L, n) local i, j, k, h, v, u, w, C, eqns, e, f, g; v := vector(n); eqns := {}; u := vector(n); w := vector(n); C := array(antisymmetric, 1 .. n, 1 .. n, []); for i to n do for j from i+1 to n do for k from j+1 to n do for h to n do v[h] := L[i, j, h]; u[h] := L[j, k, h]; w[h] := L[k, i, h] end do; e := array(sparse, 1 .. n, [k = 1]); f := array(sparse, 1 .. n, [i = 1]); g := array(sparse, 1 .. n, [j = 1]); eqns := `union`(eqns, multiply(transpose(e), multiply(C, v)))+multiply(transpose(f), multiply(C, u))+multiply(transpose(g), multiply(C, w)) end do end do end do; print('The*cocycles*are', eqns) end proc

proc (L, n) local i, j, k, h, v, u, w, C, eqns, e, f, g; v := vector(n); eqns := {}; u := vector(n); w := vector(n); C := array(antisymmetric, 1 .. n, 1 .. n, []); for i to n do for j from i+1 to n do for k from j+1 to n do for h to n do v[h] := L[i, j, h]; u[h] := L[j, k, h]; w[h] := L[k, i, h] end do; e := array(sparse, 1 .. n, [k = 1]); f := array(sparse, 1 .. n, [i = 1]); g := array(sparse, 1 .. n, [j = 1]); eqns := `union`(eqns, multiply(transpose(e), multiply(C, v)))+multiply(transpose(f), multiply(C, u))+multiply(transpose(g), multiply(C, w)) end do end do end do; print('The*cocycles*are', eqns) end proc

(1)

NULL

NULL


Download cocycle.m

Hello

It has been years since I last used maple so I apologize if my question makes no sense and my code is outdated (and wrong!).   

I need to write a function (proc) that uses a functional operator inside.  Something like

test:=proc()

local f,vars, func, aux, res;

f:=arg[1]; # a list

vars:=arg[2]: # a list

aux:=op(vars):

func:=aux -> f:  # a function from () to []

res:=func(op(func(aux))):

return(res):

end:

 

This is the basic idea of the proc.  If f:=[y, y*z-x, -15*x*y-x*z-x] and vars:=[x,y,z], the function of a function does not return as it supposes to.  Please tell me what I am doing wrong and how to improve and update the code.

 

many thanks

 

Ed

 

 

 

hi....how i can extract Coefficients  (i.e. {f1[2],f2[2],f2[3],f3[2],.....f3[6]}) from every algebric equations and create matrix A ,in form AX=0, (X are f1[2],f2[2],f2[3],f3[2],.....f3[6] ) then the determinant of the matrix of coefficients (A) set to zero for obtaining unknown parameter omega.?

Note that  if m=3 then 6 equations is appeare and if m=4 then 9 equations is appeare.thus i need a procedure that works for every arbitary value of ''m''.

in attached file below m=4 thus we have 9 equations, i.e. 3 for eq1[k_] and 3 for eq2[k_] and so on...

also we should use boundary conditions for some amount of fi[j] (i=1,2,3 and j=2,3,...,7)

be extacting above Coefficients for example from first equation ,

''**:= (1/128)*f1[2]*omega^2-(1/4)*f2[2]-(1/2)*f2[3]+(1/4)*f2[4]+(1/4)*f3[2]-(1/2)*f3[3]+(1/4)*f3[4]+140*f1[2]-80*f1[3]+20*f1[4]'''

must compute

coeff(**, f1[2]); coeff(**, f2[2]) and so on...

 

 

 

 

 

fdm-maple.mw

 

 ############################Define some parameters

 

 
restart; Digits := 15; A1 := 10; A2 := 10; A3 := 10; A4 := 1; A5 := 1; A6 := 1; A7 := 1; A8 := 1; A9 := 1; A10 := 1; A11 := 1; B1 := 10; B2 := 10; B3 := 10; B4 := 1; B5 := 1; B6 := 1; B7 := 1; B8 := 1; B9 := 1; B10 := 1; B11 := 1; C1 := 10; C2 := 10; C3 := 10; C4 := 1; C5 := 1; C6 := 1; C7 := 1; C8 := 1; C9 := 1; C10 := 1; C11 := 1; C12 := 1; C13 := 1; C14 := 1; C15 := 1; C16 := 1; A12 := 1; B12 := 1; C18 := 1; C17 := 1; C19 := 1; n := 1; U := proc (x, theta) options operator, arrow; f1(x)*cos(n*theta) end proc; V := proc (x, theta) options operator, arrow; f2(x)*sin(n*theta) end proc; W := proc (x, theta) options operator, arrow; f3(x)*cos(n*theta) end proc; n := 1; m := 4; len := 1; h := len/m; nn := m+1
 ############################Define some equation

eq1[k_] := -2*f1[k]*(-A11*n^4+A10*n^2+A12*omega^2)*h^4+(A6*(f2[k-1]-f2[k+1])*n^3+A9*(f3[k-1]-f3[k+1])*n^2-A5*(f2[k-1]-f2[k+1])*n-A8*(f3[k-1]-f3[k+1]))*h^3+(4*(f1[k]-(1/2)*f1[k-1]-(1/2)*f1[k+1]))*(A3*n^2-A2)*h^2+(-A4*(f2[k-2]-2*f2[k-1]+2*f2[k+1]-f2[k+2])*n-A7*(f3[k-2]-2*f3[k-1]+2*f3[k+1]-f3[k+2]))*h+12*A1*(f1[k]+(1/6)*f1[k-2]-(2/3)*f1[k-1]-(2/3)*f1[k+1]+(1/6)*f1[k+2]):
  ``

 

 

 

 

                                     ######################################  APPLY BOUNDARY CONDITIONS

f1[nn+1] := f1[m]:
 

for k from 2 to m do eq1[k_]; eq2[k_]; eq3[k_] end do

-(1/64)*f2[4]+(1/128)*f2[3]+(1/64)*(f3[4]-(1/2)*f3[3])*(omega^2-1)-(1/64)*f1[2]+(1/32)*f1[3]+(1/64)*f1[4]-280*f3[4]-120*f3[2]+300*f3[3]+20*f3[7]

(1)

``



Download fdm-maple.mw

 

Hi MaplePrimes,

 

I try again to ask about a procedure I wrote.  Maybee someone can spot my error.

 

collatz_conjecture_2.mw

Here is the broken procedure - 

cs := proc (n::integer)::integer;
local count;
description "Find the number of steps for a Collatz sequence to reach 1";
count := 1;
while 1 < n do
if `mod`(n, 2) = 0 then n := (1/2)*n else n := 3*n+1 end if;
count := count+1
end do;
return count
end proc

Regards,

Matt

 

how can i generate graph families(all possible set )with given number of vertices?(just vertices ,not given edge set)

for instance : how can i write a procedure about with 4-vertices all graphs ,5-vertices,..and so on

please hellp me

Hello all,

I've been writing this procedure and it all works apart from the final sequence. I don't know why the final sequence doesn't input a number. Any suggestions? Thank you in advance!

Gambia ManTest_2.mw

Hello guys, i would like to do parallel computation in my code written in the Maple18. The question that can help me is:

Given a procedure that compute an function g, where g = f1+f2+f3+f4+f5+f6+f7+f8, i would like to compute all fi at same time.
Now, i´m using " grid:-seq('f[i]',[i=1,2,3,4,5,6,7,8])" and it works very well. However, i think that for my case an better solution should be;
Calculate the f1 in core 1, f2 in core 2, f3 in core 3 ... f8 in core 8 at same time, and after this, to sum all results(f1+f2+f3+..+f8). How i can do this?

Att,

Griffith.

When using seq function below in the second call, it does not generate a sequence of functions with 'a' being 1, 2, and 3, and I had expected. 

First seq function call is just to show that it works without the function "x ->" wrapping.

I could of couse use unapply as in the third call, but I had expected the second call to work.

Am I doing anything wrong, or is this a Maple bug?

In the code below the new function g is defined based on existing function f, but the new function g is then dependent on f at the time of definition, which is shown since later changes to f will change value of g.

How to fix definition of g based on f at the when g is defined, so later changes of f does not alter g ?

Hi,

     I now have a problem.

     I want to calculate first derivative of a function and make it a function with respect to a variable.

     For example,

     f:=x->x^2

     derivative:=x->diff(f,x)

 

     I expect derivative is a function, (i.e.  derivative(x)=2x) , So if I put 'derivative(2)',I should get 4 as results. However I get "Error, (in H_Mag_Derivative_2) invalid input: diff received 2, which is not valid for its 2nd argument".

     Could someone give me a hand? Very much appreciated.

I want to use while in proc but Maple shows an error saying

 

"Error, (in exa) illegal use of a formal parameter"

 

When I click on it, as usual it says "There is no help page available for this error". I tried a very simple example of while which you can see it below and it again shows same error. The while works well but when I put it inside of a procedure it makes an error. Note: the following example is just an example, this is not what I'm doing so please don't reply this while proc is not giving anything. My question is how can I use a while in procedure without encountering the above error.

 

i := 10;
while i > 1 do
if i mod 2 = 0 then i := i/2; else i := i+1; end if;
end do;

 

Now with proc

 

exa := proc (i::integer)::integer;
while 1 < i do
if i mod 2 = 0 then i :=i/2; else i := i+1; end if
end do; 
end proc;

exa(10);

"Error, (in exa) illegal use of a formal parameter"

I need some help fix my mathematics maple code problem , I define everything my Procedures,and procedures run is ok, but when I using call functions for another procedures  I can not operator my program . For sure procedures is work and correct. if somebody can help me , I really appreciate you help.

Hi,

 

Let, fixed an integer i and 1<=j<=2^{i}-1, for each x and y in [0,1] let the following mapping

Then, with the above procedure we can obtained, for a fixed i, all the mappings for j=1,...,2^{i}-1

 

However, How can I to evalute the "components" of the above procedure? For instance, I can not to compute CreaF(2)[1](0.35,0.465) (i.e., the first function in the "vector" CreaF(2), in x=0.35, y=0.465). 

 

Thanks very much for your time.

 

Hi there,

Recently, I started to learn maple. I came across a problem. 

I entered following codes:

with(plots);

ball := proc (x, y) fieldplot([x, y], x = -1 .. 1, y = -1 .. 1) end proc;

ball(1,1);      


However, it showed me Error, (in plots/animate) bad range arguments -10. = -10 .. 10, -10. = -10 .. 10.

could someone tell me how to put fieldplot into procedure? Very much appreciated.

1 2 3 4 5 6 7 Last Page 1 of 22