# Question:Bug in maple procedural evaluation?

## Question:Bug in maple procedural evaluation?

Maple

I have a relatively simple procedure that attempts to provide a continuous function from arctan.

This function, when called is not returning values properly for some unknown reason. It is not updating variables.

The code is relatively simple, given a continuous vector valued function it gets the angle using arctan(y,x). The problem with this function is that it is not continuous as it only evaluates the function along the principle branch.

What the function below attempts to do is find out when the function has a jump discontinuility and it provides the amount to shift to make the output continuous. To do this requires some memory which is stored in the global variable l.

vs := t->[cos(3*t), sin(t)];
nvs := t->sqrt(vs(t)[1]^2 + vs(t)[2]^2);
v := t->vs(t); l/~nvs;

l := 0:
ls := [0,0]:
ArgK := proc(f, t)
local e := 0.005, q := 0, y1, y2:
global l, ls:
y1 := evalf(arctan(f(t)[2], f(t)[1]),50);
y2 := evalf(arctan(f(t+e)[2], f(t+e)[1]),50);
if ls[1] = 0 then
if abs(y2 - y1) > 1.5 then l := l - sgn(y2 - y1)*2*Pi; ls := [1,t]: q := 1434: fi;

fi;
#arctan(f(t)[2], f(t)[1]) + l;
[l,q, IF(abs(y2 - y1) > 1.5)];
end proc:

l := 0:
ArgK(v,Pi/2);
ArgK(v,Pi);
([seq([2*Pi*k/10, ArgK(v,2*Pi*k/10)],k=0..10)]);
listplot([seq([2*Pi*k/1000, ArgK(v,2*Pi*k/1000)[1]],k=0..1000)]);

output:

[0, 0, 0]

[2 Pi, 1434, 1]

[                   [1                 ]  [2                 ]
[[0, [2 Pi, 0, 0]], [- Pi, [2 Pi, 0, 0]], [- Pi, [2 Pi, 0, 0]],
[                   [5                 ]  [5                 ]

[3                 ]  [4                 ]
[- Pi, [2 Pi, 0, 0]], [- Pi, [2 Pi, 0, 0]], [Pi, [2 Pi, 0, 1]],
[5                 ]  [5                 ]

[6                 ]  [7                 ]
[- Pi, [2 Pi, 0, 0]], [- Pi, [2 Pi, 0, 0]],
[5                 ]  [5                 ]

[8                 ]  [9                 ]
[- Pi, [2 Pi, 0, 0]], [- Pi, [2 Pi, 0, 0]], [2 Pi, [2 Pi, 0, 0]]
[5                 ]  [5                 ]

]
]
]

The nonsense output is not my fault, copying directly from maple. The main thing is thatat 2pi, the output should be 1434(see 2nd line) but there is no 1434. The output is completely ignored. It seems the correct jump is never calculated properly in the sequence although it works fine manually and has worked before when messing with the code.

e.g., these should be identical

[2 Pi, 1434, 1]

[Pi, [2 Pi, 0, 1]],

yet there is a 0 where there should be a 1434. (I was using q to figure out why the thing was not working)

I've been playign around with the code trying to get it to work but I've not been able to as maple is doing something very funky.  It should be a very simple problem of detecting a jump discontinuility then adding an appropriate amount(which must be tracked).

ls was used because I was getting wierd results around the discontinuity where the test would be called multiple times, I guess because something to do with the evaluation in plotting.

E.g., commenting out the ls if statement will get the step function one epects except it's not the right values.

The idea is simple though. For a continuous function theta(t) one should be able to provide a full and meaningful angle that takes in to account the correct branch when extracting this angle from a continuous function that is known to provide a continuous theta(t). i.e., Ang(f(t)) should be continuous. This is what I'm trying to achieve.

﻿