Items tagged with procedure procedure Tagged Items Feed

Hello those in Mapleprimes,

I want to obtain the result of the following codes,

shift:=(f::procedure)->(x->(f(x+1))):

shift(sin);

 

as x->sin(x+1)..................(1)

 

But, the result I could get was only

x -> f(x + 1)......................(2)

 

Please teach me how I can obtain the result as (1), not (2)?

 

Thanks in advance.

 

taro

Dear those who are in Mapleprimes,

 

As I can't understand how Maple calculate the quick sort, I write the present question, hoping that someone give me a hint.

In essence, nested procedure I cannot understand is this:

 

quicksort:=proc(A,m,n)

....................

if m<n then

quicksort(A,m,p-1);.................................(1)

quicksort(A,p+1,n)...................................(2) 

end if;

eval(A);

end proc:

 

Details were ommitted, but I have to say that p is the number between m and n, which is determined by ommitted parts of 

the procedure.

And, with this nested procedure, 

quicksort([2,4,1,5,3],1,5) is calculated.

 

What I want to know is how to process the parts of (1) and (2).

If after (1) is processed, (2) is processed, what is the value of p in (2).

Is it the p which is determined successively through processing nested value of (1)?

 

Thank you in advance.

 

taro

We have two texts in a certain language, represented as Maple  strings,  e. g.
"die einkommen der landwirte sind fuer die abgeordneten ein
buch mit sieben siegeln um dem abzuhelfen muessen dringend alle
subventionsgesetze verbessert werden" and
"die steuern auf vermoegen und einkommen sollten nach meinung
der abgeordneten nachdruecklich erhoben werden dazu muessen die
kontrollbefugnisse der finanzbehoerden dringend verbessert werden".
We have to find the maximal common subsequence of the words in the both texts,
i.e. "die  einkommen der abgeordneten muessen dringend verbessert werden" for
the above. If there are a few such ones, then only one is enough. How to program
that by SringTools and/or EssayTools in maximum efficient way? A compiled procedure is welcome.

As I stated in an earlier post, I'm new at this.

I'm trying to write a procedure to calculate what is called a "crescent latitude". The full formula can be seen here: https://db.tt/QAUzH5i0.

b is equal to 0.081819221; it takes a single parameter φ (latitude of a location in degrees)

 

I normally get errors like unable to parse, unable to match delimters, etc. and the result is the name of the procedure and whatevere value of the parameter I put in parenthesis, not the calculated value.

Anybody can help?

 

Thanlk you

Martina

Hi

I need you to help me in writting procedure with input "r" ( order of derivative) and some coefficients seq(alpha[i],i=1..N).  My code work very well, need only put all the element in procedure with output The Taylor series obtained in last line of my code and the order of error.  I want the procedure return the coefficients beta used in the series and the order of Error  and the coefficients beta[i]

May thinks.

Second_Question.mw

 

I will not modify my previous question: only I add this remark. I tried to write these lines of procedure.
Add_display.mw

I need only to add( if the procedure is true) these lines in my procedure.  These lines gives the degree of error computed in the code, but when I put these lines in the codes, there is an error. Thanks for your help.

Degree := degree(Error,stepsize);
    if (showorder) then:
       print(cat(`This stencil is of order `,Degree));
    fi:
    if (showerror) then:
       print(cat(`This leading order term in the error is `,Error));
    fi:
    convert(D[r$n](f)(vars) = stencil,diff);

 

 

 

Hi,

I want to display the matrix M, I used return M, in this procedure, but no matrix M displayed.

restart;
N:=2:
N:=2;
ff:=proc(N)
local M,i,p;
M:=array(1..2*N+1,1..2*N+1):
for i from 1 to 2*N+1 do
for  p from 1  to 2*N+1  do
   if p=1 then M[p,i]:=-2;
    elif  p=2*N+1  then M[p,i]:=-3;
else
M[p,i]:=0;
end if; end do; end do;
return M;
end proc;

 

Many thinks

I am trying to make a plot that shows the amplitude of a second order linear system relative to an external driving frequency ω, but I am having trouble defining my function. Here's what I have so far.

 



 

When I pass the amp function ω=0 and F=4, I don't get back what I expect. I would think that those symbols should evaluate to the values I passed in. I have tried different parameter names etc..

 

All I am trying to do is plot the function shown above for F=4 and 0≤ω≤5. I know I could manually plug the values in, but I thought I'd ask the proper way to do it. Any help is greatly appreciated. Thanks folks!

Hi,

Is there any difference between

Matrix(4,5,(K,C)->K+C);

and

Array(1..4,1..5,(K,C)->K+C);

 

Say if I have a very 'complicated' procedure myfunc(K,C) that takes two options, but it runs all dependently.

Matrix(4,5,(K,C)->myfunc(K,C));

and

Array(1..4,1..5,(K,C)->myfunc(K,C));

Which one is more efficient? The final ouput of each run from myfunc is just a integer value.

 

The reason I am asking it that i think both runs on a 'single' thread (core) as CPU usage is always very low, around 15-20%.

If I look at the task manager, some cores (threads) arent doing anything.

Is there anyway to speed things up?

 

Thanks,

f:=C->sum(x[cat(new,c)],c=1..C);

f(4) # does not give me what i want , which is

x[cat(new,1)]+x[cat(new,2)]+x[cat(new,3)]+x[cat(new,4)];

 

seq(x[cat(new,c)],c=1..4);
convert([%],`+`);

This works. But it's just a simple example to illustrate my problem.

 

Is there a way to fix this 'cat' problem in the procedure 'f'?

 

Thanks,

 

casper

Hi All,

I used the command map to apply a procedure to elements of a array like this:

 

Why did I get the null array "[]"?

A vector was also used and got the similar result: 

 

I'd appreciate any help on this topic. Thank a lot.

Given the lengths of the three sides of a triangle, write a procedure, triType, to produce an output which shows whether the triangle is acute, right or obtuse with the three sides given??


firstly apologies in advance for stuff in this question such as "triangle symbol",  my computer is pretty old. 


ok so i was confused a bit here, what i'm trying to do is write a maple procedure that computes Af for a given f contained in V . except we only need to correct the bug in the script below. This script demonstrates such a procedure in the case that omega is a square. The domain is given here as the negative set of a function F contained in V .  I have left in notes where/what i think we need to do but i dunno how to...

N:=10 ; # Global Var
F:=(x,y)->sgn(abs(x-N/2)+abs(y-N/2)-N/4);
Average := proc(F, f0) local f, i, j;
f := f0; # !!!!!!!!!!!!!! something is bad here...
for i to N do for j to N do
if F(i, j) < 0 then
f[i, j] := (f0[i - 1, j] + f0[i + 1, j] + f0[i, j + 1] + f0[i, j - 1])/4 ;
end if;
end do;end do;
return f;
end proc;
f0:=Matrix(N,F); # just to have something to test the procedure
Average(F,f0); # does not return the expected average, modifies f0

 

the necessary information we were given to produce this so far was..

Let N be a positive integer and [N] = {i contained in N | 1<= i <=N }  Let "Omega" C {(i,j) contained in [N] x [N] | 2<=i,j<=N-1} be a subset. Let V = R^([N]x[N]) be the vector space of real valued functions [N]x[N] -> R
and A, "triangle symbol":V->V (average) and "triangle symbole" (Laplacian) be the linear maps such that
[Af](i; j) = f(i; j)      if (i; j) not contained in "Omega"   OR

                             [f(i, j + 1) + f(i, j - 1) + f(i + 1, j) + f(i - 1, j)]/4 if (i,j) is contained in "Omega"

["traingle symbol"f](i,j) =  0 if (i,j) isnt contained in "Omega"   OR

                            ( f(i,j) - [f(i, j + 1) + f(i, j - 1) + f(i + 1, j) + f(i - 1, j)]/4 )    if (i,j) is contained in "Omega"

 Please and thank you for any help in advance <3

                           

Dear all;

Please give me few minutes to correct the output of this procedure.Many thinks. 
We will solve the waves equations: diff(f(x,y,t),t$2)=c^2*( diff(f(x,y,t),x$2) +diff(f(x,y,t),y$2));  where (x,y,t) in [0,1]*[0,1]*[0,T] using finite difference.  With Initial boundary conditions: [u(0,y,t)=u(1,y,t)=0],   [u(x,0,t)=u(x,1,t)=0],  [u(x,y,0)=f(x,y),   diff(u(x,y,0),t)=g(x,y)]... The code is done and perfect but....The output of this procedure is Nothing. How can I plot the solution...

f:=(x,y)->x*(x-1)*y*(y-1);
g:=(x,y)->0;
analytical_sol:=proc(dx,dy,dt,Tf)
local Ft, Fx,Fy,x,y, c1,c2,c,j,k,i,u;
Ft := floor(Tf/dt)+1;
Fx := floor(1/dx)+1;
Fy := floor(1/dy)+1;
x:=[seq(0..1,dx)]:
y:=[seq(0..1,dy)]:
c1 := (c*dt/dx)^2;
c2 := (c*dt/dy)^2;
#Initial position
for j from  1 to Fx do  
   for k from 1 to Fy do
  u[j,k,1] := f(-dx + j*dx, -dy + k*dy) -dt*g(-dx+j*dx, -dy + k*dy);
   u[j,k,2] := f(-dx + j*dx, -dy +k*dy);
end do;
end do;

# Boundary values j=1
for i from  1 to Ft +1 do
      for k from 1 to Fy do
         u[1,k,i] := 0;
      end do;
      for k from 1 to Fy do
         u[Fx,k,i] := 0;
      end do;

     for j from 1 to Fx do
         u[j,1,i] := 0;
      end do;
   
   for j from 1 to Fx do
         u[j,Fy,i] := 0;
      end do;
end do;

for i from 3 to Ft + 1 do
  for j from 2 to Fx-1 do
    for k from 2 to Fy-1 do
u[j, k, i] := 2*u[j,k,i-1] - u[j,k,i-2] + c1*(u[j+1,k,i-1]-2*u[j,k,i-1]+u[j-1,k,i-1]) + c2*(u[j,k+1,i-1] - 2*u[j, k, i-1] + u[j,k-1, i-1]);
end do;
end do;
end do;
return Matrix([seq([seq([seq(u[i,j,k],i=1..Fx)],j=1..Fy)],k=1..Ft)]):
end proc:

## Try the test
f:=(x, y) -> x (x - 1) y (y - 1)
g:=(x, y) -> 0;
analytical_sol(0.1,0.1,0.1,2);
                      

I am trying to write a procedure that have the following input:  expr, xdata,ydata. [dependent variables list]

I want a procedure to calculate Rsquare following the method described in 

http://www.mapleprimes.com/questions/120014-How-To-Calculate-Coefficient-Of-Determination

 

But I want the proc to take any abitary function and be able to identify the  dependent variable...how can I approach it? what function can I use to match [dependent variable list] in expr??

 

Thanks

 

 

It is well known that  operating in  geometry  package when setting objects symbolically some inconveniences arise. The error occurs if you do not set limits on the parameters. I wrote the procedure for finding center and radius of the circumscribed circle, devoid of drawbacks:

restart;

Circumcircle:=proc(a,b,c)

local x1, y1, x2, y2, x3, y3, n;

uses geometry;

x1,y1:=op(a); x2,y2:=op(b); x3,y3:=op(c);

n:=x2*y3-x3*y2+x3*y1-x1*y3+x1*y2-x2*y1;

point(A,a), point(B,b), point(C,c);

if type(n,realcons) then triangle(T,[A,B,C]); circumcircle(cc,T,'centername'=OO);

return [coordinates(OO),radius(cc)]  else assume(n<>0);

triangle(T,[A,B,C]); circumcircle(cc,T,'centername'=OO);

simplify([coordinates(OO),radius(cc)]); fi;

end proc:

 

At initial startup procedure works correctly:

Circumcircle([x1,y1], [x2,y2], [x3,y3]);

 

 

But if you change the arguments of the procedure, an error occurs:

Circumcircle([x1,1], [x2,y2], [x3,y3]);

 

But if you run the procedure again with the same arguments, the error disappears:

Circumcircle([x1,1], [x2,y2], [x3,y3]);

 

What is the reason?

Circumcircle.mws

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