Skip to content

Commit

Permalink
Last version - included comments in code and answers in pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloOb committed Jun 10, 2018
1 parent a86f4b7 commit 55b9dcc
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
Binary file modified moo2.pdf
Binary file not shown.
6 changes: 3 additions & 3 deletions zad1.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
clc
format long

%dane
syms x1 x2
r1(x1, x2) = x1^2 + 8 * x2^2 + 2 * x1 - 655;
r2(x1, x2) = 16 * x1 * x2 + 6 * x2 - 1456;

eps = 0.1;
x0 = [11.3; 7.8];

a = x0(1);
b = x0(2);
i = 0;

f(x1, x2) = .5 * (r1 .* r1 + r2 .* r2);
f(x1, x2) = 0.5 * (r1 * r1 + r2 * r2);
g(x1, x2) = gradient(f);
h(x1, x2) = hessian(f);

Expand All @@ -36,7 +36,7 @@
norm = sqrt(g1(1)^2 + g1(2)^2);
norm = double(norm);
i = i+1;

%wyswietl wyniki
disp(['x' num2str(i) ' = [' num2str(a) ',' num2str(b) ']; ||grad f(x' num2str(i) ')|| =' num2str(norm) ])
xp = xn;
end
5 changes: 5 additions & 0 deletions zad2.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
c = x0(3);

g(x1, x2, x3) = gradient(f);
%przyblizenie poczatkowe- odwrotnosc macierzy hessego

B0 = eye(3);
i = 0;

Expand Down Expand Up @@ -47,10 +49,13 @@
g0 = g1;
g1 = g(a, b, c);
q = g1 - g0;

%konwersja do wyswietlenia
norm = sqrt(g1(1)^2 + g1(2)^2 + g1(3)^2);
norm = double(norm);
i = i + 1;

%wyswietl wyniki
disp(['x' num2str(i) ' = [' num2str(a, '%4.3f') ',' num2str(b, '%4.3f') ',' num2str(c, '%4.3f') ']; ||grad f(x' num2str(i) ')|| =' num2str(norm, '%4.6f') ])

D = dp' * q;
Expand Down
3 changes: 3 additions & 0 deletions zad3.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
clc
format long

%dane
a = 14.8;
b = 10.6;
c = 15;
Expand Down Expand Up @@ -31,6 +32,7 @@
L2 = double(Lb);
x1 = double(subs(x1));
x2 = double(subs(x2));

%w tym miejscu mamy juz L1 L2, i x(L)
%aby alfa*c = 0 musimy miec L1 * c1 == 0 i L2 * c2 == 0
%sprawdzenie
Expand All @@ -39,5 +41,6 @@
error('Error. \n Warunek alfa * c nie spe³niony')
end

%wyswietl wyniki
disp(['x = [' num2str(x1, '%4.3f') ',' num2str(x2, '%4.3f') '], L = [' num2str(L1, '%4.3f') ', ' num2str(L2, '%4.3f') ']'])

2 changes: 2 additions & 0 deletions zad4.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
clc
format long

%dane
g_acc = 9.81;
m1 = 6;
m2 = 8;
Expand Down Expand Up @@ -53,5 +54,6 @@
y2 = -2 * l * cos(xp(1)) - l * cos(xp(2));
phi2 = 270 + xp(2) * 180 / pi;

%wyswietl wyniki
disp(['q1 = [x1, y1, phi1] = [' num2str(x1, '%4.3f') ', ' num2str(y1, '%4.3f') ', ' num2str(phi1, '%4.3f') ']' ])
disp(['q2 = [x2, y2, phi2] = [' num2str(x2, '%4.3f') ', ' num2str(y2, '%4.3f') ', ' num2str(phi2, '%4.3f') ']' ])

0 comments on commit 55b9dcc

Please sign in to comment.