Items tagged with procedure procedure Tagged Items Feed

I am trying to find the root of an equation that involves a procedure and a definite integral (solved numerically). Of course, I don't need the root to be found symbolically, but numerically would be fine. The problem is, I keep getting the error

"Error, (in fsolve) Can't handle expressions with typed procedures"

whenever I try to solve it. Anyone have any ideas? My worksheet is here: Table-1-duplication-mapleprimes.mw 

 

I noticed, when using

restart;
with(LibraryTools);
Browse();

That some procedures have lost all its formating. No line numbers, no spaces in between, very hard to read. For example, dsolve() in maple.mla is like this. While other procs are well formated and easy to read.

Is there a reason for this? And is there a way to fix this in Browse() to be able to read the source? It is impossible to read it like this readlly. Maple 18.02 on windows.

Hi,

 

I've encountered a problem with Maple.

 

Is it possible to create a procedure which both displays some plots and also returns a value?

 

When I write a simple example:

 

It plots a circle as expected.

But when I add return:

 

It returns value 2, but no plot is displayed.

Is it possible to do both, display and return a value?

I used to write two copies of procedure, one for plotting and one for returning value.

But thats not "pretty" solution.

 

Thanks for help.

Hallo, I have a list with derrivatives. I'd like to choose elements with highest derrivative.

Is there any procedure in Maple to determine order of derrivative?

Hi experts

 

In a procedure with no declared parameteres I would like to return (print) the passed arguments (expecting Matrix structures) in a modified form along with the name of the symbol holding the structure passed as arguments.

 

That is, the procedure just iterates through the _passed arguments in a for-loop to display the name of the the passed argument (the symbol), a colon and then the modified matrix structure.

My problem is that when looping from i to _npassed arguments, refering to _passed[i] gives me the evaluated form.Tat is what I need to modify the structure but not to list the symbol name.

 

Say I wanted to print a transposed version of my passed matrices. Then I would call

M:=<<1,2>|<3,4>>;

myProc(M);

And the result I want would be

M: <<1,3>|<2,4>>

But I don't know if _passed holds the symbol names or just the evaluated versions of the passed arguments??

And theoretically the passed argument (assuming a matrix) could be the matrix structure put directly in the procedure call, in which case there is no symbol to refer to.

 

I hope you get my question and can help me out.

 

Thanks

Simon

 

In this document, I think that is the relevent section. But I couldnt understand it.

 

I want something like this

>plot(sin(x),color=yellow);

>plot(sin(x),color=organe);

>plot(sin(x),color=red);

>plot(sin(x),color=green);

>plot(sin(x),color=ABC); # error

>plot(sin(x),color=CBA);# error

optional, but works fine within a given sets of choices.

 

How do I write a procedure like that?

 

Thanks!

Hello people in mapleprimes,

 

I want to draw a graph of a procedure.

 

filter:=x->if x<10 then 1-x/10 else 0 fi;

plot('filter(x)',x=0..20);

 

works well. But, I don't know why it is needed for filter(x) is wrapped with foward quotte ' .

I changed that quote to back quote ` but, in this case the result hadn't appeared.

And, without the foward quote ', error appears.

And, even if I wrapped x with ' as in plot('filter(x)','x' =0..20),

a graph appeared properly, though I cannot understand why wrapped x, 'x' is right.

 

Please teach me the logic of the above code.

Best wishes.

 

taro yamada

 

So the pseudocode I'm trying to translate into maple is for the greedy vertex coloring algorithm.

The pseudo code is:

Initialize:
1. for i = 1 to n do
2. f[i] := 0 (: no color assigned yet to vertex i :)
3. end(for)
Main loop:
4. for i = 1 to n do
5. let f[i] be the smallest positive integer
which is not in the set {f(j) : j ∈ adj[i]}
6. end(for)
7 return f

 

The closest I've gotten though is:

greedy := proc (G)

local i, j, n, k, L::list;

description "Take simple graph G and return a coloring of the vertices with at most Delta(G)+1 colors";

n := nops(Vertices(G));
L := [seq(x, i = 1 .. n)];
L := subsop(1 = c(1), L);
j := 1;
for i from 2 to n do
L[Vertices(G)[i]] := c(0)
end do;

for i from 2 to n do
   for k to i do
        if member(Vertices(G)[i], Neighbors(G, Vertices(G)[k])) then j := j+1
       end if; 
   end do;
L[Vertices(G)[i]] := c(j)
end do;
return L;
end proc;

Basically my procedure is returning more than delta+1 colors for most graphs, how can I edit it to fix this? I'm guessing the problem is somewhere in my nested loops. Also, I cannot use commands like greedycolor or isvertexcolorable. Thanks.

 

Hi, I'm trying to write a maple procedure to differentiate a function from first principles and so far I have

First_Principle := proc (f); for f do A := simplify((f(x+h)-f(x))/h); Limit(A, h = 0) = limit(A, h = 0) end do end proc

and from there I have no idea where to go. Does anybody have any ideas? Thanks!

I have question about how to write the expression to get the order in the sequence?

For exmple, if I have this sequence,

E:=[0,2,7,15,26,40]

I want to write a procedure that tells me the location of any input,x in the sequence E.

For example, if I choose x:=3, then the number 3 is actually between 2 and 7, so it will give me the answer C(x)=3 (because 7 is the third elemet).

I try to write the procedure but there always wrong! I do not know what expression should I write!

C:=proc(x)
local
for i from 1 to nops(E) do
if x<=E[i] then
c:=E[i]
fi;od;
end;

Please help! 

So I'm trying to make a procedure to tell is a sequence is graphical or not.
seqgraph:= proc (L::list)

local k::integer, i::integer, n::integer, a::integer, S;

n := numelems(L);

S := convert(L, `+`);

a := 0;

if type(S, odd) then print("not graphical")

else for k to n do

if add(L[i], i = 1 .. k) <= k(k-1)+add(min(k, L[i]), i = k+1 .. n) then a := a+1

else a := a+2

end if;

end do;

end if;
if n = a then print(graphical)

else print("not graphical")

end if;

end proc;

 

 I'm trying to say that if that equality (which is part of the erdos gallai theorem) holds for that value of k then we'll add one to a value (a). Thus, if a=n at the end then the ineuqality was true for each k and thus it would it should print "graphical" but every list I test it one prints 'not graphical'. Where is my mistake? I get an error saying it can't execute add?

So if I have a procedure like 

with(GraphTheory)

tneighbors := proc (G::Graph)

local numvertices::integer, i::integer, currentvertex;

numvertices := nops(Vertices(G));

for i to numvertices do

currentvertex := Vertices(G)[i];

if nops(Neighbors(G, currentvertex)) = 2 then print(currentvertex)

end if;

end do;

end proc;

How do I make it so the output gets returned as a set?

For example, if I do  twoneighbors(G); and get
1

7

4

How do I make it so the output is listed as a set like {1,4,7}? Thanks.

I have a complicated equation which you can find in the file below. I want to multiply both sides of equaiton by cos(beta[1,j__1]*z) and integrate from 1 to L. I have many such similar equations so I decided to write a procedure to do these staffs for me.

Can you give me simple suggestions on how to write such a procedure. The procedure will take the "equation", "multiplier" and "limits of integration" as inputs and gives the "integrated equation" as the output. Integration is perfomed by the inert function "Int".

Many thanks.

Equation.mw

I'm used to Mathcad, and I am very new to Maple. Something I cannot figure out right now is how to define multiple elments of a matrix using a function.


Input Data

Define system dimensions as n:=2;

i:=1..n;

j:=1..n;

lambda:=Matrix(n);

Lambda:=Matrix(n);

upsilon:=vector(n); 

Minor side note: I originaly had upsilon defined using the syntax "Vector[row](ncomp)", but this was giving me an 'exponentiation' operation error, so I changed it to what it is now (basically a list/array, which I guess has different type definitions that no longer cause the error?).

lambda[1,2]:=471.0433;

lambda[2,1]:=883.7530;

upsilon[1]:=58.69;

upsilon[2]:=18.07;

The Problem I'm Having

Now I just want to define Lambda using a function to define all elements (like I would in Mathcad).

Lambda[i,j]:= (upsilon[j]/upsilon[i]) * exp (-lambda[i,j]/2853);

which gives me an extremely long error message:

Error, invalid input: exp expects its 1st argument, x, to be of type algebraic, but received Matrix(2, 2, {(1, 1) = -0.3504976272e-3, (1, 2) = -.16509955895845776, (2, 1) = -.30975332953088164, (2, 2) = -0.3504976272e-3}, datatype = float[8]

As far as I can tell (keep in mind that this is my very first Maple project) that it doesn't like lambda as a matrix? But shouldn't it just evaluate to the element? and why is (2,2) and (1,1) giving values, because it should intialize to zero, so exp(0) = 1 in these cases??

I tried to simplify further by just trying

Lambda[i,j]:=(upsilon[j]/upsilon[i]);

but then it just gives me 1, and when I look into Lambda all the elements are now 1 when only the diagnol elements should be 1 (the rest some fractional amount)??

I am at a complete loss. I thought about doing something like For i = 1 to n etc. but then it just looks like coding, which defeats the purpose of trying to make a calculation sheet documenting the procedure...

Any help and/or insights into what I am doing wrong here would be most welcomed :)

P.S. I've just noticed that there is an upload option :/ Wilson_Equation.mw.

 

 

``

restart:

 

C=2;

C = 2

(1)

w[2]*s[1]+w[1]*s[2];

s[1]*w[2]+s[2]*w[1]

(2)

C=3;

C = 3

(3)

(w[3]*s[2]+w[2]*s[3])*s[1];

(s[2]*w[3]+s[3]*w[2])*s[1]

(4)

C=4;

C = 4

(5)

((w[4]*s[3]+w[3]*s[4])*s[2]+w[2]*s[3]*s[4] )*s[1];

((s[3]*w[4]+s[4]*w[3])*s[2]+w[2]*s[3]*s[4])*s[1]

(6)

C=5;

C = 5

(7)

(((w[5]*s[4]+w[4]*s[5])*s[3]+w[3]*s[4]*s[5] )*s[2]+w[2]*s[3]*s[4]*s[5] )*s[1];

(((s[4]*w[5]+s[5]*w[4])*s[3]+w[3]*s[4]*s[5])*s[2]+w[2]*s[3]*s[4]*s[5])*s[1]

(8)

C=6;

C = 6

(9)

((((w[6]*s[5]+s[6]*w[5])*s[4]+w[4]*s[5]*s[6])*s[3]+w[3]*s[4]*s[5]*s[6])*s[2]+w[2]*s[3]*s[4]*s[5]*s[6])*s[1];

((((s[5]*w[6]+s[6]*w[5])*s[4]+s[5]*s[6]*w[4])*s[3]+s[4]*s[5]*s[6]*w[3])*s[2]+s[3]*s[4]*s[5]*s[6]*w[2])*s[1]

(10)

 

``


Download pattern.mw

 

This probably isnt too difficult to write a procedure to generate the expression, given C=2,3,4,5,...

But I may be thinking too much and stuck...

 

Also, I am thinking that if it is possible to use something like a "fibonacci sequence", in the famouse example here, which uses the in a procedure. Probably, we dont need to use this.

 

Thanks,

 

casper

 

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