










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to the basics of matlab, including variable assignment, basic arithmetic operations, and matrix and vector manipulations. It covers topics such as element-wise operations, built-in functions, and special matrices. Examples are given to illustrate the concepts.
Typology: Exercises
1 / 18
This page cannot be seen from the preview
Don't miss anything!











3*4/2+3 % karışık bir işlem ans = 9 sqrt(9) % kare kök ans = 3 pi % pi sayısı MATLAB'da iç değişken olarak tanımlı ans =
exp(1) % e sayısı ans =
exp(3) % e^ ans =
x= % x değişkenine 10 değerini ver x = 10 x=8; % bir komutun sonuna noktalı virgül konursa komut çalışır ama sonucu ekranda görünmez x- 4 ans = 4 ans+ ans = 5 y=x^2 % x'in karesi y = 64 a=4; b=5; c=6;
vector = [1 5 - 3] % bir satır vektörü vector = [1, 5 ,-3] % aynı satır vektörü vector = 1 5 - 3 x=0 : 2 : 10 % 0’dan başlayarak 2’şer artarak 10’a kadar x=linspace(1,10,6) x = 0 2 4 6 8 10 vector2 = [2; 1; 6] % bir sütun vektörü vector2 = 2 1 6 vector(2) % 2. elemanı seçme ans = 5
matrix=[1 2 3 ; 4 5 6 ; 7 8 9] % 3 x 3 bir matris matrix = 1 2 3 4 5 6 7 8 9 matrix 1 =[matrix; 10 11 12] % matrisin altına satır ekle matrix1 = 1 2 3 4 5 6 7 8 9 10 11 12 matrix2=[matrix ,[10; 11; 12]] % matrisin yanına s ütun ekle matrix2 = 1 2 3 10 4 5 6 11 7 8 9 12
A = [1 2 3;5 5 7] % 2x3 matris A = 1 2 3 5 5 7 C = [-1 0 1; - 1 0 2] % 2x3 matris C =
M = A+C % Matris toplama M = 0 2 4 4 5 9
% 3x3 matris B = 1 2 - 1 3 5 2
M = B^-1 % Matris tersi M = 0.6250 0.8750 1.
M = B^ M = 9 17 4 14 21 5
M = B*B M = 9 17 4 14 21 5
Örneğin: M = BA % Boyutlar uymuyor* M = A+B % Boyutlar uymuyor M = A^3 % A kare matris değil, kuvveti alınamaz M = C^- 1 % C kare matris değil, tersi alınamazM = A' % Matrisin transpozesi (devriği) M = 1 5 2 5 3 7 Not: Matris işlemi tanımlı değilse
a=4; b=5; c=6; ### Vektör-Matris İşlemleri >> vector = [1 5 - 3] % bir satır vektörü >> vector = [1, 5 ,-3] % aynı satır vektörü vector = 1 5 - 3 >> x=0 : 2 : 10 % 0’dan başlayarak 2’şer artarak 10’a kadar >> x=linspace(1,10,6) x = 0 2 4 6 8 10 >> vector2 = [2; 1; 6] % bir sütun vektörü vector2 = 2 1 6 >> vector(2) % 2. elemanı seçme ans = 5 >>matrix=[1 2 3 ; 4 5 6 ; 7 8 9] % 3 x 3 bir matris matrix = 1 2 3 4 5 6 7 8 9 >>matrix 1 =[matrix; 10 11 12] % matrisin altına satır ekle matrix1 = 1 2 3 4 5 6 7 8 9 10 11 12 >> matrix2=[matrix ,[10; 11; 12]] % matrisin yanına s ütun ekle matrix2 = 1 2 3 10 4 5 6 11 7 8 9 12 ### Matrisler için dört işlem, üst alma, eksponansiyel ### vb. işlemler >>A = [1 2 3;5 5 7] % 2x3 matris A = 1 2 3 5 5 7 >>C = [-1 0 1; - 1 0 2] % 2x3 matris C = - 1 0 1 - 1 0 2 >>M = A+C % Matris toplama M = 0 2 4 4 5 9 ###### >>B = [1 2 - 1; 3 5 2; - 2 - 5 - 1] % 3x3 matris B = 1 2 - 1 3 5 2 - 2 - 5 - 1 >>M=AB % Matris çarpımı* M = 1 - 3 0 6 0 - 2 >>M = B^-1 % Matris tersi M = 0.6250 0.8750 1. - 0.1250 - 0.3750 - 0. - 0.6250 0.1250 - 0. >>M = B^ M = 9 17 4 14 21 5 - 15 - 24 - 7 >>M = B*B M = 9 17 4 14 21 5 - 15 - 24 - 7 >>M = A' % Matrisin transpozesi (devriği) M = 1 5 2 5 3 7 Not: Matris işlemi tanımlı değilse MATLAB hata verir.
B=repmat(A,2,2) % A matrisini blok olarak 2'ye 2 defa tekrarla
B = 1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 1 1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 1
% ( satır , sütun) C= 0 1 0 0 0 1 1 0 0
a=[-1 5 0 - 2] ; b=[0 7 - 9 3] ; min (a) % Vektörün minimumu ans =
max (a) % Vektörün maksimumu ans = 5 length(a) % Vektrönü uzunluğu ans = 4 mean (a) % Vektörün ortalama değeri ans = 0. >>min(a,b) % a ve b'yi eleman eleman karşılaştır, minimum değerleri seç ans = - 1 5 - 9 - 2 >> a(end) = [] % a'nın son elemanını sil a = - 1 5 0 >>sort (a) % Vektörü sıralama ans = - 2 - 1 0 5
A=zeros(3) % 3x3 sıfırlardan oluşan matris
A = 0 0 0 0 0 0 0 0 0
A=ones(4) % 4x4 birlerden oluşan matris A = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 A=eye(3) % 3x3 birim matris A = 1 0 0 0 1 0 0 0 1 MATLAB'da birim matris, sıfır matris vb. özel matrisler yaratmak için bazı özel komutlar vardır.