Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
лабы ИСНР-ф.doc
Скачиваний:
32
Добавлен:
11.09.2019
Размер:
1.62 Mб
Скачать

Комплексные числа

В MATLAB для обозначения мнимой единицы зарезервированы две переменные - i и j , предпочтение отдаётся i. Если эти же переменные использовались в циклах, то перед началом работы с комплексными числами следует выполнить команду

>> clear i,j

ans =

0 + 1.0000i

Основные приёмы работы с комплексными числами рассмотрим на примерах:

>> Z1=5+6i

Z1 =

5.0000 + 6.0000i

>> Z2=6-8i

Z2 =

6.0000 - 8.0000i

>> Z3=10+2i

Z3 =

10.0000 + 2.0000i

>> Z=Z1+Z2*Z3/(Z2+Z3)

Z =

10.5616 + 3.8356i

>> abs(Z)

ans =

11.2366

>> real(Z)

ans =

10.5616

>> imag(Z)

ans =

3.8356

Для вычисления комплексно-сопряжённого числа необходимо использовать оператор

>> conj(Z)

ans =

10.5616 - 3.8356i

или апостроф

>> Z'

ans =

10.5616 - 3.8356i

>> sin(Z)

ans =

-21.0242 - 9.7333i

>> Z^2

ans =

96.8364 +81.0208i

>> sqrt(Z)

ans =

3.3014 + 0.5809i

Если коэффициентом при мнимой единице является переменная, то при вводе такого числа необходимо использовать знак умножения * . Строку можно заканчивать символом точки с запятой, что позволяет избежать вывода на экран результатов вычисления промежуточных выражений:

> a=-4.3;b=-6.7;z=a+b*i

z =

-4.3000 - 6.7000i

Вычисление аргумента комплексного числа с помощью оператора

>> angle(z)

даёт результат в радианах в диапазоне от + π до -π .

ans =

-2.1414

Для перевода результата в градусы необходимо выполнить операцию

>> fi=180*ans/pi

fi =

-122.6920

Элементарные функции

Для вычислений с числами предусмотрены все элементарные функции:

логарифмические, тригонометрические, гиперболические. Аргументы задаются в круглых скобках через запятую. Аргументы и результат тригонометрических функций в радианах. Рассмотрим вычисление элементарных функций на примерах:

>> sin(3.14)

ans =

0.0016

>> cos(2.5)

ans =

-0.8011

>> tan(pi/6)

ans =

0.5774

>> cot(1-pi)

ans =

0.6421

>> log10(100)

ans =

2

>> log(10)

ans =

2.3026

В MATLAB 7 аргументы тригонометрических функций можно задавать в градусах, результат также получается в градусах.

Краткое описание элементарных функций вызывается с помощью команды

>> help elfun

Elementary math functions.

Trigonometric.

sin - Sine.

sinh - Hyperbolic sine.

asin - Inverse sine.

asinh - Inverse hyperbolic sine.

cos - Cosine.

cosh - Hyperbolic cosine.

acos - Inverse cosine.

acosh - Inverse hyperbolic cosine.

tan - Tangent.

tanh - Hyperbolic tangent.

atan - Inverse tangent.

atan2 - Four quadrant inverse tangent.

atanh - Inverse hyperbolic tangent.

sec - Secant.

sech - Hyperbolic secant.

asec - Inverse secant.

asech - Inverse hyperbolic secant.

csc - Cosecant.

csch - Hyperbolic cosecant.

acsc - Inverse cosecant.

acsch - Inverse hyperbolic cosecant.

cot - Cotangent.

coth - Hyperbolic cotangent.

acot - Inverse cotangent.

acoth - Inverse hyperbolic cotangent.

Exponential.

exp - Exponential.

log - Natural logarithm.

log10 - Common (base 10) logarithm.

log2 - Base 2 logarithm and dissect floating point number.

pow2 - Base 2 power and scale floating point number.

realpow - Power that will error out on complex result.

reallog - Natural logarithm of real number.

realsqrt - Square root of number greater than or equal to zero.

sqrt - Square root.

nextpow2 - Next higher power of 2.

Complex.

abs - Absolute value.

angle - Phase angle.

complex - Construct complex data from real and imaginary parts.

conj - Complex conjugate.

imag - Complex imaginary part.

real - Complex real part.

unwrap - Unwrap phase angle.

isreal - True for real array.

cplxpair - Sort numbers into complex conjugate pairs.

Rounding and remainder.

fix - Round towards zero.

floor - Round towards minus infinity.

ceil - Round towards plus infinity.

round - Round towards nearest integer.

mod - Modulus (signed remainder after division).

rem - Remainder after division.

sign - Signum.

В MATLAB предусмотрены и специальные функции (бета- и гамма-функции, и др.), список которых можно вывести с помощью оператора

>> help specfun

Specialized math functions.

Specialized math functions.

airy - Airy functions.

besselj - Bessel function of the first kind.

bessely - Bessel function of the second kind.

besselh - Bessel functions of the third kind (Hankel function).

besseli - Modified Bessel function of the first kind.

besselk - Modified Bessel function of the second kind.

beta - Beta function.

betainc - Incomplete beta function.

betaln - Logarithm of beta function.

ellipj - Jacobi elliptic functions.

ellipke - Complete elliptic integral.

erf - Error function.

erfc - Complementary error function.

erfcx - Scaled complementary error function.

erfinv - Inverse error function.

expint - Exponential integral function.

gamma - Gamma function.

gammainc - Incomplete gamma function.

gammaln - Logarithm of gamma function.

psi - Psi (polygamma) function.

legendre - Associated Legendre function.

cross - Vector cross product.

dot - Vector dot product.

Number theoretic functions.

factor - Prime factors.

isprime - True for prime numbers.

primes - Generate list of prime numbers.

gcd - Greatest common divisor.

lcm - Least common multiple.

rat - Rational approximation.

rats - Rational output.

perms - All possible permutations.

nchoosek - All combinations of N elements taken K at a time.

factorial - Factorial function.

Coordinate transforms.

cart2sph - Transform Cartesian to spherical coordinates.

cart2pol - Transform Cartesian to polar coordinates.

pol2cart - Transform polar to Cartesian coordinates.

sph2cart - Transform spherical to Cartesian coordinates.

hsv2rgb - Convert hue-saturation-value colors to red-green-blue.

rgb2hsv - Convert red-green-blue colors to hue-saturation-value.