leftimage for poohprod.ru

Coordinate conversion: polar-to- cartesian and cartesian-to-polar

This couple of Matlab functions perform a coordinate conversion of a point given in Cartesian coordinates to polar coordinates, and vice versa.

When we use this polar-to-cartesian function, we enter a magnitude and an angle in degrees as parameters. The function returns a real number (x) and a complex number (y value).

When we use the cartesian-to-polar function, we enter a complex value as parameter. The function returns a magnitude, an angle in radians and an equivalent angle in degrees.

The formulas for the conversions are:

coordinate conversion: polar to cart. and vice versa
coordinate conversion formulas


x = abscissa
y = ordinate
r = magnitude
a = angle

These are the functions:

function [x,y]= polar2cart (mag, ang_in_deg)
x = mag * cos(ang_in_deg*pi/180);
y = j * mag * sin(ang_in_deg*pi/180);

function [r, ar, ad] = cart2polar(x)
r = abs(x);
ar = angle(x);
ad = ar*180/pi;

And now we test them:

% Clear memory and screen. Avoid double-blank lines
clear; clc; format compact

[x, y] = polar2cart(2, 30.5)
[r, ar, ad] = cart2polar(7 + 18i)
[r, ar, ad] = cart2polar(0 - 46.8i)

The results are:

x = 1.7233
y = 0 + 1.0151i
r = 19.3132
ar = 1.1999
ad = 68.7495
r = 46.8000
ar = -1.5708
ad = -90

From 'Coordinate Conversion' to home

From 'Coordinate Conversion' to 'Matlab Cookbook I'

Table of Contents


Complex Numbers

footer for coordinate conversion page

Related pages

how to convert cartesian to polargui tutorial matlabohm's law pie chartcalculate fibonacci numberfor loop matrix matlabcircle matlabsmith chart tutorial pdfdefining functions in matlabmaclaurin series examplestaylor series for cosinenonlinear fit matlabmatlab solve system of equationscircuitbuilding do it yourself for dummieshow to solve simultaneous equations in matlabplotting a function in matlabprogram fibonacci seriestaylor series of cos xpythagorean calculatorstring matlabsimple matlab program exampleconstruction of pascal trianglexls write matlabtrigonometric functions matlabmatlab 3d matrixbinomial probability distribution calculatorpolynomial root findersample matlab programlinspace matlab exampleinterpolation in matlabhelpdesk jokessemilogyrandn function in matlabmatlab plot for loophexadecimal exampleprogram to convert decimal to octalboolean logic xorfunction solver matlabplot 3d surface matlabbinary to decimal conversion programpiecewise functions helptau capacitormatlab for loop syntaxharmonic seriesprobability normal distribution calculatorc code for pascal trianglematlab magic squaretower of hanoi algorithmdisplay function in matlabascii value of alphabetsnum2string matlabtaylor expansion of cosxcramersrulehow to convert to binary from decimaldelta diracaoctal baseroot finding bisection methodplot step function matlabcalling function in matlabquadratic solver calculatormatlab zerosconvert octal2d interpolation matlabkcl equationssmith chart problemsfibonacci sequence examplesexample of fibonacci sequencelog function matlabmatlab scilabhow to create histogram in matlabwriting a piecewise function