function my_first_matlab_script %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% askhsh 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %1 a = 2^5/(2^5-1); disp(['result 1: ', num2str(a)]); % the result will be displayed only if a is converted to string %2 a = (1-1/2^5)^(-1); disp(['result 2: ', num2str(a)]); % I overwrite variable a %3 a = log(exp(3)); disp(['result 3: ', num2str(a)]); % I overwrite variable a %4 a = log10(10^5); disp(['result 4: ', num2str(a)]); % I overwrite variable a %5 a = sin(pi/6); disp(['result 4: ', num2str(a)]); % I overwrite variable a %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% askhsh 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% disp('------ askisi 2--------'); A = [1 2 3]; % grammh disp(A); B = [3;4;5]; % sthlh disp(B); % here I do not need to use num2str because inside disp I have only double (not double+string) disp('==== 2.1 ===='); C = A' % instead of disp I do not use ; disp('==== 2.2 ==== '); A = [1 1+i 1-i]; C1 = A' % ypologizei ton syzygh anastrofo pinaka C2 = A.' % correct disp('==== 2.3 ==== '); A = [1 2 3]; B = [3;4;5]; C3 = A+B.' % h prosuesh mporei na ginei me 2 tropous C4 = A.'+B % edw to .' einai peritto mias kai A, B exoyn pragmatika stoixeia disp('==== 2.4 ==== '); C5 = A.*B.' % pollaplasiazw ta STOIXEIA tou A me ta STOIXEIA toy B. Oi pinakes prepei na einai idias diastashs C6 = A.'.*B % dhladh (A.') .* B. to idio me panw apla to apotelesma einai grammh / sthlh antistoixa disp('==== 2.5 ==== '); C5 = A*B % pollaplasiazw ena 1x3 pinaka me ena 3x1 pinaka 1x3 * 3x1 = 1x1 C6 = B*A % pollaplasiazw ena 3x1 pinaka me ena 1x3 pinaka 3x1 * 1x3 = 3x3 C7 = A.'*B.' % idio me C6 disp('==== 2.6 ==== '); A = [1 3; 4 5]; C8 = A(1,:) C9 = A(:,2) C10 = det(A) % mono gia tetragwnikous pinakes!! C11 = inv(A) % b tropos gia eyresh antistrofoy I = [1 0; 0 1]; % monadiaios pinakas C12 = A\I; % prosoxh den einai diairesh alla isodynamei me inv(A)*I = inv(A) disp('==== 2.7 ==== '); % lynoyme to systhma Ax=b dhladh x=inv(A)*b ή αλλιως x=A\b; A = [5 -3 2; -3 8 4; 2 4 -9] % o A einai 3x3 ara gia na ginei h diairesh prepei o b na einai 3x1 %3x3 3x1 --> 3x1 b = [10; 20; 9] x = A\b % epalh8eush d = A*x %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% askhsh 3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% disp('------ askisi 3--------'); disp('==== 3.1 ==== '); x1 = -10:0.1:10 % bhma 0.1 gia kalyterh analysh (-10 -9.9 -9.8 klp) f1 = exp(-x1/10).*sin(x1); figure; plot(x1, f1); % bazoyme kai titlo title('grafikh parastash synarthshs') xlabel('eimai to x'); ylabel ('eimai to y'); legend('ki egw eimai h kampylh'); disp('==== 3.2 ==== '); syms x2; f2 = exp(-x2/10).*sin(x2); figure; ezplot(x2, f2, [-10, 10]); % bazoyme kai titlo title('grafikh parastash synarthshs') xlabel('eimai to x'); ylabel ('eimai to y'); legend('ki egw eimai h kampylh'); % as baloume kai tis dyo kampyles mazi!! figure; hold on; % xwris auto, 8a panwgrafei h yparxousa kampylh ezplot(x2, f2, [-10, 10]); plot(x1, f1, 'm--'); % allazw xrwma gia na fainomai.. kai bazw kai diakekommenh grammh gia na mhn krypsw thn allh kampylh title('grafikh parastash synarthshs') xlabel('eimai to x'); ylabel ('eimai to y'); legend('with symbolic variable', 'and without'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% askhsh 4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% disp('------ askisi 4--------'); disp('==== 4.1 ==== '); z = 3+sqrt(3)*j; R = real(z) I = imag(z) disp('==== 4.2 ==== '); % kata ta gnwsta enas migadikos z = a+jb grafetai ws z=|z|*exp(jwmega) % opoy wmeega h efaptomenh ths gwnias tou % tropos 1 platos = abs(z) gwnia = angle(z) % tropos 2 platos2 = sqrt(R^2+I^2) % parathreiste oti einai iso me platos gwnia2 = atan2(I, R)% parathreiste oti einai iso me gwnia disp('==== 4.3 ==== '); % polikh morfh z2 = platos*exp(j*gwnia) % parathrw oti z2 = z disp('==== 4.4 ==== '); syms x y; z = x+y*j; f = (z.^2-3)./(z-1); figure; ezsurf(x, y, f, [-5 5]); xlabel('pragmatiko meros'); ylabel('fantastiko meros'); zlabel('synarthsh f'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% askhsh 5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% disp('------ askisi 5 --------'); disp('==== 5.1 ==== '); % me thn xrhsh symbolikwn syms x; f = x^3-2*x^2-3*x+10; rizes = solve(f, x) disp('==== 5.2 ==== '); % xwris thn xrhsh symbolikwn kai epeidh einai polywnymo!! % pernaw ston pinaka toys syntelestes polywnymoy p = [1 -2 -3 10]; rizes2 = roots(p) % parathrw oti rizes = rizes2 end