Professional Documents
Culture Documents
Simbolički paket
Željko Ban
Mato Baotić
Jadranko Matuško
2014/2015
⌥ ⌅
⌥ ⌅ >> ezplot ( ' xˆ2+yˆ2=4 ' , . . .
>> ezplot ( ' xˆ2+2* x+3 ' ) [ 3 ,3 , 3 ,3])
⌃ ⇧⌃ ⇧
>> g r i d on >> g r i d on
x 2 +2 x+3
x 2 +y 2 =4
3
50
2
40
1
30
0
y
20
-1
10
-2
0
-3
-6 -4 -2 0 2 4 6 -3 -2 -1 0 1 2 3
x x
⌥ ⌅
>> ezplot ( ' s i n ( t ) ' , . . . ⌥ ⌅
' ( s i n (2 * t ) ) ' , [ 0 , 2 * p i ] ) ; >> ezplot3 ( ' s i n ( t ) ' , ' cos ( t ) ' , . . .
⌃ ⇧⌃ ⇧
>> g r i d on ; ' t ' ,[0 ,6* pi ] )
x = sin(t), y = cos(t), z = t
0.8
0.6
20
0.4 18
16
0.2 14
12
z
0
y
10
8
-0.2
6
4
-0.4
2
0
-0.6 1
0.5 1
-0.8
0 0.5
0
y -0.5
-1 -0.5 0 0.5 1 -0.5
x
x -1 -1
⌥ ⌅
subplot ( 2 2 1 ) , x exp(-x 2 - y 2 ) x exp(-x 2 - y 2 )
[ 4 ,4 , 4 ,4])
0.5
subplot ( 2 2 2 ) , 0 0
subplot ( 2 2 3 ) ,
-2 -2 x -2 -2 x
y -4 -4 y -4 -4
[ 4 ,4 , 4 ,4])
4
subplot ( 2 2 4 ) ,
0.4
2
0.2
⌃ ⇧
0
y
[ 4 ,4 , 4 ,4])
-0.2
-1
-0.4
-2
4
2 4
-3
0 2
-2 0
-4 y -2
-4 -2 0 2 4 -4 -4 x
x
⌃ ⇧
f o r k = 2:1000000
Elapsed time is 0.214507 seconds .
x ( k ) = x ( k 1) + 5 ;
⌃ ⇧
end
⌥ ⌅
% prealokacija verzija 1 ⌥ ⌅
x = zeros (1 ,1000000) ;
>> t i c , test_mem_aloc2 , toc
⌃ ⇧
f o r k = 2:1000000
Elapsed time is 0.014794 seconds .
x ( k ) = x ( k 1) + 5 ;
⌃ ⇧
end
⌥ ⌅
% prealokacija verzija 2 ⌥ ⌅
x (1 ,1000000) =0;
>> t i c , test_mem_aloc3 , toc
⌃ ⇧
f o r k = 2:1000000
Elapsed time is 0.012562 seconds .
x ( k ) = x ( k 1) + 5 ;
⌃ ⇧
end
⌥ ⌅⌥ ⌅
f u n c t i o n y = myfunc ( x ) f u n c t i o n x = myfunc ( x )
⌃ ⇧⌃ ⇧
f u n c t i o n [ a b c ] = myfunc ( x ) f u n c t i o n [ x b c ] = myfunc ( x )
⌃ ⇧
i = i + 1; toc ;
y ( i ) = sin ( t ) ;
end
⌃⌥ ⇧ ⌅
toc ;
>> TestFor
Elapsed time is 0.038448 seconds .
>> TestVec
⌃ ⇧
Elapsed time is 0.012799 seconds .
⌃ ⇧
Elapsed time is 0.012340 seconds .
⌃ ⇧
Elapsed time is 0.024861 seconds .
⌃ ⇧
i f a ( ii , jj ) > 5 a(˜b ) = a(˜b ) . ˆ 2 ;
a ( ii , jj ) = s q r t ( a ( ii , jj ) ) ;
else
a ( ii , jj ) = a ( ii , jj ) ˆ2;
end
end
⌃ ⇧
end
⌃ ⇧
>> a = sym ( ' alpha ' ) ;
⌃ ⇧
( 3 ˆ ( 1 / 2 ) * i ) /2 + 1/2
⌥ ⌅
>> assume ( x , ' r e a l ' ) ;
>> solve ( ' xˆ3+1==0 ' )
ans =
⌃ ⇧
1
⌃ ⇧
2
⌥ ⌅
>> z = sym ( ' ( 1 + s q r t ( 5 ) ) /2 ' ) ;
>> f = z ˆ2 z 1
f =
( 5 ˆ ( 1 / 2 ) /2 + 1 / 2 ) ˆ2 5 ˆ ( 1 / 2 ) /2 3/2
>> simplify ( f )
ans =
⌃ ⇧
0
⌃ ⇧
x ˆ3 6* x ˆ2 + 11* x 6
⌥ ⌅
>> syms x y
f = cos ( x + y ) ;
>> expand ( f )
ans =
⌃ ⇧
cos ( x ) * cos ( y ) sin ( x ) *sin ( y )
⌃ ⇧
[ x 3, x 1, x 2]
⌥ ⌅
>> syms x
f = x ˆ6 + 1 ;
>> factor ( f )
ans =
⌃ ⇧
[ x ˆ2 + 1 , x ˆ4 x ˆ2 + 1]
>> collect ( f , y )
ans =
⌃ ⇧
( x ˆ2 + x ) * y x ˆ2 2* x
⌃ ⇧
(b sigma ) / ( 2 * a )
⌃ ⇧
b + 4
⌥ ⌅
>>subs ( a * b ˆ2 , a * b , 5 )
ans =
⌃ ⇧
5* b
⌃ ⇧
2* x * cos ( x ˆ2)
⌥ ⌅
>> syms x y
>> d i f f ( x * cos ( x * y ) , y , 2 )
ans =
⌃ ⇧
x ˆ3* cos ( x * y )
⌃ ⇧
piecewise ( [ n == 1, log ( x ) ] , [ n ˜= 1, x ˆ ( n + 1 ) / ( n + 1 ) ] )
⌥ ⌅
>> assume ( n ˜= 1)
>> int ( f )
ans =
⌃ ⇧
xˆ(n + 1) / ( n + 1)
⌃ ⇧
4/9
⌃ ⇧
(b ( bˆ2 4*a * c ) ˆ ( 1 / 2 ) ) / ( 2 * a )
⌃ ⇧
p i /4
⌃ ⇧
in ( k , ' i n t e g e r ' )
⌃ ⇧
2
⌥ ⌅
>> xvalues = subs ( solx , solk ) 1
xvalues =
(5* p i ) /4
p i /4
0.5
(3 * p i ) /4
⌃ ⇧
(7 * p i ) /4 0
-0.5
-1 cos(x)
-sin(x)
-6 -4 -2 0 2 4 6
x
⌃ ⇧
C5 * exp ( t ) s i n ( t ) /2 cos ( t ) /2
⌃ ⇧
exp ( t ) /2 cos ( t ) /2 s i n ( t ) /2
⌃ ⇧
[ a_21 , a_22 ]
⌃ ⇧
[ a_21 / ( a_11 * a_22 a_12 * a_21 ) , a_11 / ( a_11 * a_22 a_12 * a_21 ) ]
⌃ ⇧
[ a_21 * sigma , a_11 * sigma ]
⌃ ⇧
a_11 * a_22 a_12 * a_21
⌃ ⇧
[ 1, a_11 a_22 , a_11 * a_22 a_12 * a_21 ]
⌥ ⌅
I odnosno karakteristične vrijednosti (funkcija eig).
>> e i g ( A )
ans =
a_11 /2+ a_22 /2 ( a_11ˆ2 2*a_11 * a_22 + a_22 ˆ2+4* a_12 * a_21 ) ˆ ( 1 / 2 ) /2
⌃ ⇧
a_11 /2+ a_22 / 2 + ( a_11ˆ2 2*a_11 * a_22 + a_22 ˆ2+4* a_12 * a_21 ) ˆ ( 1 / 2 ) /2
⌥ ⌅
I Trag matrice A dobije se primjenom funkcije trace.
>> t r a c e ( A )
ans =
⌃ ⇧
a_11 + a_22
⌃ ⇧
cos ( x )
⌃ ⇧⌃ ⇧
Inf Inf
⌃ ⇧
k ˆ3/3 k ˆ2/2 + k /6
⌥ ⌅
>> symsum ( k ˆ 2 , 0 , 5 )
ans =
⌃ ⇧
55
⌥ ⌅
>> syms x
>> taylor ( exp ( x ) )
ans =
⌃ ⇧
x ˆ5/120 + x ˆ4/24 + x ˆ3/6 + x ˆ2/2 + x + 1
⌥ ⌅
>> taylor ( exp ( x ) , x , 1 , ' Order ' , 3 )
ans =
⌃ ⇧
exp ( 1 ) + exp ( 1 ) * ( x 1 ) + ( exp ( 1 ) * ( x 1 ) ˆ2) /2
⌥ ⌅
>> t8 = taylor ( f , ' Order ' , 8 )
t8 =
x ˆ6/5040+ xˆ4/120 x ˆ2/6+1 >> syms x
⌃ ⇧
>> t10 = taylor ( f , ' Order ' , 1 0 ) >> f = s i n ( x ) / x ;
t10 =
x ˆ8/362880 x ˆ6/5040+ x ˆ4/120 ...
⌃ ⇧
x ˆ2/6+1
⌥ ⌅
Razvoj u Taylorov red
>> ezplot ( t6 , [ 4 , 4 ] )
>> hold on 0.8
>> ezplot ( t8 , [ 4 , 4 ] )
>> ezplot ( t10 , [ 4 , 4 ] ) 0.6
>> ezplot ( f , [ 4 , 4 ] )
legend ( ' Aproks . s i n ( x ) / x s t6 ' , . . .
0.4
⌃ ⇧
0 Aproks. sin(x)/x s t8
t i t l e ( ' Razvoj u Taylorov red ' ) Aproks. sin(x)/x s t10
sin(x)/x
-0.2
-4 -3 -2 -1 0 1 2 3 4
x
3x2 + 6x 1
f (x ) =
x2 + x 3
Potrebno je odrediti i ucrtati asimptote, kritične točke i točke in eksije.
I Odredivanje asimptota
⌥ ⌅ (6 x + 3 x 2 - 1)/(x + x 2 - 3)
% kreiranje funkcije 8
syms x
num = 3* x ˆ2 + 6* x 1; 6
denom = x ˆ2 + x 3; 4
f = num / denom ;
⌃ ⇧
ezplot ( f ) ;
2
-2
-4
-6 -4 -2 0 2 4 6
x
⌃ ⇧
3
⌃ ⇧
1 3 ˆ ( 1 / 2 ) /2 1/2 >> limit ( f , x , sol ( 1 ) , ' r i g h t ' )
ans =
⌃ ⇧
Inf
⌥ ⌅
I Crtanje asimptota.
Horizontalne i verikalne asimtote
ezplot ( f )
hold on 8
% c r t a n j e h o r i z o n t a l n i h asimptota
p l o t ([ 2 * p i 2* p i ] , . . . 6
[3 3 ] , ' g ' )
% C r t a n j e v e r t i k a l n i h asimptota 4
p l o t ( double ( sol ( 1 ) ) * [1 1 ] , . . .
[ 5 10] , ' r ' ) 2
p l o t ( double ( sol ( 2 ) ) * [1 1 ] , . . .
[ 5 10] , ' r ' ) 0
t i t l e ( ' Horizontalne i . . .
v e r t i k a l n e asimptote ' )
-2
⌃ ⇧
hold off
-4
-6 -4 -2 0 2 4 6
x
⌥ ⌅
I Pronalaženje maksimuma i minimuma funkcije
Maksimum i minimum funkcije f
f1 = d i f f ( f ) ;
f1 = simplify ( f1 ) 8
f1 =
⌃ ⇧
(3* x ˆ2+16* x +17) / ( x ˆ2+ x 3)ˆ2
⌥ ⌅
6
1 3 ˆ ( 1 / 2 ) /3 8/3
⌃ ⇧
1 3 ˆ ( 1 / 2 ) /3 8/3
⌥ ⌅
0
-2
ezplot ( f ) , hold on
p l o t ( double ( crit_pts ) , . . . -4
⌃ ⇧
t e x t ( 2.5 ,2 , ' L o k a l n i maksimum ' )