Blog Archives

lesson_2_ex_3_19_20_GaussNaive

#Save the following function as GaussNaive.m file function x = GaussNaive(A,b) % GaussNaive: naive Gauss elimination % x = GaussNaive(A,b): Gauss elimination without pivoting. % input: % A = coefficient matrix % b = right hand side vector % output:

Posted in Uncategorized

lesson_2_ex_2_19_20

function norm=my_norm(A) % calculates the max absolute row sum for the matrix A [m,n]=size(A); largest=0; for i=1:m % loop along rows row_sum=0; for j=1:n % loop along columns row_sum=row_sum+abs(A(i,j)); end if row_sum>=largest largest=row_sum; end end norm=largest;  

Posted in Uncategorized

lesson_2_ex_1_19_20

%insert matrix A elements from keyboard for i=1:3 for j=1:4 A(i,j)=input(“Dose stoixeio tou A:”) end end %insert matrix B elements from keyboard for i=1:3 for j=1:4 B(i,j)=input(“Dose stoixeio tou B:”) end end %Matrix addition C=A+B  

Posted in Uncategorized

lesson_1_ex_1_19_20

a=input(“Dose to a:”); b=input(“Dose to b:”); c=input(“Dose to c:”); D=b^2-4*a*c if D>0 x1=(-b+sqrt(D))/2*a x2=(-b-sqrt(D))/2*a k=sprintf(“Oi luseis einai x1= %f kai x2=%f”,x1,x2); disp(k) elseif D==0 x=-b/2*a k=sprintf(“I lusi einai x= %f”,x); disp(k) else disp(“Den exei pragmatikes luseis”) endif  

Posted in Uncategorized

lesson_13_ex_2_17_18

def bathmologia(agwnes): scores = {} for i in agwnes: print i tl=i.split(“: “) tl1=tl[0].split(“-“) print tl , tl1 if tl1[0] not in scores: scores[tl1[0]]=0 if tl1[1] not in scores: scores[tl1[1]]=0 tl2=tl[1].split(“-“) if int(tl2[0]) > int(tl2[1]): scores[tl1[0]] += 3 elif int(tl2[0])

Posted in Uncategorized

lesson_13_ex_1_17_18

import pylab import numpy x = numpy.linspace(-15,15,100) y = x**5 + 24*x**2 – 100 + numpy.log(x) pylab.plot(x,y) pylab.show()  

Posted in Uncategorized

lesson_12_ex_2_17_18

def Fibo(n): if n == 1 or n == 2: return 1 else: l = [1,1] for i in range(2 , n): l.append(l[i-1] + l[i-2]) return l[-1] print Fibo(10) def Ribo(n): if n == 1: return 6 else: l =

Posted in Uncategorized

lesson_12_ex_1_17_18

def my_primes(x): counter = 0 i = 2 while (i <= x – 1): if x % i == 0: return ‘no’ i += 1 return ‘yes’ print my_primes(2), my_primes(1), my_primes(3)  

Posted in Uncategorized

lesson_11_ex_3_17_18

# -*- coding: utf-8 -*- “”” Created on Thu May 31 18:23:16 2018 @author: stkarlos “”” def discrete_maths(start , stop , show = False): k = [] for i in range(start , stop + 1): j = str(i) if (int(j[0])

Posted in Uncategorized

lesson_11_ex_2_17_18

# -*- coding: utf-8 -*- “”” Created on Thu May 31 18:13:54 2018 @author: stkarlos “”” def discrete_maths(start , stop , show = False): k = [] for i in range(start , stop + 1): j = str(i) if (int(j[0])

Posted in Uncategorized