Contents

help
help elfun
help abs
HELP topics:

Documents\MATLAB               - (No table of contents file)
matlab\testframework           - (No table of contents file)
matlab\demos                   - Examples.
matlab\graph2d                 - Two dimensional graphs.
matlab\graph3d                 - Three dimensional graphs.
matlab\graphics                - Handle Graphics.
matlab\plottools               - Graphical plot editing tools 
matlab\scribe                  - Annotation and Plot Editing.
matlab\specgraph               - Specialized graphs.
matlab\uitools                 - Graphical user interface components and tools
hardware\stubs                 - (No table of contents file)
matlab\images                  - (No table of contents file)
toolbox\local                  - General preferences and configuration information.
matlab\optimfun                - Optimization and root finding.
matlab\codetools               - Commands for creating and debugging code
matlab\datafun                 - Data analysis and Fourier transforms.
matlab\datamanager             - (No table of contents file)
matlab\datastoreio             - (No table of contents file)
matlab\datatypes               - Data types and structures.
matlab\elfun                   - Elementary math functions.
matlab\elmat                   - Elementary matrices and matrix manipulation.
matlab\funfun                  - Function functions and ODE solvers.
matlab\general                 - General purpose commands.
matlab\guide                   - Graphical user interface design environment
matlab\helptools               - Help commands.
matlab\iofun                   - File input and output.
matlab\lang                    - Programming language constructs.
matlab\mapreduceio             - (No table of contents file)
matlab\matfun                  - Matrix functions - numerical linear algebra.
matlab\ops                     - Operators and special characters.
matlab\polyfun                 - Interpolation and polynomials.
matlab\randfun                 - Random matrices and random streams.
matlab\sparfun                 - Sparse matrices.
matlab\specfun                 - Specialized math functions.
matlab\strfun                  - Character strings.
matlab\timefun                 - Time and dates.
matlab\verctrl                 - Version control.
matlab\winfun                  - Windows Operating System Interface Files (COM/DDE)
winfun\NET                     - Using .NET from within MATLAB
matlab\apps                    - (No table of contents file)
matlab\audiovideo              - Audio and Video support.
coder\connectivity             - (No table of contents file)
rtw\rtw                        - (No table of contents file)
tools\registry                 - (No table of contents file)
foundation\tfl                 - (No table of contents file)
AUTOSAR4p0\IFX                 - (No table of contents file)
AUTOSAR4p0\IFL                 - (No table of contents file)
tfl\gui                        - (No table of contents file)
shared\comparisons             - (No table of contents file)
connector\connector            - (No table of contents file)
curvefit\curvefit              - Curve Fitting Toolbox
curvefit\splines               - Curve Fitting Toolbox -- Spline Functions
curvefit\cftoolgui             - Curve Fitting Toolbox -- Curve Fitting Tool
curvefit\curvefitdemos         - Curve Fitting Toolbox -- Examples
daq\daq                        - Data Acquisition Toolbox
daq\daqguis                    - Data Acquisition Toolbox - Data Acquisition Soft Instruments.
daq\daqdemos                   - Data Acquisition Toolbox - Data Acquisition Demos.
toolbox\distcomp               - Parallel Computing Toolbox
distcomp\distcomp              - (No table of contents file)
distcomp\user                  - (No table of contents file)
distcomp\mpi                   - Parallel Computing Functions for Message Passing
distcomp\parallel              - Parallel Algorithms
parallel\util                  - (No table of contents file)
distcomp\lang                  - Parallel computing programming language constructs.
distcomp\cluster               - Functions and Classes for Parallel Computing with Clusters
distcomp\gpu                   - There are several options available for using your computer's graphics 
distcomp\pctdemos              - (No table of contents file)
eml\eml                        - (No table of contents file)
fixedpoint\fixedpoint          - (No table of contents file)
hdllib\ml_lib                  - (No table of contents file)
images\colorspaces             - Image Processing Toolbox --- colorspaces
images\images                  - Image Processing Toolbox
images\imdata                  - Image Processing Toolbox --- sample images
images\imuitools               - Image Processing Toolbox --- imuitools
images\iptformats              - Image Processing Toolbox --- File Formats
images\iptutils                - Image Processing Toolbox --- utilities
matlab\imagesci                - (No table of contents file)
images\imdemos                 - Image Processing Toolbox --- demos
imaq\imaq                      - Image Acquisition Toolbox
imaq\imaqdemos                 - Image Acquisition Toolbox.
imaqblks\imaqblks              - (No table of contents file)
imaqblks\imaqmex               - (No table of contents file)
imaqblks\imaqmasks             - (No table of contents file)
shared\instrument              - (No table of contents file)
shared\m3i                     - (No table of contents file)
matlab\networklib              - Network support.
optim\optim                    - Optimization Toolbox
optim\optimdemos               - Demonstrations.
toolbox\pde                    - Partial Differential Equation Toolbox
pde\pdedemos                   - Partial Differential Equation Toolbox Examples
interfaces\python              - (No table of contents file)
shared\configset               - (No table of contents file)
controllib\general             - Control System Toolbox -- General Utilities.
controllib\graphics            - Control Library - Graphics.
graphics\utils                 - (No table of contents file)
graphics\plotoptions           - (No table of contents file)
shared\dastudio                - (No table of contents file)
dspblks\dspblks                - (No table of contents file)
shared\filterdesignlib         - (No table of contents file)
shared\imageslib               - Image Processing Toolbox Library
shared\imaqlib                 - Image Acquisition Toolbox Library
shared\measure                 - (No table of contents file)
shared\optimlib                - Optimization Toolbox Library
shared\pdelib                  - PDE Toolbox Library
shared\rptgen                  - (No table of contents file)
shared\siglib                  - (No table of contents file)
shared\spcuilib                - (No table of contents file)
shared\statslib                - Statistics Toolbox Library
testmeaslib\simulink           - (No table of contents file)
signal\signal                  - Signal Processing Toolbox 
signal\sigtools                - (No table of contents file)
signal\sptoolgui               - (No table of contents file)
signal\sigdemos                - (No table of contents file)
stats\stats                    - Statistics Toolbox
stats\classreg                 - (No table of contents file)
stats\clustering               - (No table of contents file)
stats\statsdemos               - Statistics Toolbox --- Demos
matlab\timeseries              - Time series data visualization and exploration.
matlab\hds                     - (No table of contents file)
matlab\toolbox_packaging       - (No table of contents file)
wavelet\wavelet                - Wavelet Toolbox
wavelet\wmultisig1d            - (No table of contents file)
wavelet\compression            - (No table of contents file)
wavelet\wavedemo               - (No table of contents file)
matlab\webcam                  - Webcam support.
webservices\restful            - (No table of contents file)
interfaces\webservices         - Web services interface.

  Elementary math functions.
 
  Trigonometric.
    sin         - Sine.
    sind        - Sine of argument in degrees.
    sinh        - Hyperbolic sine.
    asin        - Inverse sine.
    asind       - Inverse sine, result in degrees.
    asinh       - Inverse hyperbolic sine.
    cos         - Cosine.
    cosd        - Cosine of argument in degrees.
    cosh        - Hyperbolic cosine.
    acos        - Inverse cosine.
    acosd       - Inverse cosine, result in degrees.
    acosh       - Inverse hyperbolic cosine.
    tan         - Tangent.
    tand        - Tangent of argument in degrees.
    tanh        - Hyperbolic tangent.
    atan        - Inverse tangent.
    atand       - Inverse tangent, result in degrees.
    atan2       - Four quadrant inverse tangent.
    atan2d      - Four quadrant inverse tangent, result in degrees.
    atanh       - Inverse hyperbolic tangent.
    sec         - Secant.
    secd        - Secant of argument in degrees.
    sech        - Hyperbolic secant.
    asec        - Inverse secant.
    asecd       - Inverse secant, result in degrees.
    asech       - Inverse hyperbolic secant.
    csc         - Cosecant.
    cscd        - Cosecant of argument in degrees.
    csch        - Hyperbolic cosecant.
    acsc        - Inverse cosecant.
    acscd       - Inverse cosecant, result in degrees.
    acsch       - Inverse hyperbolic cosecant.
    cot         - Cotangent.
    cotd        - Cotangent of argument in degrees.
    coth        - Hyperbolic cotangent.
    acot        - Inverse cotangent.
    acotd       - Inverse cotangent, result in degrees.
    acoth       - Inverse hyperbolic cotangent.
    hypot       - Square root of sum of squares.
 
  Exponential.
    exp         - Exponential.
    expm1       - Compute exp(x)-1 accurately.
    log         - Natural logarithm.
    log1p       - Compute log(1+x) accurately.
    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.
    nthroot     - Real n-th root of real numbers.
    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.

abs - Absolute value and complex magnitude

    This MATLAB function returns the absolute value of each element in array X.

    Y = abs(X)

    See also angle, hypot, sign, unwrap

    Other functions named abs
        signal/abs

Operatory arytmetyczne

doc arithmetic operators
2+3
5-3
3*4
2/4
3^2
ans =
     5
ans =
     2
ans =
    12
ans =
    0.5000
ans =
     9

Co oznacza symbol ^ ?

3\9
ans =
     3

Co oznacza symbol \ ?

Znaczenie kropki

3.*4
2./4
3.^2
ans =
    12
ans =
    0.5000
ans =
     9

Nieskończoność i nieoznaczoność

0/1
1/0
51+inf
17/inf
0/0
ans =
     0
ans =
   Inf
ans =
   Inf
ans =
     0
ans =
   NaN

Zmienne

a = 2
a = a + 7
a = a*10
a =
     2
a =
     9
a =
    90

Znaczenie znaku ; na końcu linii

b = 3;
b
b =
     3

Utworzenie nowej zmiennej ze zmiennych już istniejących

a_plu_b = a + b
a_plu_b =
    93

Funkcje matematyczne

clc
help elfun
sqrt(pi)
sin(90*pi/180)
  Elementary math functions.
 
  Trigonometric.
    sin         - Sine.
    sind        - Sine of argument in degrees.
    sinh        - Hyperbolic sine.
    asin        - Inverse sine.
    asind       - Inverse sine, result in degrees.
    asinh       - Inverse hyperbolic sine.
    cos         - Cosine.
    cosd        - Cosine of argument in degrees.
    cosh        - Hyperbolic cosine.
    acos        - Inverse cosine.
    acosd       - Inverse cosine, result in degrees.
    acosh       - Inverse hyperbolic cosine.
    tan         - Tangent.
    tand        - Tangent of argument in degrees.
    tanh        - Hyperbolic tangent.
    atan        - Inverse tangent.
    atand       - Inverse tangent, result in degrees.
    atan2       - Four quadrant inverse tangent.
    atan2d      - Four quadrant inverse tangent, result in degrees.
    atanh       - Inverse hyperbolic tangent.
    sec         - Secant.
    secd        - Secant of argument in degrees.
    sech        - Hyperbolic secant.
    asec        - Inverse secant.
    asecd       - Inverse secant, result in degrees.
    asech       - Inverse hyperbolic secant.
    csc         - Cosecant.
    cscd        - Cosecant of argument in degrees.
    csch        - Hyperbolic cosecant.
    acsc        - Inverse cosecant.
    acscd       - Inverse cosecant, result in degrees.
    acsch       - Inverse hyperbolic cosecant.
    cot         - Cotangent.
    cotd        - Cotangent of argument in degrees.
    coth        - Hyperbolic cotangent.
    acot        - Inverse cotangent.
    acotd       - Inverse cotangent, result in degrees.
    acoth       - Inverse hyperbolic cotangent.
    hypot       - Square root of sum of squares.
 
  Exponential.
    exp         - Exponential.
    expm1       - Compute exp(x)-1 accurately.
    log         - Natural logarithm.
    log1p       - Compute log(1+x) accurately.
    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.
    nthroot     - Real n-th root of real numbers.
    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.

ans =
    1.7725
ans =
     1

Przysłanianie nazw

clc
pi = 4
sqrt(pi)
pi =
     4
ans =
     2

Zarządzanie przestrzenią roboczą

whos
clear pi
whos
sqrt(pi)
clear
whos
  Name             Size              Bytes  Class     Attributes

  A                2x2                  32  double              
  B                2x1                  16  double              
  Fs               1x1                   8  double              
  X              257x250            514000  double              
  a                1x1                   8  double              
  a_plu_b          1x1                   8  double              
  ans              1x1                   8  double              
  b                1x1                   8  double              
  g                1x1                   8  double              
  h                1x126              1008  double              
  map             64x3                1536  double              
  n                1x1                   8  double              
  pi               1x1                   8  double              
  r               33x33               8712  double              
  t                1x126              1008  double              
  u                1x1                   8  double              
  w                1x11                 88  double              
  x               33x33               8712  double              
  y            52634x1              421072  double              
  z               33x33               8712  double              

  Name             Size              Bytes  Class     Attributes

  A                2x2                  32  double              
  B                2x1                  16  double              
  Fs               1x1                   8  double              
  X              257x250            514000  double              
  a                1x1                   8  double              
  a_plu_b          1x1                   8  double              
  ans              1x1                   8  double              
  b                1x1                   8  double              
  g                1x1                   8  double              
  h                1x126              1008  double              
  map             64x3                1536  double              
  n                1x1                   8  double              
  r               33x33               8712  double              
  t                1x126              1008  double              
  u                1x1                   8  double              
  w                1x11                 88  double              
  x               33x33               8712  double              
  y            52634x1              421072  double              
  z               33x33               8712  double              

ans =
    1.7725

Wektory

x = 0 : 10
size(x)
x =
     0     1     2     3     4     5     6     7     8     9    10
ans =
     1    11

Tworzenie wektora na podstawie istniejącego wektora

y = 3*x
w = y./x
z = sin(x)
y =
     0     3     6     9    12    15    18    21    24    27    30
w =
   NaN     3     3     3     3     3     3     3     3     3     3
z =
  Columns 1 through 7
         0    0.8415    0.9093    0.1411   -0.7568   -0.9589   -0.2794
  Columns 8 through 11
    0.6570    0.9894    0.4121   -0.5440

Wykresy funkcji

x = 0 : 0.1 : 4*pi;
z = sin(x);
plot(x,z)
grid on
axis tight
z = tan(x);
plot(x,z)
grid on
axis tight

ezplot('tan(fi)')

Rozwiązywanie układów równań liniowych

$$x + 2y = 4$$

$$2x - y = 3$$

Metoda macierzowa

$$A * X = B; |A| <> 0$$

gdzie: X - macierz niewiadomych (rozwiązań), A - macierz współczynników, B - macierz wyrazów wolnych

$$X = A^{-1} * B$$

A = [1 2; 2 -1]
B = [4; 3]
X = A\B
A =
     1     2
     2    -1
B =
     4
     3
X =
     2
     1

Funkcja linsolve

X = linsolve(A,B)
X =
     2
     1

Sprawdzenie wyników

2 + 2*1 % x + 2*y = 4
2*2 - 1 % 2*x -y =3
ans =
     4
ans =
     3

Wykres konturowy funkcji 2D (macierzy danych)

contour(magic(22))

Wykres siatkowy funkcji dwóch zmiennych (meksykański kapelusz)

[x,y] = meshgrid(-8 : 0.5 : 8);
r = sqrt(x.^2 + y.^2) + eps;
z = sin(r)./r;
mesh(z)

Wykres powierzchni dla funkcji dwóch zmiennych

figure; surf(z)
figure; surf(z)
shading flat

Warianty funkcji: mesh i surf

figure; meshc(z)
figure; surfc(z)
figure; surfc(z), shading flat

Powtórzenia (petla for)

Animacja funkcji meksykański kapelusz dla n=-3:0.5:3

close all
for n=-3:0.05:3
z = sin(r.*n)./r;
surf(z), view(-37,38), axis([0, 40, 0, 40, -4, 4])
pause(0.1)
end

Wykorzystanie danych - dzwięki

load handel
sound(y,Fs)
load train
sound(y,Fs)
load chirp
sound(y,Fs)
load gong
sound(y,Fs)
load splat
sound(y,Fs)
load laughter
sound(y,Fs)

Wykorzystanie danych - obrazy

load earth
image(X)
colormap(map)
axis image

Why

why
why(2)
type why
edit why
He suggested it.
You insisted on it.

function why(n)
%WHY    Provides succinct answers to almost any question.
%   WHY, by itself, provides a random answer.
%   WHY(N) provides the N-th answer.
%   Please embellish or modify this function to suit your own tastes.

%   Copyright 1984-2014 The MathWorks, Inc.

if nargin > 0
   dflt = rng(n,'v5uniform');
end
switch randi(10)
   case 1
      a = special_case;
   case {2, 3, 4}
      a = phrase;
   otherwise
      a = sentence;
end
a(1) = upper(a(1));
disp(a);
if nargin > 0
   rng(dflt);
end


% ------------------

function a = special_case
switch randi(12)
   case 1
      a = 'why not?';
   case 2
      a = 'don''t ask!';
   case 3
      a = 'it''s your karma.';
   case 4
      a = 'stupid question!';
   case 5
      a = 'how should I know?';
   case 6
      a = 'can you rephrase that?';
   case 7
      a = 'it should be obvious.';
   case 8
      a = 'the devil made me do it.';
   case 9
      a = 'the computer did it.';
   case 10
      a = 'the customer is always right.';
   case 11
      a = 'in the beginning, God created the heavens and the earth...';
   case 12
      a = 'don''t you have something better to do?';
end

function a = phrase
switch randi(3)
   case 1
      a = ['for the ' nouned_verb ' ' prepositional_phrase '.'];
   case 2
      a = ['to ' present_verb ' ' object '.'];
   case 3
      a = ['because ' sentence];
end

function a = preposition
switch randi(2)
   case 1
      a = 'of';
   case 2
      a = 'from';
end

function a = prepositional_phrase
switch randi(3)
   case 1
      a = [preposition ' ' article ' ' noun_phrase];
   case 2
      a = [preposition ' ' proper_noun];
   case 3
      a = [preposition ' ' accusative_pronoun];
end

function a = sentence
a = [subject ' ' predicate '.'];

function a = subject
switch randi(4)
   case 1
      a = proper_noun;
   case 2
      a = nominative_pronoun;
   otherwise
      a = [article ' ' noun_phrase];
end

function a = proper_noun
switch randi(12)
   case 1
      a = 'Cleve';
   case 2
      a = 'Jack';
   case 3
      a = 'Bill';
   case 4
      a = 'Joe';
   case 5
      a = 'Pete';
   case 6
      a = 'Loren';
   case 7
      a = 'Damian';
   case 8
      a = 'Barney';
   case 9
      a = 'Nausheen';
   case 10
      a = 'Mary Ann';
   case 11
      a = 'Penny';
   case 12
      a = 'Mara';
end

function a = noun_phrase
switch randi(4)
   case 1
      a = noun;
   case 2
      a = [adjective_phrase ' ' noun_phrase];
   otherwise
      a = [adjective_phrase ' ' noun];
end

function a = noun
switch randi(6)
   case 1
      a = 'mathematician';
   case 2
      a = 'programmer';
   case 3
      a = 'system manager';
   case 4
      a = 'engineer';
   case 5
      a = 'hamster';
   case 6
      a = 'kid';
end

function a = nominative_pronoun
switch randi(5)
   case 1
      a = 'I';
   case 2
      a = 'you';
   case 3
      a = 'he';
   case 4
      a = 'she';
   case 5
      a = 'they';
end

function a = accusative_pronoun
switch randi(4)
   case 1
      a = 'me';
   case 2
      a = 'all';
   case 3
      a = 'her';
   case 4
      a = 'him';
end

function a = nouned_verb
switch randi(2)
   case 1
      a = 'love';
   case 2
      a = 'approval';
end

function a = adjective_phrase
switch randi(6)
   case {1 2 3}
      a = adjective;
   case {4 5}
      a = [adjective_phrase ' and ' adjective_phrase];
   case 6
      a = [adverb ' ' adjective];
end

function a = adverb
switch randi(3)
   case 1
      a = 'very';
   case 2
      a = 'not very';
   case 3
      a = 'not excessively';
end

function a = adjective
switch randi(7)
   case 1
      a = 'tall';
   case 2
      a = 'bald';
   case 3
      a = 'young';
   case 4
      a = 'smart';
   case 5
      a = 'rich';
   case 6
      a = 'terrified';
   case 7
      a = 'good';
end

function a = article
switch randi(3)
   case 1
      a = 'the';
   case 2
      a = 'some';
   case 3
      a = 'a';
end

function a = predicate
switch randi(3)
   case 1
      a = [transitive_verb ' ' object];
   otherwise,
      a = intransitive_verb;
end

function a = present_verb
switch randi(3)
   case 1
      a = 'fool';
   case 2
      a = 'please';
   case 3
      a = 'satisfy';
end

function a = transitive_verb
switch randi(10)
   case 1
      a = 'threatened';
   case 2
      a = 'told';
   case 3
      a = 'asked';
   case 4
      a = 'helped';
   otherwise
      a = 'obeyed';
end

function a = intransitive_verb
switch randi(6)
   case 1
      a = 'insisted on it';
   case 2
      a = 'suggested it';
   case 3
      a = 'told me to';
   case 4
      a = 'wanted it';
   case 5
      a = 'knew it was a good idea';
   case 6
      a = 'wanted it that way';
end

function a = object
switch randi(10)
   case 1
      a = accusative_pronoun;
   otherwise
      a = [article ' ' noun_phrase];
end

Prosty program - Rzut pionowy

Tor lotu ciała wyrzuconego pionowo do góry z prędkościa początjkową u opisany jest wzorem:

$$h = u*t-(g*t^2)/2$$

Naspisz skrypt, który będzie wyznaczał wektor wysokości ciała w rzucie pionowym w kolejnych chwilach czasowych od o do 12.5 [s] oraz tworzył wykres przebiegu wysokości na jakiej znajduje się ciało w czasie.

Algorytm - szkielet skryptu

  1. Wprowadzenie danych
  2. Wyznaczenie wartości wysokości h zgodnie z powyzszym wzorem
  3. Utworzenie wykresu zależnosci h od t
  4. Koniec

Wypelnienie szkieletu

% 1. Wprowadzenie danych (inicjalizacja zmiennych g, u i t odpowiednimi
% wartościami)
g = 9.81;               % przyspieszenie ziemskie [m/s^2]
u = 60;                 % prędkość początkowa [m/s]
t = 0 : 0.1 : 12.5;     % wektor czasu [s]

% 2.Wyznaczenie wartości wysokości h zgodnie z wzorem
% h = u*t-(g*t^2)/2

h = u*t - g*t.^2/2;

% 3.Utworzenie wykresu zależności h od t

plot(t,h);
title ('Rzut pionowy');
xlabel('czas [s]');
ylabel('wysokość [m]')
grid on

% 4.Koniec