Items tagged with proc proc Tagged Items Feed

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

 

 

 

 

Hello everbody.

Newton:=proc(p[0],TOL,N)  

 local i,p,f;   i:=1;

 while i<= N do      

     p:=p[0]-(f(p[0]))/(diff(f(p[0]),x));    

     if abs(p-p[0])<TOL then             return p;     else i:=i+1;            p[0]:=p; end if;  

end do;

printf("The method failed after N iterations,N=%d",N);  end proc:

Hi, I'm trying to create a procedure like this;

f:=proc(a);
if a in RealRange(0,1) then a else no;
end if;
end proc;

 But when I try with f(0.5); for instance, I get the error: 

Error, (in f) cannot determine if this expression is true or false: .5 in RealRange(0, 1)

What am I doing wrong here, why can Maple not determine this?

Thank you! 

Collatz := proc (n)

    local count;

       while n != 1 do

           if `mod`(n, 2) = 0 then n := (1/2)*n

           else n := 3*n+1

           end if;

           count := count+1;

       end do;

print(count);

end proc:

 

I wanna correct 'illegal use of formal parameter' error.

'n' always goes to 1 through 'while statement'.

The following code works fine:

restart;
with(LinearAlgebra): with(MTM): with(StringTools): MultivariateNormalSample := proc (Sigma, V, N) local d; d := LinearAlgebra:-Dimension(V); LinearAlgebra:-LUDecomposition(Matrix(Sigma, datatype = float[8]), 'method' = 'Cholesky') . ArrayTools:-Alias(Statistics:-Sample(Normal(0, 1), d*N), [d, N])+ArrayTools:-Replicate(Vector[column](V, datatype = float[8]), 1, N) end proc: S := MultivariateNormalSample(`<,>`(`<|>`(1, 2), `<|>`(2, 5)), `<,>`(2, 3), 100):
W := ~int8(~round(S)):
K := convert(W, string):
K := Drop(K, 17):
K := Select(IsDigit, K):
M := seq(PadRight(K[i], 2), i = 1 .. Length(K)):
Z := M[1]:
for i from 2 to Length(K) do Z := cat(Z, M[i]); if `mod`(i, 2) = 0 then Z := cat(Z, "\n") end if end do:
Z;

but if I make a proc out of it then it breaks down on the line:

 W := ~int8(~round(S)):

There seems to be an issue with the elementwise tilde operator.

restart;
Generate:=proc()
local MultivariateNormalSample,S,W,K,M,Z,i;
with(LinearAlgebra): with(MTM): with(StringTools):
MultivariateNormalSample := proc (Sigma, V, N) local d; d := LinearAlgebra:-Dimension(V); LinearAlgebra:-LUDecomposition(Matrix(Sigma, datatype = float[8]), 'method' = 'Cholesky') . ArrayTools:-Alias(Statistics:-Sample(Normal(0, 1), d*N), [d, N])+ArrayTools:-Replicate(Vector[column](V, datatype = float[8]), 1, N) end proc: S := MultivariateNormalSample(`<,>`(`<|>`(1, 2), `<|>`(2, 5)), `<,>`(2, 3), 100):
W := ~int8(~round(S)):
K := convert(W, string):
K := Drop(K, 17):
K := Select(IsDigit, K):
M := seq(PadRight(K[i], 2), i = 1 .. Length(K)):
Z := M[1]:
for i from 2 to Length(K) do Z := cat(Z, M[i]); if `mod`(i, 2) = 0 then Z := cat(Z, "\n") end if end do:
return Z:
end proc;Generate();

I seem to have missed something. Any ideas?

Harry

I have a maple proc for which I would like to find parameters to fit data I have. The proc has an 'if' statement in it, and when I try to use the CurveFitting function 'NonlinearFit' function, I'm getting an error.

Is there a curve fitting function that can be used with procs with 'if' statements in them?

Thanks. 

1 2 3 4 5 6 7 Page 1 of 8