Items tagged with proc

I have a function that is defined by a proc command including some conditional statements (if ... then ...). The conditions are so long so that I can not use a piecewise function instead of using proc. The commands in my code are long and I simplify my question as follows:
f := proc(x) local r; r := sin(x)+x*cos(x); if abs(r) < 1/2 then sin(x) else cos(x) end if; end proc;

plot('f'(x), x = -1 .. 1) works fine but the command int(('f')(x), x = -1 .. 1) gives an error:
Error, (in f) cannot determine if this expression is true or false: abs(sin(x)+x*cos(x)) < 1/2

Is there any way (except rewriting the function as a piecewise function) to get rid of the error? 

Any help is appreciated.

When trying to perform the following:

p1 := proc (x, y) if x^2+y^2 <= 1 then x*y-y^2 else 0 end if end proc;
plot3d(p1, x = -1 .. 1, y = -1 .. 1);
Error, (in plot3d) expected ranges but received x = -1 .. 1 and y = -1 .. 1
 

I get this strange error message. To the best of my knowledge x and y ARE provided as ranges. What am I missing/not understanding?

If I omit the ranges in plot3d Maple returns a correct plot, but the default range (-10 .. 10) does not display sufficient details

Hello. Two teams A and B (consisting of 2, 3 or even 4 players) compete and the outcome of each game is either a win or a loss. I have a to process the new (gaussian) laws of players given whom beats whom.

Given the initial means and standard deviations of the players, I have a algorithm (RC) which computes the new laws of the players. [the actual algorithm i use is different to the one i am showing here]. 

By way of example consider two teams with 2 players per side. Each person plays 2 games.

The initial laws of A1,A2,B1,B2 are given.

(A1,B1) --->(A1',B1').......[iteration 1. A1 beats B1, resulting in new laws A1' and B1'(computed by RC)]

(B2, A1') --->(B2', A1").......[ iteration 2. B2 beats A1. using A1' from iteration 1. A1 has played twice and is denoted by A1"]

(B2',A2) --->(B2",A2').......[ iteration 3. B2 beats A2. using B2' from iteration 2.  B2 has finished and is denoted by B2"]

(A2',B1') --->( A2",B1")......[ iteration 4. A2 beats B1. using B1' from iteration 1 and A2' from iteration 3. now all players have played their matches]

new laws A1" ,A2", B1" & B2" should be outputted.

my first code gets the result, but it is tedious to enter the iterations in the right place .especially for teams of 3 or more.

my second with parameters gets errors.

So what i want is to enter who beat who:

eg  [[B1, A1], [B2,A1], [B2, A2], [A2, B1]];
and the final laws are computed automatically.

bb_processing_edit.mw

In a trajectory. How can i return the range if i know the position-function. ... return x when y=0?

You have three cakes, with diameters 15cm, 20cm and 25cm (same width). You want to share the cakes equally among your four customers. How do you do it?
What if you want the cakes sliced into the minimum total number of pieces?


The answer is to cut the cakes in half, but five pieces is the minimum.

What I want is a procedure for a more general case.

m cakes (different diameters) divided equally amongst n people. what is the minimum number of cuts or pieces to achieve this.

cuts.mw

Hi there,
I have a simple task to do with arrays. I have an 8x3000 array, whose columns are sometimes all zeroes (if any element in the column is zero then the entire column is zero). I want to eliminate the zero vectors, so I have this loop (the array is A)

for i from 1 to 3000 do
    while A(1,i)=0 do
        A:=DeleteColumn(A,i);
    end do;
end do:

Setting "A:=DeleteColumn(A,i);" reduces the size of the array, so if all the zero columns have been deleted at "i=200", Maple will keep trying to check the next column, which doesn't exist anymore. This gives an "index out of bounds" error, but also records "A" as the new smaller array, which is fine.

If I run this loop inside a procedure, the error stops the procedure, but it doesn't record the new array, it stays as the older, larger one. Does anyone know of a way around this?

Any help would be much appreciated.

Dear Community,

I get this message

'EQU' is implicitly declared local to procedure 'Z_DAK_FSOLVE'Problem with procedurefor a procedure, and  cannot go further. How can I avoid it?

Tx for the help in advance,

best regards

Andras

Z_DAK_PROC.mw

I want to compute delta but i do not want to show result for delta. i know i need to put 
delta := unassign('delta');
but i do not know where to put, i try and error so many times but the answer still the same. 
the answer should be in marix form 2x2 
[-δD11   0    ]
[0         D22]



>derivation := proc (A, n)
local i, j, k, t, s1, m, D, sols, eqns, BChange, delta; eqns := {}; D := matrix(n, n); BChange := matrix(n, n);
for i to n do
for j to n do
for m to n do
s1 := sum(0*A[i, j, k]*D[m, k], k = 1 .. n)-(sum(A[k, j, m]*D[k, i]+delta*A[i, k, m]*D[k, j], k = 1 .. n));
eqns := `union`(eqns, {s1})
end do
end do
end do;
sols := [solve(eqns)];
delta := unassign('delta');
t := nops(sols);
for i to t do
for j to n do
for k to n do
BChange[k, j] := subs(sols[i], D[k, j])
end do
end do;
print("BChange:=", BChange)
end do
end proc

> AS1 := array(sparse, 1 .. 2, 1 .. 2, 1 .. 2, [(1, 1, 2) = 1]);
> derivation(AS1, 2);

 

restart

with(LinearAlgebra):

with(StringTools):

FormatTime("%m-%d-%Y, %H:%M")

NULL

Pile spacing of each pile from a refrence pile:

S__p := Matrix(9, 9, {(1, 1) = 0., (1, 2) = 3.30, (1, 3) = 6.60, (1, 4) = 3.30, (1, 5) = 4.67, (1, 6) = 7.38, (1, 7) = 6.60, (1, 8) = 7.38, (1, 9) = 9.33, (2, 1) = 3.30, (2, 2) = 0., (2, 3) = 3.30, (2, 4) = 4.67, (2, 5) = 3.30, (2, 6) = 4.67, (2, 7) = 7.38, (2, 8) = 6.60, (2, 9) = 7.38, (3, 1) = 6.60, (3, 2) = 3.30, (3, 3) = 0., (3, 4) = 7.38, (3, 5) = 4.67, (3, 6) = 3.30, (3, 7) = 9.33, (3, 8) = 7.38, (3, 9) = 6.60, (4, 1) = 3.30, (4, 2) = 4.67, (4, 3) = 7.38, (4, 4) = 0., (4, 5) = 3.30, (4, 6) = 6.60, (4, 7) = 3.30, (4, 8) = 4.67, (4, 9) = 7.38, (5, 1) = 4.67, (5, 2) = 3.30, (5, 3) = 4.67, (5, 4) = 3.30, (5, 5) = 0., (5, 6) = 3.30, (5, 7) = 4.67, (5, 8) = 3.30, (5, 9) = 4.67, (6, 1) = 7.38, (6, 2) = 4.67, (6, 3) = 3.30, (6, 4) = 6.60, (6, 5) = 3.30, (6, 6) = 0., (6, 7) = 7.38, (6, 8) = 4.67, (6, 9) = 3.30, (7, 1) = 6.60, (7, 2) = 7.38, (7, 3) = 9.33, (7, 4) = 3.30, (7, 5) = 4.67, (7, 6) = 7.38, (7, 7) = 0., (7, 8) = 3.30, (7, 9) = 6.60, (8, 1) = 7.38, (8, 2) = 6.60, (8, 3) = 7.38, (8, 4) = 4.67, (8, 5) = 3.30, (8, 6) = 4.67, (8, 7) = 3.30, (8, 8) = 0., (8, 9) = 3.30, (9, 1) = 9.33, (9, 2) = 7.38, (9, 3) = 6.60, (9, 4) = 7.38, (9, 5) = 4.67, (9, 6) = 3.30, (9, 7) = 6.60, (9, 8) = 3.30, (9, 9) = 0.})

Angle of each pile from a reference pile in radian:

xi := Matrix(9, 9, {(1, 1) = 0., (1, 2) = 0., (1, 3) = 0., (1, 4) = 1.57, (1, 5) = .785, (1, 6) = .464, (1, 7) = 1.57, (1, 8) = 1.11, (1, 9) = .785, (2, 1) = 3.14, (2, 2) = 0., (2, 3) = 0., (2, 4) = 2.36, (2, 5) = 1.57, (2, 6) = .785, (2, 7) = 2.03, (2, 8) = 1.57, (2, 9) = 1.11, (3, 1) = 3.14, (3, 2) = 3.14, (3, 3) = 0., (3, 4) = 2.68, (3, 5) = 2.36, (3, 6) = 1.57, (3, 7) = 2.36, (3, 8) = 2.03, (3, 9) = 1.57, (4, 1) = 1.57, (4, 2) = .785, (4, 3) = .464, (4, 4) = 0., (4, 5) = 0., (4, 6) = 0., (4, 7) = 1.57, (4, 8) = .785, (4, 9) = .464, (5, 1) = 2.36, (5, 2) = 1.57, (5, 3) = .785, (5, 4) = 3.14, (5, 5) = 0., (5, 6) = 0., (5, 7) = 2.36, (5, 8) = 1.57, (5, 9) = .785, (6, 1) = 2.68, (6, 2) = 2.36, (6, 3) = 1.57, (6, 4) = 3.14, (6, 5) = 3.14, (6, 6) = 0., (6, 7) = 2.68, (6, 8) = 2.36, (6, 9) = 1.57, (7, 1) = 1.57, (7, 2) = 1.11, (7, 3) = .785, (7, 4) = 1.57, (7, 5) = .785, (7, 6) = .464, (7, 7) = 0., (7, 8) = 0., (7, 9) = 0., (8, 1) = 2.03, (8, 2) = 1.57, (8, 3) = 1.11, (8, 4) = 2.36, (8, 5) = 1.57, (8, 6) = .785, (8, 7) = 3.14, (8, 8) = 0., (8, 9) = 0., (9, 1) = 2.36, (9, 2) = 2.03, (9, 3) = 1.57, (9, 4) = 2.68, (9, 5) = 2.36, (9, 6) = 1.57, (9, 7) = 3.14, (9, 8) = 3.14, (9, 9) = 0.})

NULL

Angle of each pile from a reference pile in degrees:

theta := Matrix(9, 9, {(1, 1) = 0., (1, 2) = 0., (1, 3) = 0., (1, 4) = 90.0, (1, 5) = 44.8, (1, 6) = 26.6, (1, 7) = 90.0, (1, 8) = 63.6, (1, 9) = 44.8, (2, 1) = 180., (2, 2) = 0., (2, 3) = 0., (2, 4) = 135., (2, 5) = 90.0, (2, 6) = 44.8, (2, 7) = 116., (2, 8) = 90.0, (2, 9) = 63.6, (3, 1) = 180., (3, 2) = 180., (3, 3) = 0., (3, 4) = 153., (3, 5) = 135., (3, 6) = 90.0, (3, 7) = 135., (3, 8) = 116., (3, 9) = 90.0, (4, 1) = 90.0, (4, 2) = 44.8, (4, 3) = 26.6, (4, 4) = 0., (4, 5) = 0., (4, 6) = 0., (4, 7) = 90.0, (4, 8) = 44.8, (4, 9) = 26.6, (5, 1) = 135., (5, 2) = 90.0, (5, 3) = 44.8, (5, 4) = 180., (5, 5) = 0., (5, 6) = 0., (5, 7) = 135., (5, 8) = 90.0, (5, 9) = 44.8, (6, 1) = 153., (6, 2) = 135., (6, 3) = 90.0, (6, 4) = 180., (6, 5) = 180., (6, 6) = 0., (6, 7) = 153., (6, 8) = 135., (6, 9) = 90.0, (7, 1) = 90.0, (7, 2) = 63.6, (7, 3) = 44.8, (7, 4) = 90.0, (7, 5) = 44.8, (7, 6) = 26.6, (7, 7) = 0., (7, 8) = 0., (7, 9) = 0., (8, 1) = 116., (8, 2) = 90.0, (8, 3) = 63.6, (8, 4) = 135., (8, 5) = 90.0, (8, 6) = 44.8, (8, 7) = 180., (8, 8) = 0., (8, 9) = 0., (9, 1) = 135., (9, 2) = 116., (9, 3) = 90.0, (9, 4) = 153., (9, 5) = 135., (9, 6) = 90.0, (9, 7) = 180., (9, 8) = 180., (9, 9) = 0.})

The total number of piles in a pile group:

n__pile := 9

The length of each pile in the pile group in (meters):

L__p := 12.182   

 

``

Diameter of pile (meter):

`&phi;__pile` := .457

The radius of each pile (meter):

r__0 := evalf((1/2)*`&phi;__pile`, 2)

NULL

`&rho;__A` := 1.0

NULL

D__s := 0.5e-1

NULL

Omega := 46``

``

`&nu;__soil` := .5

NULL

E__p := 3.2*10^10``

NULL

G__s := 5.7*10^7``

NULL

 

V__s := 182.88

NULL

``

NULL

NULL

V__La := 395.845``

NULL

`&alpha;__&nu;` := proc (S__p, xi, n__pile) local `&alpha;__tmp`, flist, i, j, `&alpha;__1`, `&alpha;__2`, `&alpha;__3`; global D__s, V__La, V__s, Omega; description "Calculate the horizontal interaction factor from a refernce pile in a pile group"; flist := []; for i to `n__pile ` do for j to n__pile do `&alpha;__1`[i, j] := evalf[4](.5*(S__p[i, j]/`&phi;__pile`)^.5*exp(-D__s*Omega*S__p[i, j]/V__La)*exp(-I*Omega*S__p[i, j]/V__La)); `&alpha;__2`[i, j] := evalf[4]((3/4)*(S__p[i, j]/`&phi;__pile`)^.5*exp(-D__s*Omega*S__p[i, j]/V__s)*exp(-I*Omega*S__p[i, j]/V__s)/sqrt(2)); `&alpha;__3`[i, j] := evalf[4](`&alpha;__1`[i, j]*cos(xi[i, j])^2+`&alpha;__2`[i, j]*sin(xi[i, j])^2); if i = j then `&alpha;__tmp`[i, i] := 1.0 elif xi[i, j] = 0. then `&alpha;__tmp`[i, j] := `&alpha;__1`[i, j] elif xi[i, j] = 1.57 then `&alpha;__tmp`[i, j] := `&alpha;__2`[i, j] elif xi[i, j] <> 1.57 and xi[i, j] <> 0. then `&alpha;__tmp`[i, j] := `&alpha;__3`[i, j] end if; flist := [op(flist), `&alpha;__tmp`[i, j]] end do end do end proc:

NULL

NULL

NULL

NULLNULL

NULLNULLNULL

`&alpha;__v` := eval(Matrix(n__pile, n__pile, `&alpha;__&nu;`(S__p, xi, n__pile)))``

NULL

``

``

``

NULL

NULL

``

NULL

 

Download Test_pile.mw

Good Evening Maple Community,

Can anybody please help in the attached file. Highlighted in yellow are the three equations I'm trying to program in Maple procedure, but could not get any output due to an error message. Please Help.

 

Boyer 

 

Think I've solved my problems, thanks.

I am trying to do some algebra with the derivatives of some variables within a program. As a result i need to relable them before i feed them into solve.

To relable them i create vectors and use subs. one of these vectors behaves differently within a proc to how it behaves outside it. This is weird.

TimefullBehavesFunny := proc (nPars, nVars)
local nDiffs, timefull, timeless;
nDiffs := nPars;
timefull := [seq(dx[j, i] = diff(x[i](t), `$`(t, j)), i = 1 .. nVars)];
timefull := [seq(op(timefull), j = 0 .. nDiffs), seq(x[i] = x[i](t), i = 1 .. nVars)];
timeless := `~`[`=`](`~`[rhs](timefull), `~`[lhs](timefull));
timefull, timeless, nDiffs;
end proc

When i run the above for (3,3) i get a differet result to when i run the following
nVars:=3;
nDiffs := 3;
timefull := [seq(dx[j, i] = diff(x[i](t), `$`(t, j)), i = 1 .. nVars)];
timefull := [seq(op(timefull), j = 0 .. nDiffs), seq(x[i] = x[i](t), i = 1 .. nVars)];
timeless := `~`[`=`](`~`[rhs](timefull), `~`[lhs](timefull));

and similarly for other numbers.

any ideasas to why?

To saving my time i create a function like this:

LTTS:=proc(ff)

local ll,r,r1,r2,r3;

ll:=rhs(ff)-lhs(ff);
solve01(ll):
solve02(ll):
solve03(ll):
solve04(ll):
solve05(ll):
end:

 But when i run it, it is only give me the result of solve05(ll). when i run alone from solve01 to solve05 it still give me result.

I also try:

myfunction:solve01(ll):solve02(ll):solve03(ll):solve04(ll):solve05(ll):

It still the same :(

This one really has me baffled.

What the proc does is not important. This is just about as simple an example as I could write. Maple 2015 is complaining anytime I try to declare a local variable. The second example shows that the local declaration is needed - Maple even introduces it into the procedure that it defines.

restart;
test := proc(  )
local a;
a := 3
end proc;
Error, unexpected `local` declaration in procedure body
test := proc(  )
# local a;
a := 3
end proc;
Warning, `a` is implicitly declared local to procedure `test`
test := proc(x) local a; a := x end proc

Here's the version information for my current Maple.

interface( version );
Standard Worksheet Interface, Maple 2015.0, Windows 7, February 17 2015 Build ID 1022128

Can someone explain what is happening, and why I'm just now seeing this?

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

A lot of my life is at the moment spent using solve to solve systems of equations, and then trying to weed through the solutions maple gives to find the ones I am interested in. Specifically i'd like to have a program that can weed through the solutions and eliminate those that include equalities of the  form p[i]=-p[j] or p[i]=0  where i and j are integers (or equalities of that form with the letter q replacing p). Specifically i don't want to exclude equalities of the form p[i]=-p[j]*something+something else-another thing.... as they can be useful (or equalities of that form with the letter q replacing p).

Here is a (simple) example of the kind of equations I am likely to be solving and their output from solve:
A := solve([p[1]*p[2]*p[3] = q[1]*q[2]*q[3], p[1]+p[3] = q[1]+q[3], p[2]^2+p[3]^2 = q[2]^2+q[3]^2])

I have some code which gets rid of solutions where one variable is set to 0 

with(ArrayTools);
GetRidOfDumbSolutions := proc (sols)
local Nsols, Npars, GoodSol, GoodSols, GoodSolsCounter, i, j;
Nsols := numelems(sols); Npars := numelems(sols[1]);
GoodSols := []; GoodSolsCounter := 0;
for i to Nsols do
GoodSol := 1;
for j to Npars do
if IsZero(rhs(sols[i, j]))
then GoodSol := 0
end if
end do;
if GoodSol = 1 then
GoodSols := Concatenate(1, GoodSols, sols[i])
end if
end do;
GoodSols
end proc

but i can't see how (in maple) to detect an expression of the form p[i]=-p[j] especiall if that is being written in 2-d math. (i don't quite understand the different maths environments or how to convert from one to another or to string)

Hello,

I try to use a Catmull-Rom spline which has to match on several points.

I use a code extracted from the book "Geometry and curves with maple".

Here you can find an extract which is visible from google book :

I have slightly modified the initial procedure crom_2d. I didn't find the error in my procedure. May you help me to find the blocking point of my procedure ?

Here I attached my code:

CalculSplineMatmull-Rom.mw

Thank you for your help.

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