0% found this document useful (0 votes)
9 views23 pages

TP 1

The document is a MATLAB session log that demonstrates various operations such as variable assignment, matrix manipulation, and function usage. It includes commands for saving and loading workspace variables, performing matrix calculations, and plotting functions. Additionally, it showcases the creation of transfer functions and state-space models.

Uploaded by

yahyadouissa490
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views23 pages

TP 1

The document is a MATLAB session log that demonstrates various operations such as variable assignment, matrix manipulation, and function usage. It includes commands for saving and loading workspace variables, performing matrix calculations, and plotting functions. Additionally, it showcases the creation of transfer functions and state-space models.

Uploaded by

yahyadouissa490
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

>> a

Undefined function or variable 'a'.

>> a=2

a=

>> a=2;

>> a=3

a=

>> help save

save - Save workspace variables to file

This MATLAB function saves all variables from the current workspace in a MATLAB

formatted binary file (MAT-file) called filename.

save(filename)

save(filename,variables)

save(filename,variables,fmt)

save(filename,variables,version)
save(filename,variables,'-append')

save filename

Reference page for save

See also clear, hgsave, load, matfile, regexp, saveas, whos

Other uses of save

daq/save, ecoder/save, imaq/save, instrument/save, mbc/Save, opc/save,

slvnv/rmidata.save, simulink/Simulink.Bus.save,

simulink/Simulink.sdi.save

>> save

Error using save

Unable to write file matlab.mat: permission denied.

>> a.mat

Attempt to reference field of non-structure array.

>> save

Error using save

Unable to write file matlab.mat: permission denied.

>> save(a)

Error using save

Argument must contain a string.


>> save

Saving to: D:\asma ilhem borji\matlab.mat

>> save a

>> load('a.mat')

>> clear all

>> a

Undefined function or variable 'a'.

>> load a.mat

>> clear all

>> load a.mat

>> who

Your variables are:

>> what

MAT-files in the current folder D:\asma ilhem borji

a matlab

>> who
Your variables are:

>> clear all

>> A=[1 2 3;4 5 6;7 8 9]

A=

1 2 3

4 5 6

7 8 9

>> size(A)

ans =

3 3

>> A'

ans =

1 4 7

2 5 8

3 6 9
>> A(3,2)

ans =

>> A(:,3)

ans =

>> A(1,:)

ans =

1 2 3

>> inv(A)

Warning: Matrix is close to singular or badly scaled. Results

may be inaccurate. RCOND = 1.541976e-18.


ans =

1.0e+16 *

-0.4504 0.9007 -0.4504

0.9007 -1.8014 0.9007

-0.4504 0.9007 -0.4504

>> det(A)

ans =

6.6613e-16

>> trace(A)

ans =

15

>> eye(4)

ans =

1 0 0 0

0 1 0 0
0 0 1 0

0 0 0 1

>> diag(2)

ans =

>> diag([1,2,3])

ans =

1 0 0

0 2 0

0 0 3

>> [V,D]=eig(A)

V=

-0.2320 -0.7858 0.4082

-0.5253 -0.0868 -0.8165

-0.8187 0.6123 0.4082

D=
16.1168 0 0

0 -1.1168 0

0 0 -0.0000

>> randn(2,4)

ans =

0.5377 -2.2588 0.3188 -0.4336

1.8339 0.8622 -1.3077 0.3426

>> vligne=[27,31,40]

vligne =

27 31 40

>> Vcol=[36;88;95]

Vcol =

36

88

95

>> zeros(1,3)
ans =

0 0 0

>> ones(5,2)

ans =

1 1

1 1

1 1

1 1

1 1

>> B=[3 2 5;1 8 4;2 7 3]

B=

3 2 5

1 8 4

2 7 3

>> C=[0 2 9;4 6 1;3 8 5]

C=

0 2 9
4 6 1

3 8 5

>> V=[1;2;3]

V=

>> W=[0;5;2]

W=

>> B*C

ans =

23 58 54

44 82 37

37 70 40
>> B.*C

ans =

0 4 45

4 48 4

6 56 15

>> V.*W

ans =

10

>> F=[B W;1 2 3 4]

F=

3 2 5 0

1 8 4 5

2 7 3 2

1 2 3 4

>> F(2,2)

ans =
8

>> F(:,3)

ans =

>> F(4,:)

ans =

1 2 3 4

>> F(2,[3 4])

ans =

4 5

>> F([3 2 4],[1 3 2])

ans =
2 3 7

1 4 8

1 3 2

p=[3 -5 2]

p=

3 -5 2

>> polyval(p,5)

ans =

52

>> x=[-1:0.1:2]

x=

Columns 1 through 6

-1.0000 -0.9000 -0.8000 -0.7000 -0.6000 -0.5000

Columns 7 through 12
-0.4000 -0.3000 -0.2000 -0.1000 0 0.1000

Columns 13 through 18

0.2000 0.3000 0.4000 0.5000 0.6000 0.7000

Columns 19 through 24

0.8000 0.9000 1.0000 1.1000 1.2000 1.3000

Columns 25 through 30

1.4000 1.5000 1.6000 1.7000 1.8000 1.9000

Column 31

2.0000

>> y=polyval(p,x)

y=

Columns 1 through 6

10.0000 8.9300 7.9200 6.9700 6.0800 5.2500

Columns 7 through 12
4.4800 3.7700 3.1200 2.5300 2.0000 1.5300

Columns 13 through 18

1.1200 0.7700 0.4800 0.2500 0.0800 -0.0300

Columns 19 through 24

-0.0800 -0.0700 0 0.1300 0.3200 0.5700

Columns 25 through 30

0.8800 1.2500 1.6800 2.1700 2.7200 3.3300

Column 31

4.0000

>> racines=roots(p)

racines =

1.0000

0.6667

>> p3=poly([1 -1])


p3 =

1 0 -1

>> conv(p,p3)

ans =

3 -5 -1 5 -2

>> x1=[1 2 3 4]

x1 =

1 2 3 4

>> y1=[1 -1 2 0]

y1 =

1 -1 2 0

>> p4=polyfit(x1,y1,3)

p4 =
-1.6667 12.5000 -27.8333 18.0000

>> z=5*exp(-0.4*x1).*sin(7.5*y1)

z=

3.1438 -2.1074 0.9793 0

x=-2+5i

x=

-2.0000 + 5.0000i

>> a=real(x)

a=

-2

>> b=imag(x)

b=

>> m=abs(x)
m=

5.3852

>> c=conj(x)

c=

-2.0000 - 5.0000i

>> d=angle(x)

d=

1.9513

>> e=sqrt(2)

e=

1.4142

>> f=sign(-5)

f=

-1
>> x=0:0.02:5;

>> y=sin(x.^2);

>> z=cos(x.^2);

>> plot(x,y,'b',x,z,'r');grid;

>> xlabel ('x');

>> ylabel('y et z');

>> title('courbes y=sin(x.^2) et z=cos(x.^2)');

>> legend('y','z');

>>

>> plot(x,y,'b',x,z,'r');grid;

>> xlabel ('x');

>> ylabel('y et z');

>> title('courbes y=sin(x.^2) et z=cos(x.^2)');

>> legend('y','z');

courbes y=sin(x. 2 ) et z=cos(x. 2 )


1

0.8

0.6

0.4

0.2
y et z

-0.2
y
-0.4 z

-0.6

-0.8

-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
x
>> subplot(2,4,3)

>> plot(x,y)

>>

-1
0 5

g=tf([1 1],[1 2 1])

g=

s+1

-------------

s^2 + 2 s + 1

Continuous-time transfer function.

>> h=zpk([],[-1 -2],-10)

h=

-10
-----------

(s+1) (s+2)

Continuous-time zero/pole/gain model.

>> a=[0,1;-4,-4]

a=

0 1

-4 -4

>> b=[0;2]

b=

>> c=[1,0];

>> d=0

d=

>> fs=ss(a,b,c,d)
fs =

a=

x1 x2

x1 0 1

x2 -4 -4

b=

u1

x1 0

x2 2

c=

x1 x2

y1 1 0

d=

u1

y1 0

Continuous-time state-space model.

>> zpk(g)

ans =
(s+1)

-------

(s+1)^2

Continuous-time zero/pole/gain model.

>> tf(h)

ans =

-10

-------------

s^2 + 3 s + 2

You might also like