Items tagged with procedure procedure Tagged Items Feed

Dear all,

I have one probem in using Maple in comparison with Matlab.

Generally, when using Matlab, I write a long program with 500 lines (for example) and where I use some matricial calculations and other. When I want to repeat this program for some parameters (variables) many times, I transform the program to a procedure "Function" with just adding the command Function in the start of the program.

When using Maple, I have a difficulty to transform a long program which I want to repeat for some variables to a procedure "proc". The program uses packages like LinearAlgebra and other procedures.

Is there a simple way to transform a long Maple program to a procedure which should be repeated many times for some variables in Maple. 

I have especially problems with the commands local, global, use (for packages), etc.. and the warning related to the variables. It is not easy for a long program with many variables to write them in local or global variables.

Thank you.

Hi Maple People,

I got stuck trying to write a procedue for my project today.  My topic is Prime Constellations.

If you want to help me, please read my primer on constellations

https://docs.google.com/viewer?a=v&pid=sites&srcid=ZGVmYXVsdGRvbWFpbnxwcmltZWNvbnN0ZWxsYXRpb25zfGd4OjNmOWZlNWQxZDY2ODY4YmQ

The procedure should refine an offset Vector and increase a multiplier scalar.

 

I want to delay putting the broken procedure until I can simplify it and try again.

Thanks,

Matt Anderson

Write a recursive Maple procedure, called “decToBin”, that converts an integer from decimal (base 10) to binary (base 2). Ensure that only integers are allowed as arguments to the procedure. Passing a negative integer should result in no output. Test your procedure by outputting the result of the following:
decToBin(10)
decToBin(163)
decToBin(213)
decToBin(-1)
decToBin(“A”) # should result in an “invalid input” error

Hi all,

I've been working on this problem for a while and only need to figure out why the function vector is returning zeros every time I call the procedure. The problem statement is in the file I attached to this.

If any of you could help me, I would be a happy guy.

 

File: 1.2.mw

Hello,
I am looking here for a tutor, that can help me doing some Maple programming.
I am a mathematic student and we use Maple programming.
I will be happy to pay a small amount of money for each exercice you help me doing,
Obviously the money will not be much, as I am just a student, I am just thinking you help me , and the money I pay you will be just as a Thank you gift, I thought about asking tutors at the college, but they are charging too much :( 
if anyone is interested, please contact me here.

(The procedures that we usually have to write are for example:
Aitken’s method, Newton-Raphson Method, Chebyshev Polynomial,...  I don't think it is hard for you.
Thank you very time for your time and your help.

I want to translate my maple code with matrice multiplication  to C code. But the command  "Multiply" cannot be translated. So I want to edit the function translation by myself. I use "AddFunction" command to create a new function  "Multiply" and want to specify its corresponding C code.

 


f := proc ()
local x,y;
x := Matrix([[1, 2], [3, 4]]);
y := Matrix([[1,3],[4,2]]);
Multiply(x, y);
NULL;
end proc;

LanguageDefinition:-Define("NewC", extend = "C", AddFunction("Multiply", [Matrix,Matrix]::Matrix,
proc (X, Y)
local a,b;
a := 2;
b := convert(a, string);
Printer:-Print("Mmultiply(", X);
Printer:-Print(",", Y, ")"); Printer:-Print("\n");
Printer:-Print("from", b, "to");
Printer:-Print(",", Y, "do") end proc, numeric = double));
Translate(f, language = "NewC")

 

But when I run it, the "Multiply" function cannot be translated.  The result is:

 

Warning, type signature [CodeGeneration:-Names:-ArrayType(integer,CodeGeneration:-Names:-ArrayRanges(1 .. 2,1 .. 2),CodeGeneration:-Names:-ArrayOptions()), CodeGeneration:-Names:-ArrayType(integer,CodeGeneration:-Names:-ArrayRanges(1 .. 2,1 .. 2),CodeGeneration:-Names:-ArrayOptions())] for function Multiply is not recognized
void f (void)
{
  int x[2][2];
  int y[2][2];
  x[0][0] = 1;
  x[0][1] = 2;
  x[1][0] = 3;
  x[1][1] = 4;
  y[0][0] = 1;
  y[0][1] = 3;
  y[1][0] = 4;
  y[1][1] = 2;
  Multiply(x, y);
  ;
}

I don't know why "Multiply(x,y)" cannot be translated.

If I put two "Multiply(x, y)" in the procedure, like this:


f := proc ()
local x,y;

Multiply(x, y);
x := Matrix([[1, 2], [3, 4]]);
y := Matrix([[1,3],[4,2]]);
Multiply(x, y);
NULL;
end proc;

LanguageDefinition:-Define("NewC", extend = "C", AddFunction("Multiply", [Matrix,Matrix]::Matrix,
proc (X, Y)
local a;
a := 2;
b := convert(a, string);
Printer:-Print("Mmultiply(", X);
Printer:-Print(",", Y, ")"); Printer:-Print("\n");
Printer:-Print("from", b, "to");
Printer:-Print(",", Y, "do") end proc, numeric = double));
Translate(f, language = "NewC")

THe result is:

Warning, cannot resolve types, reassigning x's type
Warning, cannot resolve types, reassigning y's type
Error, (in CodeGeneration:-IssueError) type 'Matrix' cannot be translated to target language

I don't know why type 'Matrix' cannot be translated.

 

 

Hi,

I tried to write a procedure which performs a differentiation on list elements:

 

list1:= [x^3 , 2x , 3]
list2:= [x^5, 2x^4 , 2x]

 



dList:=proc(a::list, b::list)::list;
    local res::list, i::integer, n::integer; 
    description "add list elements and diff";
    n:=min(nops(a), nops(b)) ;
res:=[seq(0, i=1..n)];
for i from 1 by 1 to n do
     res[i]:=diff(a[i]+b[i],x)
end do;
res;
end proc:


dList(list1,list2)

However the Line:  res[i]:=diff(a[i]+b[i],x)

 

causes the Error: Error, illegal use of an object as a name;

 

Can someone give me a hint how to fix this?

 

Thank you very much.

hi everyone.how can i write a function or procedure or summation so that i can write down the following polynomial ? i just want to create a set of polynomials which their summation of power ( power of x + power of y ) be less than three or equal to three ? the coefficients priority is not important , for example it is not important that a1 multiplies to x or y , i just want to create this polynomial with some coeeficients. tnx for help

``

restart:

a[9]*y^3+x^3*a[8]+x^2*y*a[5]+x*y^2*a[7]+x^2*a[2]+x*y*a[4]+y^2*a[6]+x*a[1]+y*a[3]+a[0];

x^3*a[8]+x^2*y*a[5]+x*y^2*a[7]+y^3*a[9]+x^2*a[2]+x*y*a[4]+y^2*a[6]+x*a[1]+y*a[3]+a[0]

(1)

 

``

 

Download problem.mw

Using Maple 18, I solved for minimum and maximum price. Instead of using fsolve I wanna use procedure programming structure in order to get the same results. How can I do it?

min_sol := fsolve([bc_cond, slope_cond, x[G, 1] = w[aggr, 1]], {p = 0 .. 1, x[G, 1] = 0 .. w[aggr, 1], x[G, 2] = 0 .. w[aggr, 2]}); p_min := subs(min_sol, p); max_sol := fsolve([bc_cond, slope_cond, x[G, 2] = w[aggr, 2]], {p = 0 .. 1, x[G, 1] = 0 .. w[aggr, 1], x[G, 2] = 0 .. w[aggr, 2]}); p_max := subs(max_sol, p);
{p = 0.3857139820, x[G, 1] = 127.8000000, x[G, 2] = 38.99045418}
0.3857139820
{p = 0.8841007104, x[G, 1] = 44.30160890, x[G, 2] = 164.2000000}
0.8841007104

I have the following procedure to do the above. It works but it returns [9,10],[10,9],[12,1] for n=1729(for example). How do I modify this to 

a) to count 9,10 and 10,9 as the same and hence only show one of them

b) get 1,12 to show as a solution?

cubesum:=proc(n::nonnegint)
global listcub:=table();
local k:=0, x:=iroot(iquo(n,3),3),y:=x,x3:=x^3,y3:=y^3;
if 3*x3 <> n then x=x+1; x3:=x^3;y:=x;y3:=x3 end if;
while x3<=n do
y:=iroot(n-x3,3); y3:=y^3;
if(x3+y3 = n) then k:=k+1; listcub[k]:=[x,y]end if;
x:=x+1; x3:=x^3;
end do;
convert(listcub,list);
end proc:

 

So i got a procedure test, she is kind of numeric, i whant to optimaze test([.5, .5, .5], 1, 3, 100, 100, true, [x, 0, 0, 0, 0])=0 by x. But optinization substitutes x like a symbol, i tryed all methods but they all do the same.

f := proc (x) options operator, arrow; abs(test([.5, .5, .5], 1, 3, 100, 100, true, [x, 0, 0, 0, 0])-.4) end proc; Minimize(f(x));
%;
Error, (in test) cannot determine if this expression is true or false: 0 < -43.0+100*x


Can i some how use optinization on such procedure?

file link  - >    primset.mw

I have a nice family of functions of the form:

W:=(p,n,mu,w)->sum(w[k] * (n-k)* mu(n-k),k=1..n)

which can be evaluated for different p's using the operator mu*diff(...,mu)

The recursion begins with p=0 and proceeds using mu*diff(W(p,n,mu,w),mu) = W(p+1,n,mu,w).

Can anybody implement this procedure in Maple

Thank you 

Hi all,

I'm having some trouble trying to make it so the answer Max(3,1,x,4) turns into Max(x,4), that is, only the greates number and the non numerical values are returned. I've tried a bunch of different things, but have gone out of ideas.

This is the link to the Maple file :6-1.mw and this is the code:

``

#Improve the general Max procedure on page 224 so that Max(3,x,1,4)returns Max(x,4). That is, the procedure returns the maximum numerical value along with all nonnumerical values.

Max:=proc() local m, i;
m:=-infinity;
for i in (args) do
  if not type(i, numeric) then
    return 'procname'(args):
  end if;
  if i>m then
    m:=i
  end if;
end do;
m;
end proc;

proc () local m, i; m := -infinity; for i in args do if not type(i, numeric) then return ('procname')(args) end if; if m < i then m := i end if end do; m end proc

(1)

Max(3,1,x,4);

Max(3, 1, x, 4)

(2)

 

``


Would really appreaciate your help with this

Download 6-1.mw

I am trying to find the root of an equation that involves a procedure and a definite integral (solved numerically). Of course, I don't need the root to be found symbolically, but numerically would be fine. The problem is, I keep getting the error

"Error, (in fsolve) Can't handle expressions with typed procedures"

whenever I try to solve it. Anyone have any ideas? My worksheet is here: Table-1-duplication-mapleprimes.mw 

 

I noticed, when using

restart;
with(LibraryTools);
Browse();

That some procedures have lost all its formating. No line numbers, no spaces in between, very hard to read. For example, dsolve() in maple.mla is like this. While other procs are well formated and easy to read.

Is there a reason for this? And is there a way to fix this in Browse() to be able to read the source? It is impossible to read it like this readlly. Maple 18.02 on windows.

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