# Convert formula into coding form

1 view (last 30 days)
Syakira Akmal on 1 Apr 2017
Answered: Image Analyst on 1 Apr 2017
Hi, i don't know how to convert formula into coding form. Example of formula
theta(kx, ky) = arctan(dy/dx)

Star Strider on 1 Apr 2017
The arguments to the function do not match the arguments to the arctangent function. Are ‘kx’ and ‘ky’ the same as ‘dx’ and ‘dy’ or different?
One of these should do what you want:
theta = @(kx, ky) atan2(ky,kx); % The Values (Or Vectors) Themselves
The atan2 function puts the returned angles in the correct quadrants. The atan function does not.

Syakira Akmal on 1 Apr 2017
(kx, ky) is a point. dy = In(kx,ky+1) - In(kx,ky-1) dx = In(kx+1,ky) - In(kx-1,ky)
Star Strider on 1 Apr 2017
My function then changes to:
theta = @(kx, ky) atan2(In(kx,ky+1) - In(kx,ky-1), In(kx+1,ky) - In(kx-1,ky)); % Directly Using ‘In’
That should work.

John D'Errico on 1 Apr 2017
Edited: John D'Errico on 1 Apr 2017
I'd strongly suggest that you start reading the getting started tutorials. This is a very basic question, although I honestly have no idea what it is that you really want to do here. If I had to guess, you need to learn how to write a function.
Using a four quadrant atan, this would do what you want.
theta = @(kx,ky) = atan2(ky,kx);
Or do this:
theta = @(kx,ky) = atan(ky/kx);

Image Analyst on 1 Apr 2017