% EE3510 HW1 105060012張育菘
% 1.

close all; clear;

x = [2 1+2j; 
    -0.45 5];
I = [1 0;
    0 1];
z1 = 0.5*log(x+sqrt(1+x.^2)) + I;
z1

%
% 2.

A = [12 34 -4; 34 7 87; 3 65 7];
B = [1 4 7; 2 5 8; 3 6 9];

z2 = A*B;
z3 = A.*B;
z4 = A^3;
z5 = A.^3;
z6 = [A([1:3],:);B^2];
[T, E] = eig(B); z7 = E;
z8 = det(A);
z2 
z3
z4
z5
z6
z7
z8

%
% 3.

H3 = [1/2 1/3 1/4; 1/3 1/4 1/5; 1/4 1/5 1/6];
Y = [0.95; 0.67; 0.52];
x = (H3^-1)*Y;
x1 = x(1,1); x2 = x(2, 1); x3 = x(3, 1);
fprintf('x1 = %2.2f, x2 = %2.2f, x3 = %2.2f\n', x1, x2, x3);

Y = [0.95; 0.67; 0.53];
x = (H3^-1)*Y;
x1 = x(1,1); x2 = x(2, 1); x3 = x(3, 1);
fprintf('After changing 0.52 to 0.53:\n');
fprintf('x1 = %2.2f, x2 = %2.2f, x3 = %2.2f\n', x1, x2, x3);

%
% 4.
% H_{\mathrm{ij}} =\frac{1}{i+j-1},H_{\mathrm{ij}} =\int_0^1 x^{i+j-2} \mathrm{dx}

H4 = zeros(9,9);

for i = 1:1:9
    for j = 1:1:9
        f4 = @(x) x.^(i+j-2);
        H4(i, j) = integral(f4, 0, 1);
    end
end
H4

%
% 5.

figure; 
fplot(@(x) -sqrt(cos(x))+3, [-pi/2, pi/2]);
title('-sqrt(cos(x))+3');
xlabel('x');

figure;
x =[-2:0.2:2];  % value x range
y =[-4:0.2:4];  % value y range
[xm, ym] = meshgrid(x,y);  % meshgrid: 2-D and 3-D grids
fxy =  (xm.^2/(2^2)) - (ym.^2/(4^2)); % Your Function  fxy=f(x,y) 
surf(fxy);   % surf : Surface plot
title('(x^2/(2^2)) - (y^2/(4^2))');