Items tagged with procedure

Hello,

i have a Problem with maple. I have written this simple procedure

myPi_1:=proc(r)
local i,l;
l:=0;
for i from 1 to floor(r) do
    if isprime(i) and (i mod 4 = 1) then
        l:=l+1;
    end if;
end do;
return l;
end proc:    

 

When i use it like this 

k := myPi_1(80);

it works

But when i triy to plot it

plot(myPi_1(t), t = 0 .. 500, numpoints = 500, thickness = 2, color = black);

i get this message
Warning, expecting only range variable t in expression myPi_1(t) to be plotted but found name myPi_1

And no plot

Thank you for any Help

 

 

 

 

I have a program:

Running abb(1,3) gives error: Error, (in abb) illegal use of a formal parameter

Might be a silly question: Is it not allowed? Do I have to define a local variable for b in order to change it?

Hi I have this code

 psi:=proc(n,x);
 (1/sqrt(sqrt(pi)*2^n*factorial(n))*exp(-x^2/2)*HermiteH(n,x))
 end proc;
 psi := proc(n, x) exp(-1/2*x^2)*HermiteH(n, x)/sqrt(sqrt(pi)*2^n*n!) end proc

 psi2=proc(a,x);
 psi(a,x):=(1/sqrt(sqrt(pi)*2^a*factorial(a))*exp(-x^2/2)*HermiteH(a,x))
 end proc;
psi2 = (proc(a, x)
    psi(a, x) := exp(-1/2*x^2)*HermiteH(a, x)/sqrt(sqrt(pi)*2^a*a!)

end proc)
 for n from 0 to 2 do;
 for a from 0 to 2 do;
 result=proc(n,a);
 result(n,a)=psi*psi2
 end proc;
print(evalf(int(result(n,a),x=0..infinity)));
od;
od;


it returns

 Float(infinity) signum(result(0, 0))

                     Float(infinity) signum(result(0, 1))

                     Float(infinity) signum(result(0, 2))

                     Float(infinity) signum(result(1, 0))

                     Float(infinity) signum(result(1, 1))

                     Float(infinity) signum(result(1, 2))

                     Float(infinity) signum(result(2, 0))

                     Float(infinity) signum(result(2, 1))

                     Float(infinity) signum(result(2, 2))

I know the results for (0,0), (1,1) and (2,2) should be 1 and the rest should be 0.

Can anybody help fix this please

I want to produce a user defined function in Maple and use it in my program like Matlab. My function in Matlab is as below:

function R=ff(i,m)
K=1;
Q= zeros( i );
for j=1:2:i
 Q(j)=2*i-K;
 K=4+K;
end
R=Q(m);

How to produce this function in Maple and use it in my program?

Hi!

I have seen th following procedure to compute the image of the points of [0,1] under the so called Peano space-filling curve (sorry, I have to pasted the code in "text plane" mode):

P[0] := (x, y) -> ((1/3)*y, (1/3)*x);

P[1] := (x, y) -> (-(1/3)*x+1/3, (1/3)*y+1/3); 

P[2] := (x, y) -> ((1/3)*x, (1/3)*y+2/3); 

P[3] := (x, y) -> ((1/3)*x+1/3, -(1/3)*y+1);

P[4] := (x, y) -> (2/3-(1/3)*y, 2/3-(1/3)*x); 

P[5] := (x, y) -> ( (1/3)*x+1/3, 1/3-(1/3)*y));

 P[6] := (x, y) -> (1/3)*x+2/3, (1/3)*y);

P[7] := (x, y) -> (-(1/3)*x+1, (1/3)*y+1/3);

P[8] := (x, y) -> ((1/3)*x+2/3, (1/3)*y+2/3);

peano := proc (t::numeric, depth::integer)

local q, r; global P;

if depth = 0 then return 0, 0 end if;

q := floor(9*t); r := 9*t-q;

return P[q](peano(r, depth-1))

end proc;

 

Now, I need to use the procedure "peanofun" as a function. For instance, if we define f:=(x,y)->x+y, I need to use (plot, compute, etc) for instance, the function f(peanofun(t,5))

Can you help me with this issue, please?

Many thanks for your time!

 

 

I was trying to write a procedure that would compute a simple linear equation using the Extended Euclidean Algorithm. I was thinking of a procedure like the following:

solveEeaMatrix := proc (a::list, b::list) 
 local c::list;  
 c := a -iquo(a[1],b[1])*b;  
 print(c);  
 while (c[1] <> gcd(a[1],b[1]) do 
 ...

I am basically stuck at this part as

1) I don't know how to setup a multi-dimensional array that could dynamically grow(as a possible solution).

2) I can't come up with a recursive function that could possibly take care of this.

In short, if I am given for example an equation like: 84*x+203*y = 14

I will transform it into 2 linear equation as follow:
row0 := [203, 0, 1] row1 := [84, 1, 0] Subsequently, I will perform the following:

c := a -iquo(a[1],b[1])*b;  

Where aand b are both lists and arguments of the procedure and cbeing another list and a local variable.

But I don't know how to do the following programmatically:

row3 := row1-iquo(row1[1], row2[1])*row2;
row4 := row2-iquo(row2[1], row3[1])*row3;
row5 := row3-iquo(row3[1], row4[1])*row4;
and so on ...                  

Any hint would be appreciated.

Hello I was trying to manipulate maple to write a procedure checking a matrix , say A with n rows and n columns. That matrix A given any row/column the sum of the entries for every row and column are equal. For example matrix [(-1,2)(2,-1)], every row and column in this matrix sums to 1. The entries in the matrix can be any real number.

Maple provides efficient vectorization and automatic parallelization for many common operators. For example

x -> 2*~x*~cos~(x*~x)

But in my application it is common to want to create rather long vectorized operators starting from some complicated symbolic computations. Doing conversions by hand from symbolic expressions to element-wise operations is laborious and error prone.

As a very simple example consider that it is possible to obtain (almost) the same result as above by writing the following as a vectorized operation

D(x->sin(x^2))~

But there are at least two problems with this. First of all it is not nearly as efficient as the first operator and second, perhaps not unrelated, is that the datatype returned when applying this operator to a Vector/rtable of hardware floats (e.g. datatype=float[8]) becomes something  more general.

My question is how can I convert a complicated symbolic expression into an efficient numeric element-wise vector operation?

I have tried several different approaches but so far without success. In the case above for example it seemed natural to expect that the following derivative

D(x->sin~(x^~2))

would produce a vectorized result, but this is not the case. In another attempt I was unable to see how to perform substitions into an expression, e.g. like this

unapply(subs(`*`=`*`~, cos=cos~, diff(sin(x),x)), x)

I would be glad to receive suggestions and/or references to relevant documentation. 

 

I would like to return local variable y (line 4 in showstat) in the attached dummy procedure (s1) without manually adding any comment inside the procedure s1. This procedure is a simple one and easy to copy paste/or change. When we have a long procedure, it is difficult to do so. I will always know the name of the local variable I want (say, y) and/or line number in showstat

Thanks

PS, I want to get y:=array(1..,2[(1)=x,2=zz])
 

restart;

s1:=proc(n,x)
local y,xx,i,j,zz::array(1..n,1..n);
for i from 1 to n do for j from 1 to n do zz[i,j]:=x[i]*(1+x[j]^2);od:
od:
y:=array(1..2,[(1)=x, (2)=zz]):
for j from 1 to n do xx[i]:=zz[i,i]/(add(zz[i,j],j=1..n));od:
0;
end proc;

s1 := proc (n, x) local y, xx, i, j, zz::(array(1 .. n, 1 .. n)); for i to n do for j to n do zz[i, j] := x[i]*(1+x[j]^2) end do end do; y := array(1 .. 2, [1 = x, 2 = zz]); for j to n do xx[i] := zz[i, i]/add(zz[i, j], j = 1 .. n) end do; 0 end proc

(1)

showstat(s1);

 

s1 := proc(n, x)

local y, xx, i, j, zz::array(1 .. n,1 .. n);

   1   for i to n do

   2     for j to n do

   3       zz[i,j] := x[i]*(1+x[j]^2)

         end do

       end do;

   4   y := array(1 .. 2,[1 = x, 2 = zz]);

   5   for j to n do

   6     xx[i] := zz[i,i]/add(zz[i,j],j = 1 .. n)

       end do;

   7   0

end proc

 

 

x0:=Vector(2,[1,1]);

x0 := Vector(2, {(1) = 1, (2) = 1})

(2)

s1(2,x0);

0

(3)

 


 

Download showstatexample.mws

Hi

I have a set P which is filled with 2D elements e.g.

P:={[1,1],[1,2],[1,3]...}


Later I'm wanting to add a new element e.g. {[1,10]}
At the moment I have

P union {[10, 10]}


If I were to print this I get what I want, but I want to update P.
When I try and do

 P:= P union {[10,10]}

I get an error "Error, illegal use of an object as a name"

What am I doing wrong and how can I solve this? Much appreciated!

Hi guys, i'm working on a problem using the runge kutta method (4). The problem is, when I run this program, with the given starting values, it perfectly calculates every value of x[w-i] except x[0] and i have no idea why. Can anyone help? Thanks!

In Kitonums'answer of

http://www.mapleprimes.com/questions/220229-How-Do-I-Solve-A-Differential-Equation-In-Maple

I read a code of remove(t->t=".", b);
t->t="." is a Boolean-valued procedure.

But, then, why does (t->t=".")(9); not return false like (t->t^2)(3); returns 9?
How can I have maple return false?

Thanks in advance.

i wrote a procedure for determine a lambda symmetries and first integrals of ODEs.

Procedure is running but commands is getting error.

Can  anybody help me.

Thanks in advance. procedure.mws

Hi everyone,

I created a procedure "SIM" which depends on two formal parameters x and y. I write Threads:-Map(SIM, x, y) in order to execute it with the Threads package.

I would like to create .mpl files automatically, each one made of the code Threads:-Map(SIM, x, y) with specific values of x and y. For instance:

Threads:-Map(SIM, 5000, 1), then Threads:-Map(SIM, 5000, 2) ... and so on until Threads:-Map(SIM, 5000, 5000).

The fact is, I tried writing the following:

for y from 1 to 5000 do
a[y] := Threads:-Map(SIM, 5000, y);
save a[y], sprintf("SIM_%d.mpl", y)
end do

However, it does not work. The error message says "Error, save can only save names". I also tried, but without success:

for y from 1 to 5000 do
a[y] := Threads:-Map(SIM, 5000, y);
save convert(a[y], name), sprintf("SIM_%d.mpl", y)
end do

Any idea? Thanks a lot.

 

 

Hi Maple Primes,

Can this code be improved?

I know that the Goldbach Conjecture has been checked with computer tools above 10^10.

Request for comments.

check_g_conjecture_26_b.mw

check_g_conjecture_26_b.pdf

Regards

Matt

 

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