Items tagged with procedure procedure Tagged Items Feed

The following code is part of my attempt to answer the recent Question about the bifurcation of the map f:= x-> exp(x^2*(a-x)). Two very weird things are happening. They can be seen by applying trace to f. The first is that the input argument to f seems to be changed to a very large integer. The second is that for some real values of a and x, I get imaginary results from this obviously real-valued function. Why are these things happening?

restart:

f:= x-> exp(x^2*(a-x)):

trace(f):

Iterate:= proc(a, x0:= 1., n:= 2000)
local A:= hfarray(1..n, [x0]), f:= subs(:-a= a, eval(:-f));          
     #evalhf(
          proc(f, A, n)
          local k;
               for k from 2 to n do A[k]:= f(A[k-1]) end do
          end proc
          (f, A, n);
     #);
     evalf[4]~(convert(A[1000..], set))
end proc:

Iterate(1.05);

{--> enter f, args = 4607182418800017408

 

HFloat(1.0512710963760241)

 

<-- exit f (now in unknown) = 4607413323290551347}
{--> enter f, args = 4607413323290551347

 

HFloat(0.9985962074909431)

 

<-- exit f (now in unknown) = 4607169774561176020}
{--> enter f, args = 4607169774561176020

 

HFloat(1.0525960836530153)

 

Warning,  computation interrupted

 

Iterate(.75);

{--> enter f, args = 4607182418800017408

 

.754589752755861+.192678397202388*I

 

<-- exit f (now in unknown) = HFloat(0.7545897527558614)+HFloat(0.19267839720238844)*I}

Error, (in unknown) unable to store 'HFloat(0.7545897527558614)+HFloat(0.19267839720238844)*I' when datatype=float[8]

 

 

 

Download bifurcation.mw

hi,

i'm trying to figure out where i did a mistake by coding reducedEchelonForm.

with(LinearAlgebra):
reduced:=proc(M)
 local l:=1, m:=RowDimension(M),n:=ColumnDimension(M),i,j; # l current column
 for i from 1 to m do # going trough every row item
  if n<l then # ColumnDimension need to be bigger than current column
   return M;
  end if;
 j:=i; # given current row item
 while M[j,l]=0 do # search for first rom item unequal zero
  j:=j+1;
  if m<j then # end of row
   j=i;
   l=l+1;
   if n<l then # end of rows and columns -> finish
    return M;
  end if;
 end if;
end do;
M:= perm(m,n,j,i).M; #permute row j and i
if not(M[i,l]=0) then # multiply row i with M[i,l])^(-1)
 M:= multiplikation(m,n,i,(M[i,l])^(-1)).M;
end if;
for j from 1 to m do # subtract every row j with row i for M[j,l]-times
 if not(j=i) then
  M:= addition(m,n,j,i,-M[j,l]).M;
 end if;
end do;
l:=l+1; # increase l by 1, next iteration i increase either
end do;
end proc:

 

Hint: perm(...),multiplikation(...) and addition(...) are the elementary matrices. They are working.

 

Now i got an error by running it: 

L:=Matrix(2,3,[1,2,3,4,5,6]);
reduced(L);
Error, (in reduced) invalid left hand side in assignment

Can someone explain me these error? And maybe a hint what i need to fix in my code?

Greets felix

How I can write a procedure in Maple 18 that it receives:

Inputs: function f(x) and real unmbers a and b (as interval [a,b]) and natural unmber n 

then devides interval [a,b] to n subinterval and computes f'(a), f'(a+(b-a)/n), f'(a+2(b-a)/n),..., and f'(a+n(b-a)/n)=f'(b)

and

showes at output: graph f(x) and all points [a,f'(a)], [a+(b-a)/n, f'(a+(b-a)/n)],[a+2(b-a)/n, f'(a+2(b-a)/n)]..., and [a+n(b-a)/n,f'(a+n(b-a)/n)] on a coordinate plane x-y

How I can write a procedure with Maple 18 that it receives function f(x) and x=a as inputs, 
then compute f'(a) and shows in output these 2 cases:

1) value f'(a)
2) curves f(x) ,y=f'(a)*(x-a)+f(a) and also the point (a,f'(a)) in a system ?

Hello,

I would like to obtain the display of several outputs from a procedure.

Sorry for this question which should be quiet simple but I didn't manage to solve my issue. By the past, I always wanted to obtain only one output from a procedure.

I put attached a example of procedure which calculates x^2 and x^3 for a given value of x.

With my procedure, I didn't obtain the display of the output calculating the square value.

How can I display all the outputs of a procedure ?

Thank you for your help

ExampleOfprocedure.mw

I'm trying to write a procedure that computes Pollard's P-1 Method for a given integer n, and then outputs the prime factorisation of n.

Here is what I have so far:

Pollard := proc (n)
local i, r, g;
r[1] := `mod`(2^factorial(2), n);
for i from 2 while gcd(`mod`(r[i-1]-1, n), n) = 1 do
r[i] := `mod`(2^factorial(i+1), n) end do;
g[i] := gcd(`mod`(r[i-1]-1, n), n);
if g[i] < n then return g[i]
else return n
end if
end proc;

But my procedure doesn't seem to work for a lot of large values for n.
And also I can't figure out how to make it actually output the factorisation.

Any help would be appreciated.

>mylist:=462;

mylist:=462

>kekuncirahsia:=proc(n) local c,d,r,sum; c:=n; while (c>9) do sum:=0; d:=c; while (d>9) do r:=irem(d,10); sum:=sum+r; d:=iquo(d,10);od; c:=sum+d;print(c);od;end;

>kekuncirahsia(mylist);

12

3

 

Hi, anyone know how i need to write my command to get this >> kekuncirahsiafinal:=3

I just want it to print the last digit..

Thank you~=]]

The solution should show the procedure.
But without tutor.

 

Problem.mw

 

Atte.

Lenin Araujo Castillo

 

Every time I try to type in a procedure I get the error:  

Error, unterminated procedure

immediately after typing in the first line.  How can I type in the remaining lines of my procedure?

Note:  in maple 7 (years ago) I never had this problem.

 

Think I've solved my problems, thanks.

I wrote the following procedure that evaluates i-th B-spline basis function of degree n over the knot vector T:

N := proc(i, n, t, T)

if (n = 0) then
    if ((t >= T[i]) and (t < T[i+1])) then
        return 1.0:
    else
        return 0.0:
    fi:
fi:

return (evalf((t-T[i])/(T[i+n]-T[i]))*N(i, n-1, t, T) + evalf((T[i+n+1]-t)/(T[i+n+1]-T[i+1]))*N(i+1, n-1, t, T)):

end proc:

 

Now, I want to compute

int(N(i, n, t, T)*N(j, n, t, T), t=0..1, numeric),

where i, n and T are given. However, Maple evaluates N and, since t is unknown, I get the following error:

"Error, (in N) cannot determine if this expression is true or false: .1 <= t and t < .25"

In http://www.maplesoft.com/support/help/Maple/view.aspx?path=evalf/Int  I read that in order to integrate a procedure, one should write (see the example given there)

evalf(Int(N*N, 0..1));

however, in my case, It will not work because I must pass the known parameters i, n and T. Is there a way to solve my problem?

 

 

 

 

Hi Guys, 

I'm trying to find stationary points of a numeric function. Any help would be appreciated. 

Assume I have a numeric function g(x). I'm attempting the following:

deriv:=(x)->fdiff(g(t),t=x); (I can't use the D operator as it doesn't like g(x))

Now deriv(x) <- Can be computed and computes the value quickly and easily. However plot and other functions require algebraic functions. I can plot this (with difficulty) via the following

plot(deriv,-10..10) <- This avoids converting to algebraic function and runs as a procedure. 

I can't use convert(deriv,algebraic) as it fails. 

I want to use the Student[NumericalAnalysis]Roots command, but it requires an algebraic function and I can't use the procedure trick which I did in the plot command. 

Does anyone know a better way of doing this? or is there a way I can write the numerical differivative as an algebraic function. (I've tried fsolve <- But this guy doesn't give me the correct answers generally). 

Thanks guys. 

 

 

 

The issue Type check of parameters was resolved using the depends modifier. As far as I can tell, this modifier is not allowed for expected or keyword parameters, though. Thus the issue seems to reemerge for these types of parameters. Consider the following test example:

createModule := proc(V::Vector)
   local dim := LinearAlgebra:-Dimension(V);
   module()
      export f,g,h;
      f := proc( x::depends('Vector'(dim))              ) x end proc;
      g := proc( x::expects('Vector'(dim)) := something ) x end proc;
      h := proc({x::        'Vector'(dim)  := something}) x end proc;
   end module
end proc:
createModule(Vector(4)):-f(    Vector(4));
createModule(Vector(4)):-g(    Vector(4));
createModule(Vector(4)):-h(x = Vector(4));

The function f is just a restatement of the already resolved issue, compare the above link, while the functions g and h are for the expected and keyword parameter cases, respectively. The problem remains the same: the variable dim is not evaluated for g and h. What to do? Does there exist a solution equally satisfactory as the one for f?

Consider the following two functions:

f := (theta) -> (x) -> theta*x;
g := unapply(unapply(theta*x,x),theta);

I would have expected f and g to behave identically. Apparently I am wrong, though:

f(phi)(x),
g(phi)(x);

But why? If the functions were alternatively defined as

f := (theta,x) -> theta*x;
g := unapply(theta*x,theta,x);

using unapply only once, then they would behave identically. But that is not quite what I want: I would like to have parameter-valued procedures of a single parameter, not (parameter-less) procedures of two parameters.

with(Student[LinearAlgebra]);
example1 := Matrix([[1, 2, 3], [4, 5, 6], [6, 7, 8]]);
whattype(example1);

testproc := proc (A) print(whattype(A)) end proc;

testproc(example1);

The whattype() calls output:

Matrix
proc() ... end proc

I don't understand why what is a Matrix type outside the procedure seems to change into this unrelated type? This is really bizarre. I feel like it may be something outside my code? Thank you.

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