Колись здавалось, що до кінця ще дуже далеко, а тепер ось я тут - здав останню сесію в свому житті.
Хочеться залишити після себе якийсь слід... наприклад щось корисне для інших поколінь магістрів... наприклад реалізацію перших чотирьох лабораторних робіт)
"Чтоб жизнь малиной не казалась" реалізацією п'ятої лабораторної роботи залишу на вашу совість.
От власне реалізація першої, здається найпростішої лабораторної роботи:
Код:
%#> Lab#1_Sheremeta
%-> Arithmetic calculations
answ = 1 + 2;
fprintf('-> Arithmetic calculations: First example result equals %d\n', answ);
answ = answ/4.5;
fprintf('-> Arithmetic calculations: Second exapmle result equals %d\n', answ);
%-> Elementary functions
answ = exp(-2.5) * log(11.3)^0.3 - sqrt((sin(2.45 * pi) + cos(3.78 * pi))/tan(3.3));
fprintf('-> Elementary functions: Third example result equals %d\n', answ);
answ = (2.1 + 3.2i) * 2 + (4.2 + 1.7i)^2;
fprintf('-> Elementary functions: Fourth example result equals %d + i%d\n', real(answ), imag(answ));
%-> Charting
% First plot
figure(1);
x = 0:0.01:1;
y = exp(-x).*sin(10*x);
plot(x, y, 'r-*');
grid on;
% Second plot with two charts on it
figure(2);
x = -1:0.005:-0.3;
f = sin(x.^-2);
g = sin(1.2*x.^-2);
plot(x, f, 'r-*', x, g, 'b-*');
grid on;
%-> Functions
% syntax of functions in matlab:
% function f = myfun(x)
% f = exp(-x)*sqrt((x^2 + 1)/(x^4 +0.1));
% I know that I can save function in separate file, and use it everywhere
% in project workspace, but let's use anonymous function here
% Anonymos function with single number argument
myFun = @(x) exp(-x)*sqrt((x^2 + 1)/(x^4 +0.1));
fprintf('-> Functions: Fifth example result equals %d\n', myFun(5));
% Anonymos function with single array argument
myFunForEach = @(x) exp(-x).*sqrt((x.^2 + 1)./(x.^4 + 0.1));
fprintf('-> Functions: Sixth example result equals %d, %d\n', myFunForEach([1.3, 7.2]));
% Let's chart a plot with function
x = 0:0.1:4;
y = myFunForEach(x);
figure(3);
plot(x, y, 'r-*');
grid on;
% Anonymos function with multiple arguments
radius3 = @(x, y, z) sqrt(x.^2 + y.^2 + z.^2);
fprintf('-> Functions: Seventh example result equals %d\n', radius3(1, 1, 1));
%-> Loops
% Let's chart a plot with using loop
figure(4);
x = 0:pi/30:2*pi;
for a = -0.1:0.02:0.1
y = exp(-a*x).*sin(x);
plot(x, y);
hold on;
end;
grid on;
%-> Individual task implementation (variant #7)
%{
Завдання:
а) Побудувати графік функції на інтервалі [0, 10] згідно варіанту.
б) Визначити максимум та мінімум функції на заданому проміжку.
%}
x = 0:0.1:10;
y = sqrt(exp(-x) + sin(x));
figure(5)
plot(x, real(y), 'r-*');
grid on;
title('Individual task implementation(variant #7)');
fprintf('-> Individual task implementation:\n\tmaximum value of the given function on the interval [0, 10] equals %d\n\tminimum value of the given function on the interval [0, 10] equals %d\n', max(y), min(y));
clear;
P.S. Мою реалізацію наступних лабораторних робіт дивіться в відповідних топіках.