commit 5c3e6b4d9c840b802c76645b0c54112abb9621cc Author: Giovanni Di Grezia Date: Wed Oct 1 14:09:48 2014 +0200 Primi esercizi in Matlab compreso algoritmo di risoluzione per sistemi lineari diff --git a/float2bin.m b/float2bin.m new file mode 100644 index 0000000..7b89583 --- /dev/null +++ b/float2bin.m @@ -0,0 +1,28 @@ + +function b = float2bin(f) +%This function converts a floating point number to its binary form. + +%Input error handling +if ~isfloat(f) + disp('Input must be a floating point number.'); + return; +end + +%Hex characters +hex = '0123456789abcdef'; + +%Convert from float to hex +h = num2hex(f); + +%Convert to cell array of chars +hc = num2cell(h); + +%Convert to array of numbers +nums = cellfun(@(x) find(hex == x) - 1, hc); + +%Convert to array of binary numbers +bins = dec2bin(nums, 4); + +%Reshape into horizontal vector +b = reshape(bins.', 1, numel(bins)); +end \ No newline at end of file diff --git a/jesocristo_calculate_eps.m b/jesocristo_calculate_eps.m new file mode 100644 index 0000000..93a5ce0 --- /dev/null +++ b/jesocristo_calculate_eps.m @@ -0,0 +1,5 @@ +errore = 1; +while 1+errore ~= 1 + errore = errore /2; +end +errore = errore *2 \ No newline at end of file diff --git a/jesocristo_minimo.m b/jesocristo_minimo.m new file mode 100644 index 0000000..632aad5 --- /dev/null +++ b/jesocristo_minimo.m @@ -0,0 +1,6 @@ +u = 1; +while u~= 0 + rmin = u; + u=u/2; +end +rmin \ No newline at end of file diff --git a/jesocristo_while.m b/jesocristo_while.m new file mode 100644 index 0000000..2208bb7 --- /dev/null +++ b/jesocristo_while.m @@ -0,0 +1,5 @@ +a = 0; +while a~= 5 + a= a + 0.625 +end + \ No newline at end of file diff --git a/liner_system_resolver.m b/liner_system_resolver.m new file mode 100644 index 0000000..569340d --- /dev/null +++ b/liner_system_resolver.m @@ -0,0 +1,17 @@ +U=[2,2,4;0,-7,-11;0,0,2]; +b=[5;-8;-2]; + +x=[]; +n= length(b); +x(n) = b(n)/U(n,n); + +for i=n-1:-1:1 + somma = 0; + for k=i+1:n + somma=somma+U(i,k) * x(k); + end + + x(i) = (b(i) - somma)/ U(i,i); +end +disp ('La soluzione è ') +x \ No newline at end of file diff --git a/matricesuperiore.m~ b/matricesuperiore.m~ new file mode 100644 index 0000000..18deca4 --- /dev/null +++ b/matricesuperiore.m~ @@ -0,0 +1,10 @@ +U=[1,2,3:4,5,6;7,8,9]; +B=[5;6;7]; + +x=[]; +n= lenght(B); +x(n) = b(n)/U(n,n); + +for i=n-1:-1:1 + somma = 0; + for k \ No newline at end of file