Items tagged with procedure procedure Tagged Items Feed

I am not sure how/why, but here is the worksheet.

test.mw

 

The function evalutes fine and can be used for sequence. But it does not seem to be working with plot or Maximize.

V is assumed to between 0 and 1.

Need some help.

 

Thanks,

 

casper

Hello, could someone please help me to understand this warning that i'm getting?

Warning, `N4ds` is implicitly declared local to procedure `SFunc`

Thanks

Hello,

I have a procedure wich is something like 

 

F:=proc(a,b,l) limit(f(a,b),b=l); end proc;

For my specific problem, the limit always exists and is a well defined function

After that, I would like to generate other functions, depending on F(a,b,l), e.g.:

 

G:=proc(a,b,N) add(F(a,b,l),l=1..N); end proc;

 

However, when I tried to do that, Maple inserts in G an unevaluated F, depending on the results of the limits. This makes G not work properly (unevaluated), since the limit is not computed before G. I tried to use some intermediate steps, like using unapply command, but it does not works.

If someone can help, I would appreciate.

 

 

I want to test linearly dependence of a polynomial f on a list of polynomials F by additional condition on parametric coefficients of linear parametric polynomial (linear for variables not parameters). Please note that:

  1. The polynomialand the members of are always homogenous in the variables.
  2. The coefficients of f, the coefficients of the members of F are all always polynomials in the parameters or contant and the members of N and W are all always polynomials in the parameters.

 

For example let

and

(a,b,c,d,e,h are parameters and A1,A2,A3 are variables).

If I use PolyLinearCombo(F,f,{A1,A2,A3}) (see http://www.mapleprimes.com/questions/204469-How-Can-I-Find-The-Coefficients-Of-Linear#comment217621)then its output is false,[].

Now we let to condition sets for parameters as the following:

N:=[ebc+ahd]

W:=[a,c]

The elements of N must be zero means that ebc+ahd=0

and the elements of W are non-zero that is a<>0 and c <>0.

Let a=b=c=d=h=1 and e=-1. This specialization satisfy in the above condition sets N and W. By this specialization we have:

and

Now if I use PolyLinearCombo(F,f,{A1,A2,A3}) then its output is true,[-1,1].

By this additional two condition sets I have to check that whether f is linearly independent of F or not. How can I do this without specialization? In fact I want an algorithm that its input is (null condition N, not-null condition W, list of polynomials F, a polynomial f, the set of variables) and its output is true and coefficients if f is linearly dependent of F w.r.t. null and not-null conditions N and W, else its output is false.

If the name of new procedure is ExtPolyLinearCombo and 

N:=[ebc+ahd]

W:=[a,c]

I want the output of

ExtPolyLinearCombo(N,W,F,f,{A1,A2,A3}) be true,[coefficients]

Thank you very much in advance.

 

 

The following toy procedure does not work (I give a value to a symbol). How to make it work ? Thanks.

Hi all,
can you help in that please?
How can I use this small procedure (root_of_cheb) as a sub-procedure in  the next procedure (EvalInt) ?
is it possible?

restart:
root_of_cheb:=proc(n)
   local xk,b,k:
   xk:=(k,n)->cos((2*k-1)*Pi/(2*n));
   sort([seq(evalf(xk(k,n)),k=1..n)]):
end:
EvalInt:=proc(f,n)
   local xk:
   xk:=(k,n)->cos((2*k-1)*Pi/(2*n));
   evalf((Pi/n)*add(f(xk(i,n)),i=1..n)):
end:

Thank you

bags.mw

$15 is spread among four different bags. How  can you can make any whole number of dollars from $1 to $15 by selecting some of these bags of money, without taking any money out of the bags.
 
How is the money distributed ?

One bag must have $1 in it.
To be able to make $2, and each bag is different, so one bag must have $2 in it.
 can now make $3, but can’t make $4, so the third bag must have $4 in it.
With $1, $2 and $4 in three bags, can make every total up to $7. The last bag has the rest of his money in it – $8.

so the answer is $[1,2,4,8]

wondering how to do this with maple procedure. unsurprisingly my code doesn't work

 

 

Could someone help me understand what is happening to this procedure. When I run it, I get the subject error. Thanks.

game := proc()
  local player1, player2, roll;
  roll := rand( 1..6 );
  player1 := roll():
  player2 := roll(2):
  if player1>player2 then "A wins"
  elif player1=player2 then "Tie"
  else "B wins"
  end if;
end proc:

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

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

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