I am trying to write a function which takes the value x and y in cartesian coordinates as the input and outputs the polar and trigonometric forms. I would like the output to contain the exponential and sin/cos rather than the actual value. For example, if the cartesian is z=1i, I would like the function to output z=sqrt(2)e^(ipi/4) and z=sqrt(2)(cos(pi/4)+Isin(pi/4). How can I do this?
function coordinates(x,y)
r=sqrt(x.^2+y.^2);
theta=atan(y./x);
polarcoord=rexp(itheta)
trigcoord=r*(cos(theta)+i*sin(theta))
end
This gives me the following output :
polarcoord =
1.0000 + 1.0000i
trigcoord =
1.0000 + 1.0000i
thanks