Items tagged with procedure procedure Tagged Items Feed

Consider the following two test procedures for creation of the same module:

createModule1 := proc(dim::posint)
    module()
        export det;
        det := (x::Matrix(1..dim,1..dim)) -> Determinant(x);
    end module
end proc:

and

createModule2 := proc(A::Matrix(square))
    local dim;
    dim := RowDimension(A);
    module()
        export det;
        det := (x::Matrix(1..dim,1..dim)) -> Determinant(x);
    end module
end proc:

as well as the following code lines calling these:

createModule1(       2 ):-det(IdentityMatrix(2));
createModule2(Matrix(2)):-det(IdentityMatrix(2));

The first line executes unproblematically, while for the second line an error results concerning the dimensionality check 1..dim,1..dim of the matrix. Why is dim available/initialized in the first version, while not in the second?

Hi

I have this attched procedure "Alt_lisse1".

Why the result e1 does'nt take into account the known variables

Thanks

ALt_lisse1.mw

Hi

is it possible to remove this warning and not to show it when executing a procedure ? 

Warning, `AzIII` is implicitly declared local to procedure `lisse`

Thanks

I am working on a problem that involves a great deal of combinatorics, and I have broken the problem into several procedures.  I am trying to create a first procedure that creates a list output, a second procedure which takes the list and other input and cycles over combinations of two elements from the list and calls a third procedure to perform the calculus needed for each pair.  A simplified example follows:

f1:=proc(a1, a2, ..., an)
(various if-then statements)

return [b1, b2,...,bn];

end:

 

f2:=proc(alpha, beta,...,L::list)

A:=0;
for i from 1 to n-1 do
     for j from i+1 to n do
     A:= A+ f2(alpha, beta, ..., L[i], L[j])
     end do;
end do;

return A;

end:

 

f3:=proc(alpha, beta, ..., bi, bj)

(various mathematical manipulations)
return x;

end:

 

When I first use f1 to get [b1, b2, ..., bn] and then invoke f2 as f2(alpha, beta, ..., [b1, b2, ..., bn]) everything works fine.

However, f1 needs to be invoked by yet a larger function as follows:
...

L0:=[0,0,0,...,0]:
L0:=f1(a1, a2, ..., an):
B:=f2(alpha, beta,...,L0):

...
When I do this, L0 still gets assigned the correct value according the program trace, yet it fails to invoke f3 correctly.  What could the problem be?

Hello people in mapleprime

 

maxi:=proc(obj,expre,x,y)
local eq1,eq2,eq3,lagrangean;
lagrangean:=obj+lambda*expre;
eq1:=diff(lagrangean,x)=0:
eq2:=diff(lagrangean,y)=0:
eq3:=diff(lagrangean,lambda)=0:
solve({eq1,eq2,eq3},{x,y});
end proc;

Using the above procedure, next code will not return the values of a and b, or a[2] and b[2].

Can you teach me the reason why?

maxi(a*b,z-a-b,a,b);

maxi(a[2]*b[2],z-a[2]-b[2],a[2],b[2])

Thanks in advance.

 

taro

What does one use to duplicate a procedure along with its remember table, so that they are distinct instances of said?

Hello all,

I am trying to create a matrix throgh a procedure but unfortunately I could not find how to define an empty matrix in Maple. This is how my procedure looks like,

Initial_Matrix := proc (BC::list, n, BP::list)
local M::Matrix, i;
M:=[][];
for i from 1 to numelems(BC) do
M:= <M,function_coeffs(BC[i], n, BP)>;
end do;

where the procedure function_coeffs returns a row vector. Logically, it should keep adding rows function_coeffs(BC[i], n, BP) to the emty matrix, but its not happening. Please help me out.

Thank you for your time.

Hello,

I would like to plot coupled elliptic parametric curves.

I have a problem in the for loop in my code. The index i of the phi variable is not incremented.

Here my code:

for i to 4
do
u[i]:=t->L/2*cos(w*t);
v[i]:=t->H*sin(w*t+phi[i]);
end do;

The result looks like this :

u[1](t) -> - L cos(w t)
v[1](t) -> H sin(w t + phi[i])

u[2](t) -> - L cos(w t)
v[2](t) -> H sin(w t + phi[i])

u[3](t) -> - L cos(w t)
u[3](t) -> H sin(w t + phi[i])

u[4](t)  -> - L cos(w t)
u[4](t)  -> H sin(w t + phi[i])

And i would have prefered :

u[1](t) -> - L cos(w t)
v[1](t) -> H sin(w t + phi[1])

u[2](t) -> - L cos(w t)
v[2](t) -> H sin(w t + phi[2])

u[3](t) -> - L cos(w t)
v[3](t) -> H sin(w t + phi[3])

u[4](t)  -> - L cos(w t)
v[4](t)  -> H sin(w t + phi[4])

Do you have ideas how I can obtain iteration on my phi variable ?

Thank you for your help.

Hi,

I have a first order differential eq. for some variable say $r(x)$, where $x$ is the independent variable.

After solving this differential equation numerically, I want to use its solution in other expression for $r(x)$ and plot the expession with $x$.

Please let me know how to do it.

Thanks in advance.

 

 

I'm trying to use the CodeGeneration package to generate code for a series expansion. I'd like to wrap it in a function that specifies the arguments, so that the code generation package can generate a complete function definition along with definitions for all the temporary variables.

with(CodeGeneration):
f := proc(r): x->r end proc:
to_translate := f(convert(series(sin(x),x,20),polynom));

to_translate := proc (x) options operator, arrow; x-(1/6)*x^3+(1/120)*x^5-(1/5040)*x^7+(1/362880)*x^9-(1/39916800)*x^11+(1/6227020800)*x^13-(1/1307674368000)*x^15+(1/355687428096000)*x^17-(1/121645100408832000)*x^19 end proc


CodeGeneration['C']( to_translate );


Warning, procedure/module options ignored
double to_translate (double x)
{
  return(r);
}

Instead of using the value for 'r' passed in, CodeGenerate is producing a function which returns the bare symbol 'r' which is treated as a double. It shouldn't be an issue with lazy evalution because 'to_translate' is evaluated on the statement before the call to CodeGeneration, and to_translate has the full expression that I want to generate code for. How do I get CodeGeneration to produce the intented result?

hi .how i can clarify expression in maple that in running dont asked me again..

for example attached file

2)how i can deleted one parameter of 
Memory in maple or
Restart it??

I a working with circuits, and was wondering whether or not it might be possible to shorten the proces of calculating parallel resistors. My idea is that using some symbol, such as || would find the equivalent resistor.

My idea is based on the fact that CrossProduct can also be done using &x command. Like so.

CrossProduct(a,b) = a &x b

 

So for resistors it would look something like:

Parallel(a,b) = a || b

 

For those interested the function for parallel resistors would be:

Parallel := (a,b) -> 1/(1/a+1/b);

I wish to define a function with a finite number of inputs, but I do not know that number ahead of time (in other words the user will specify n and my function operates on vectors of size n). How can this be done?

Hello,

I've got this error in my code and I don't know why as I didn't get it when I used a different xn function. Any help would be greatly appreciated! Thank you in advance!

Kind regards,

Gambia Man

restart

with(plots):

boxcount := proc (data, N) local n, xmax, xmin, xrange, ymax, ymin, yrange, dx, dy, i, j, ix, iy, sum, res; n := (1/2)*ArrayNumElems(data); xmax := max(seq(data[i, 1], i = 1 .. n)); xmin := min(seq(data[i, 1], i = 1 .. n)); ymax := max(seq(data[i, 2], i = 1 .. n)); ymin := min(seq(data[i, 2], i = 1 .. n)); xrange := xmax-xmin; xmin := xmin+(-1)*0.1e-1*xrange; xmax := xmax+0.1e-1*xrange; xrange := 1.02*xrange; yrange := ymax-ymin; ymin := ymin+(-1)*0.1e-1*yrange; ymax := ymax+0.1e-1*yrange; yrange := 1.02*yrange; dx := xrange/N; dy := yrange/N; res := Array(0 .. N-1, 0 .. N-1, 0); for i to n do ix := trunc((data[i, 1]-xmin)/dx); iy := trunc((data[i, 2]-ymin)/dy); res[ix, iy] := 1 end do; add(add(res[i, j], i = 0 .. N-1), j = 0 .. N-1) end proc:

``

bicationplot := proc (N) local Nr, Nt, x0, rmin, rmax, bif, k, ir, r, xn, i; global pts; Nr := 100; Nt := 200; x0 := .1; rmin := .75; rmax := 3.5; bif := Array(1 .. Nr*N, 1 .. 2); k := 1; for ir to Nr do r := rmin+ir*(rmax-rmin)/Nr; xn := x0; for i to Nt do xn := xn^2-r end do; for i to N do xn := xn^2-r; bif[k, 1] := r; bif[k, 2] := xn; k := k+1 end do end do; pts := bif end proc:

bif

bif

(1)

fractaldimension := proc (Noofitterations::integer, Npoints::integer, Nmax::integer) local res, xv, yv, line, stderrors, avgstderrors, i, avgline; avgstderrors := 0; avgline := 0; for i to Noofitterations do bicationplot(Npoints); res := [seq([1.0/n, boxcount(pts, n)], n = 1 .. Nmax, 10)]; xv := [seq(log(res[i][1]), i = 1 .. nops(res))]; yv := [seq(log(res[i][2]), i = 1 .. nops(res))]; line[i] := Fit(m*x+const, xv, yv, x, output = [leastsquaresfunction]); stderrors[i] := Fit(m*x+const, xv, yv, x, output = standarderrors) end do; for i to Noofitterations do avgstderrors := avgstderrors+stderrors[i] end do; avgstderrors := avgstderrors/Noofitterations; for i to Noofitterations do avgline := avgline+line[i] end do; avgline := avgline/Noofitterations; return FD = -(diff(avgline, x)), avgline, avgstderrors, loglogplot(res) end proc:

fractaldimension(10, 100, 100)

Error, (in boxcount) bad index into Array

 

``

 

Download First_part_fractal_determination_.mw

Explore the values of km digit(n,m) using km list for all m, 0 ≤ m ≤ 8.
Look at the output until you can make a conjecture that concerns the pattern
obtained for each fixed m, 0 ≤ m ≤ 8 using 

km := proc (n::posint, m::nonnegint)

local k,

mySum := 0;

for k to n do

mySum := mySum+k^m

end do;

return mySum

end proc

using a list km list(m,6,20) when m is not a multiple of 4, and km list(m,6,50) when m is a multiple of 4.

 

any help appreciated..THank you

 

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