Items tagged with proc proc Tagged Items Feed

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):

`φ__pile` := .457

The radius of each pile (meter):

r__0 := evalf((1/2)*`φ__pile`, 2)

NULL

`ρ__A` := 1.0

NULL

D__s := 0.5e-1

NULL

Omega := 46``

``

`ν__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.

Should restart always be in separate execution group? I noticed when I write something like

>restart;
  foo:=proc()
  local sys;
  with(DynamicSystems):
  sys := TransferFunction(25/(s^2+4*s+25)):
  print(ResponsePlot(sys, Step(),duration=4));
end proc;
>

then type foo(); in the next execution group, it does not work. The plot is not generated. No matter how many times I evaluate the execution group. The proc() does not seem to be fully defined. But if I do this:

>restart;  #hit return
>foo:=proc()
  local sys;
  with(DynamicSystems):
  sys := TransferFunction(25/(s^2+4*s+25)):
  print(ResponsePlot(sys, Step(),duration=4));
end proc;
>#hit another return

and now calling foo(); then it works, and the proc() returns the plot. Only difference is that restart was in separate group. But also I had to call foo() once, then evaluate the execution group where foo() is defined two times ! for it to work (why two times?) why one time did not work? is it becuase I am loading package inside the proc()?

What are the rules for putting the restart() call? Should it always be in separate group? I put it in the same group, so that I do not have to hit return 2 times, being a lazy person. But it seems to cause problem sometimes.

And related question, why did I have to hit return 2 times in the execution group to have proc() work in the second case above?

 

I am able to get unlimeted numbers of equations describing my system. These equations are generally relate quotients of multivariate polynomials. Each additional equation I get is generally less than twice the length of the last, and it is not always the case that an equation is independant of the previous equations. Although I can get unlimited numbers of equations describing the system, it is not overdetermined.

I am interested in solving these equations for their variables. There are about 30 cases I am working on, the smallest number of evariables is six, the largest would be twenty.

I want to be able to solve these equations in the minimal time possible. But I don't understand the function solve well enough to do so.

How do I choose the equations to minimise the time taken for the command solve to proccess them?
How does the command solve work?

particularly:

  1. if I process the command solve([Eq1,Eq2,Eq3...Eqn],variables) would the command solve([Eq[1],Eq[2],Eq[3]...Eq[n],Eq[n+1]],variables) take longer if Eq[n+1] is not indipendant of the previous equations? 
  2. Is there a way of checking whether Eq[n+1] is independant of the previous vequations, fast enough for it to be useful to check the equations before they are processed?
  3. Does the ordering of the equations affect the speed of solve?
  4. Is there a way of pre processing the equations before they are put into solve that will save it time? (for example factorising them, simplifying them etc...)

 

 

Hello people in mapleprimes,

I have a question about how Int does.

The following function spy returns 0, of course, with a side effect of listing the value of x one by one to secrets.

secrets := NULL:

spy:=proc(x::{name,numeric})
  global secrets;
  if type(x,name) then
    return 'procname'(args)
  else
  secrets:=x,secrets;
  return 0;
  end if;
end proc;

 

And, with this function, calculation of the Int, that is, following brings a sequence of numbers:

evalf(Int(spy,0..1));

secrets;

.7506605773, .2493394227, .9118140517, 0.881859483e-1, .9970470440, 0.29529560e-2, 1.0000000000, 2.2449529449*10^(-11), .5000000000

 

The question I have is why the number of this sequence is not from smaller( or greater) to greater (smaller) in order,

but in random order. And, numerical calculation of Int can be done with only 9 points extracted?

 

Best wishes.

taro

 

 

 

 

 

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?

Just a simple little proc that grabs and displays some simple data for general stars (I've only listed a couple for starters).  It wasn't till later that I realized it's not an up to date database as it doesn't contain more recent interesting stars like Kepler 452.  One would have to go to the SIMBAD astronomical database for which I have not yet devoted any time for .. at least not yet. 

StarData := proc (a::string) local b, c, d, e1, e2, e3; b := StringTools:-DeleteSpace(StringTools:-Substitute(a, " ", "+")); c := HTTP:-Get(cat("http://www.stellar-database.com/Scripts/search_star.exe?Name=", b)); d := convert(c[2], string); e1 := d[StringTools:-Search("<H1>", d)+4 .. StringTools:-Search("</H1>", d)-1]; e2 := d[StringTools:-Search("Right", d) .. StringTools:-Search("Standard error in distance", d)-8]; e3 := StringTools:-SubstituteAll(StringTools:-SubstituteAll(StringTools:-SubstituteAll(e2, "<BR>", ""), "<B>", ""), "</B>", ""); print(e1); print(e3) end proc:

StarData("Sun")

"Right Ascension and Declination: 0h0m0s, +0&deg;0'0" (epoch 2000.0)
Distance from Sol: 0 light-years (0 parsecs)
"

(1)

StarData("Wolf 1061")

"Right Ascension and Declination: 16h30m18.097s, -12&deg;39'45.17" (epoch 2000.0)
Distance from Sol: 13.91 light-years (4.264 parsecs)
"

(2)

StarData("Alpha Centauri")

"Right Ascension and Declination: 14h39m35.88s, -60&deg;50'7.4" (epoch 2000.0)
Distance from Sol: 4.395 light-years (1.347 parsecs)
"

(3)

StarData("Sirius")

"Right Ascension and Declination: 6h45m8.871s, -16&deg;42'57.99" (epoch 2000.0)
Distance from Sol: 8.601 light-years (2.637 parsecs)
"

(4)

````


Download StarData3.mw

 

 

 

 

1 2 3 4 5 6 7 Page 1 of 8