Operacje arytmetyczne + dodawnie, - odejmowanie, * mnożenie, / dzielenie, ^ potęgowanie
5 + 5
ans = 10
-2 * 4.3
ans = -8.6000
2 ^ 10
ans = 1024
3 / 5
ans = 0.60000
3 / 0
warning: division by zero ans = Inf
Ćwiczenie: oblicz ile wynoisi $\frac{1.3^{2.2}}{5.3 - 3/13}$
Stałe: pi $\pi$, inf $\infty$, NaN not a number, realmax największa liczba, rzeczywista, eps dokładność maszynowa
Funkcje: sin(), cos(), tan, cot, sinh, asin, sqrt() $\sqrt{x}$, exp() $e^x$, abs $|x|$, log, log2, log10, sign znak, mod reszta z dzielenia
sin( pi / 4 )
ans = 0.70711
realmax eps
ans = 1.7977e+308 ans = 2.2204e-16
sqrt(16)
ans = 4
sqrt(-1)
ans = 0 + 1i
Ćwiczenie: oblicz ile wynosi $\sqrt{\sin(0.3\pi) \cdot e^{-0.1}} $
disp() wypisywanie zmiennychfprintf() wypisywanie formatowanych komunikatów zgodnie z funkcją printf z Csin(5) + 3;
disp(sin(5) + 3);
disp('Witaj świecie')
2.0411 Witaj świecie
fprintf('Witaj ściecie!\n')
fprintf('sin(%d) = %f\n', 2, sin(2))
Witaj ściecie! sin(2) = 0.909297
Formatowanie printf:
%f, %e notacja naukowa, %g krótka format %.3f precyzja %10f szerokośc okna %-10f wyrówanie do lewej %d liczby całkowite %x liczby całkowite (szesnastkowo) %s napis (ciąg znaków) %c znakfprintf('%f\n', pi)
fprintf('%e\n', pi)
fprintf('%g\n', pi)
fprintf('%.10f\n', pi)
fprintf('%10f\n', pi)
fprintf('%10.2f\n', pi)
fprintf('%-10.2f\n', pi)
fprintf('%d %x %c\n', 42, 42, 42)
fprintf('Liczba %s wynosi %f', 'pi', pi)
3.141593
3.141593e+00
3.14159
3.1415926536
3.141593
3.14
3.14
42 2a *
Liczba pi wynosi 3.141593
= przypisania wartości <html><br></html> zmienna = wyrażenieA-Za-z0-9_, małe/wielkie litery rozróżnianex = 16 y = sqrt(x) z = x + y + sin(x) napis = 'Witaj Świecie'
x = 16 y = 4 z = 19.712 napis = Witaj Świecie
x = x + 1
x = 17
błędne przypisanie
1 = x
parse error:
invalid constant left hand side of assignment
>>> 1 = x
^
who - lista zmiennychwhos - lista zmiennych wraz informacją o typieclear - usuwanie zmiennychwho
Variables in the current scope: ans napis x y z
whos
Variables in the current scope:
Attr Name Size Bytes Class
==== ==== ==== ===== =====
ans 1x1 8 double
napis 1x14 14 char
x 1x1 8 double
y 1x1 8 double
z 1x1 8 double
Total is 18 elements using 46 bytes
char) 1xNans przechowuje ostatni wynik (answer)sqrt(2)
ans = 1.4142
x = ans + 5
x = 6.4142
double domyślny dla warlości liczbowychlogical, wartości: true, falsechar, napis to macierz (wektor) znakówint32 po rzutowaniu int32()x = 1; y = true; z = int32(x); d = 'abc'; whos
Variables in the current scope:
Attr Name Size Bytes Class
==== ==== ==== ===== =====
ans 1x1 8 double
d 1x3 3 char
napis 1x14 14 char
x 1x1 8 double
y 1x1 1 logical
z 1x1 4 int32
Total is 21 elements using 38 bytes
x = [ 1 2 3]
x = 1 2 3
x = [ 1, 2, 3]
x = 1 2 3
x = 1:10
x =
1 2 3 4 5 6 7 8 9 10
y = [ 1 ; 2 ; 3 ; 4]
y = 1 2 3 4
x = [1 2 3 4 5] x + 2
x = 1 2 3 4 5 ans = 3 4 5 6 7
sqrt(x)
ans = 1.0000 1.4142 1.7321 2.0000 2.2361
y = [6 7 8 9 10] z = x + y sqrt(x)
y =
6 7 8 9 10
z =
7 9 11 13 15
ans =
1.0000 1.4142 1.7321 2.0000 2.2361
Ćwiczenie: oblicz wartość wyrażenia $\begin{bmatrix} 1 & 2 & 3
\end{bmatrix} \cdot \begin{bmatrix} 1
2
3
\end{bmatrix}$
clc czyszczenie wiersza poleceńwho whos lista zmiennychclear usuwa wszystkie zmienneclear x usuwa zmienną xhelp polecenie pomocquit wyjście z Matlabhelp sin
'sin' is a built-in function from the file libinterp/corefcn/mappers.cc
-- sin (X)
Compute the sine for each element of X in radians.
See also: asin, sind, sinh.
Additional help for built-in functions and operators is
available in the online version of the manual. Use the command
'doc <topic>' to search the manual index.
Help and information about Octave is also available on the WWW
at https://www.octave.org and via the help@octave.org
mailing list.
help polecenie pomoc dotycząca poleceniahelp elfun elementarne funkcje matematycznehelp elmat elementarne funkcje macierzowedoc polecenie strona dokumentacji dotycząca polecenialookfor wyrażenie lista poleceń dotyczacych wyrażeniaF1pomoc dotycząca zaznacznej funkcjilookfor cosine
acos Compute the inverse cosine in radians for each element of X
.
acosh Compute the inverse hyperbolic cosine for each element of X
.
cos Compute the cosine for each element of X in radians.
cosh Compute the hyperbolic cosine for each element of X.
acosd Compute the inverse cosine in degrees for each element of X
.
cosd Compute the cosine for each element of X in degrees.
cosint Compute the cosine integral function:
Ćwiczenie: zobacz pomoc dla polecenia format. Porównaj wyniki wyświetlania liczby $\pi$ w róznych formatach, np.: short, long, rat, bin
cd zmiana katalogudir zawartość katalogupwd bieżący katalogsave nazwa zapis zmiennych, load nazwa odczytanie zmiennychdate dataclc czyszcenie wiersza poleceńquit wyjście z Matlabdate
ans = 03-Nov-2020
Ćwiczenie: wykonaj nastepujące kroki:
dane dane i wypisz ich wartościTryby pracy Matlab:
*.m (M-pliki) zawierający ciąg instrukcji staje się poleceniem Matlab. Nazwa pliku staje się poleceniem MatlabaPrzykład: uruchomienie pliku hello.m
hello
Witaj Świecie
type nazwa wyświetla zawartość plikuedit nazwa otwiera edycję plikutype hello
% To jest pierwszy progeam w Matlab tekst = 'Witaj Świecie'; disp(tekst)
help hello
To jest pierwszy progeam w Matlab Additional help for built-in functions and operators is available in the online version of the manual. Use the command 'doc <topic>' to search the manual index. Help and information about Octave is also available on the WWW at https://www.octave.org and via the help@octave.org mailing list.
Napisz skrypt o nazwie zad1.m, który wykona nastepujące instrukcje: