Sunteți pe pagina 1din 10

Aplicaii Matlab

1. S se calculeze: 125 3 14

1
.
6

>> 125+14^(1/3)+1/6
ans =
1.275768089308419e+02

2. S se aproximeze ca fracie: 4 120 .


>> rats(120^(1/4))
ans =
1731/523

3. S se transforme numrul 2557 din baza 8 n baza 10.


>> base2dec('2557',8)
ans =
1391

4. Ci metri care un yard?


>> unitsratio('m','yd')
ans =
0.9144

5. Ci inci reprezint 30 cm?


>> 30*unitsratio('in','cm')
ans =
11.811023622047244
6. Cte grade are un radian?
>> unitsratio('deg','rad')
ans =
57.295779513082323

7. S se defineasc variabilele simbolice a, b i x, polinoamele simbolice


f(x)=ax+b, g(x)=bx+a i s se calculeze produsul lor.
>> syms a b x
>> f=a*x+b
1

f =
b + a*x
>> g=b*x+a
g =
a + b*x
>> f*g
ans =
(a + b*x)*(b + a*x)

8. S se defineasc o variabil simbolic de tip complex i s se calculeze, partea


real i conjugata.
>> syms x y real
>> z=x+y*i
z =
x + y*i
>> real(z)
ans =
x
>> conj(z)
ans =
x - y*i

9. S se defineasc variabila simbolic x i funcia simbolic f(x) =


S se calculeze valoarea funciei f n punctul x=2.

2x 2 x 3 .

>> syms x f
>> f=sqrt(2*x^2+x+3)
f =
(2*x^2 + x + 3)^(1/2)
>> subs(f,2)
ans =
13^(1/2)

10. Fie funcia simbolic de dou variabile f(x, y) = x2 + y2 + xy + 2. S se


calculeze valoarea funciei f pentru x = 1 i y = -2.
>> syms x y
>> f=x^2+y^2+x*y+2
f =
x^2 + x*y + y^2 + 2
>> subs(f,{x,y},{1,-2})
ans =
5

11. S se defineasc matricea cu elementele simbolice a, b, c, d i s se calculeze


determinantul i inversa acesteia.
>> syms a b c d
>> M=[a b; c d]
M =
[ a, b]
[ c, d]
>> det(M)
ans =
a*d - b*c
>> inv(M)
ans =
[ d/(a*d - b*c), -b/(a*d - b*c)]
[ -c/(a*d - b*c), a/(a*d - b*c)]

12. S se determine forma soluiilor ecuaiei ax2 + bx + c = 0.


>> syms a b c x
>> f=a*x^2+b*x+c
f =
a*x^2 + b*x + c
>> solve(f)
ans =
-(b + (b^2 - 4*a*c)^(1/2))/(2*a)
-(b - (b^2 - 4*a*c)^(1/2))/(2*a)

13. S se rezolve ecuaia x2 + 5x + 6 = 0.


>> sym x
ans =
x
>> f=x^2+5*x+6
f =
x^2 + 5*x + 6
>> solve(f)
ans =
-3
-2

14. S se rezolve ecuaia ex = x + 1.


>> sym(x,'real')
ans =
x
>> solve('exp(x)=x+1')
ans =

0
2 x y 3
15. S se rezolve sistemul de ecuaii
.
x 3 y 4

>> syms x y f g
>> f=2*x+y-3
f =
2*x + y - 3
>> g=x+3*y-4
g =
x + 3*y - 4
>> s=solve(f,g)
s =
x: [1x1 sym]
y: [1x1 sym]
>> s.x
ans =
1
>> s.y
ans =
1
1 2 1
1 0 1

16. Fie matricele A 2 0 1 i B 3 2 0 . S se calculeze A + B, A B,


3 1 3
1 1 3

A * B, A / B, B / A, A + 2, B * 3. S se concateneze pe orizontal i pe vertical


cele dou matrice.

>> A=[1 2 1; 2 0 1; 3 1 3]
A =
1
2
1
2
0
1
3
1
3
>> B=[1 0 1; 3 2 0; 1 1 3]
B =
1
0
1
3
2
0
1
1
3
>> A+B
ans =
2
2
2
5
2
1
4
2
6

>> A-B
ans =
0
2
0
-1
-2
1
2
0
0
>> A*B
ans =
8
5
4
3
1
5
9
5
12
>> A/B
ans =
-1.5714
0.5714
1.8571
0.1429
1.7143
0.2857
>> A\B
ans =
2.8000
1.6000
0.4000
-0.2000
-2.6000
-1.2000
>> A+2
ans =
3
4
3
4
2
3
5
3
5
>> B*3
ans =
3
0
3
9
6
0
3
3
9
>> C=[A B]
C =
1
2
1
2
0
1
3
1
3
>> D=[A;B]
D =
1
2
1
2
0
1
3
1
3
1
0
1
3
2
0
1
1
3

0.8571
-0.2857
0.4286

-1.0000
0
2.0000

1
3
1

0
2
1

1
0
3

1 2 1 0

3 4 1 8
. S se calculeze sumele pe coloane i suma
17. Fie matricea A
7 6 7 2

0 5 2 1

tuturor elementelor din matrice. S se determine valorile minime de pe fiecare


coloan. S se calculeze valoarea minim de pe colana a doua i valoarea
maxim de pe linia a treia. S se determine valoarea medie elementelor matricei.
>> A=[1 2 1 0; 3 4 1 8; 7 6 7 2; 0 5 2 1]
A =
1
2
1
0
3
4
1
8
7
6
7
2
0
5
2
1
>> S=sum(A)
S =
11
17
11
11
>> Suma=sum(S)
Suma =
50
>> min(A)
ans =
0
2
1
0
>> min(A(:,2))
ans =
2
>> max(A(3,:))
ans =
7
>> nr_el=numel(A)
nr_el =
16
>> media=Suma/nr_el
media =
3.1250

121
1.735 2.123 1

19.5
77
25
10
S se determine elementele de
18. Fie matricea M
14
0
992
4

78

99
34
.
5
78
.
2

pe diagonala principal a metricei i suma elementelor de pe diagonala matricei.


>> M=[1.735 2.123 1 121; 10 19.5 77 25; 14 0 992 4; 78
99 34.5 78.2]

M =
1.7350
2.1230
10.0000
19.5000
14.0000
0
78.0000
99.0000
4
>> D=diag(M)
D =
1.7350
19.5000
992.0000
78.2000
>> sum(D)
ans =
1.0914e+03
>> trace(M)
ans =
1.0914e+03

1.0000
77.0000
992.0000
34.5000

19. S se reprezinte grafic funcia f(x) =


[-4, 4].

121.0000
25.0000
4.0000
78.2000

2x 2 x 3

pe intervalul de valori

>> x=-4:0.1:4;
>> y=sqrt(2*x.^2+x+3);
>> plot(x,y)

20. S se reprezinte grafic funciile sin i cos pe intervalul [0, 6 ].


>> x=linspace(0,6*pi,200);
>> y=sin(x);
>> plot(x,y,'r');

>>
>>
>>
>>
>>
>>
>>

hold on;
y=cos(x);
plot(x,y,'b');
title('Graficele functiilor sin si cos');
xlabel('Ox');
ylabel('Oy');
grid on;

21. Inserarea unui grid pe o imagine dat.


clf
rgb = imread('c:\10.jpg');
imshow(rgb)
hold on
M = size(rgb,1);
N = size(rgb,2);
for k = 1:25:M
x = [1 N];
y = [k k];
plot(x,y,'Color','w','LineStyle','-');
plot(x,y,'Color','k','LineStyle',':');
end
for k = 1:25:N
x = [k k];
y = [1 M];
plot(x,y,'Color','w','LineStyle','-');
plot(x,y,'Color','k','LineStyle',':');
end
hold off

22. Un cerc
function plotround
x0=390;
y0=423;
O=x0+i*y0;
d=20;
Z0=O+d;
thitar=0:10:360; %degree
rthitar=thitar*pi/180; %rad
lr=length(rthitar);
for di=1:lr
Z(di)=O+(Z0-O)*exp(i*rthitar(di));
end
pZ=[Z,Z(1)];
hold on;
plot(pZ,'ko-');

23. Exemplu de funcie pentru importul datelor


9

raw=[];
for k='D':4:'P'
sir=strcat(k,int2str(2),':',k,int2str(16))
% xx=uint8(k)-67;
raw_ = xlsread('C:\Apa.xlsx','Mangan',sir);
%[~, ~, raw0_1] = xlsread('C:\Apa.xlsx','Mangan','H2:H16');
%[~, ~, raw0_2] = xlsread('C:\Apa.xlsx','Mangan','L2:L16');
%[~, ~, raw0_3] = xlsread('C:\Apa.xlsx','Mangan','P2:P16');
raw = [raw raw_];
end
%% Create output variable
data = reshape([raw{:}],size(raw));
%%
M1
M2
M3
M4

Allocate imported array to column variable names


= data(:,1);
= data(:,2);
= data(:,3);
= data(:,4);

%% Clear temporary variables


clearvars raw raw_ sir;

10