0% found this document useful (0 votes)
28 views10 pages

Lab 6 Matlab

The document contains MATLAB code for numerical integration and solving differential equations. It includes: 1) Examples of numerical integration using quad() and dblquad() functions. 2) Code for solving ordinary differential equations (ODEs) using ode45() to model free and forced oscillations with and without damping. 3) Derivations of equations for oscillation amplitude and frequency based on the system parameters.

Uploaded by

Viorel Mirzenco
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)
28 views10 pages

Lab 6 Matlab

The document contains MATLAB code for numerical integration and solving differential equations. It includes: 1) Examples of numerical integration using quad() and dblquad() functions. 2) Code for solving ordinary differential equations (ODEs) using ode45() to model free and forced oscillations with and without damping. 3) Derivations of equations for oscillation amplitude and frequency based on the system parameters.

Uploaded by

Viorel Mirzenco
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

1a

>> quad('(x.^(3/4).*(x.^(2/3)+2))',0,3)

ans =

13.7015

1b

>> quad('((y.^(2/5))./(y.^3+3))',0.2,3)

ans =

0.4572

2filefunctia
function f=integr1(x,y);
f=(x.^(3/2).*y.^(7/3)+log(x.*y).*sin(x));
programul

>> f=dblquad(@integr1,0.3,1,1,2)

f=

1.0325

4a
failfunctia
function dxdt=difer1(t,x);
dxdt=zeros(2,1); % a column vector
dxdt(1)=x(2);
w0=5;
dxdt(2)=-w0.^2.*x(1);

program

>> [t,x]=ode45(@difer1,[0 10],[-5;0]);

>> plot(t,x(:,1),'-');
>> title('Oscilatii libere in lipsa rezistentei mediului')

Oscilatii libere in lipsa rezistentei mediului


5

-1

-2

-3

-4

-5
0 1 2 3 4 5 6 7 8 9 10

>> x0=10;
>> v0=15;
>> w0=5;
>> A=sqrt(x0.^2+(v0.^2)./(w0.^2))

A=

10.4403

>> eps=atan(w0.*x0)/v0

eps =

0.1034

>> T=2.*pi/w0

T=

1.2566

>> f=1/T

f=
0.7958

4b

H<w0

failfunctia
function dxdt=difer2(t,x);
dxdt=zeros(2,1); % a column vector
dxdt(1)=x(2);
w0=5;
h=0.3;
dxdt(2)=-w0.^2.*x(1)-2.*h.*x(2);
programul
>> [t,x]=ode45(@difer2,[0 10],[-5;0]);
>> plot(t,x(:,1),'-');
>> title('Oscilatii libere in prezenta rezistentei mediului, h<w0')
Oscilatii libere in prezenta rezistentei mediului, h<w0
5

-1

-2

-3

-4

-5
0 1 2 3 4 5 6 7 8 9 10

H=w0
Failfunctia
function dxdt=difer2(t,x);
dxdt=zeros(2,1); % a column vector
dxdt(1)=x(2);
w0=5;
h=5;
dxdt(2)=-w0.^2.*x(1)-2.*h.*x(2);
programul
>> [t,x]=ode45(@difer2,[0 10],[-5;0]);
>> plot(t,x(:,1),'-');
>> title('Oscilatii libere in prezenta rezistentei mediului, h=w0')

Oscilatii libere in prezenta rezistentei mediului, h=w0


1

-1

-2

-3

-4

-5
0 1 2 3 4 5 6 7 8 9 10

h>w0
failfunctia
function dxdt=difer2(t,x);
dxdt=zeros(2,1); % a column vector
dxdt(1)=x(2);
w0=5;
h=9;
dxdt(2)=-w0.^2.*x(1)-2.*h.*x(2);
program
>> [t,x]=ode45(@difer2,[0 10],[-5;0]);
>> plot(t,x(:,1),'-');
>> title('Oscilatii libere in prezenta rezistentei mediului, h>w0')
Oscilatii libere in prezenta rezistentei mediului, h>w0
0

-0.5

-1

-1.5

-2

-2.5

-3

-3.5

-4

-4.5

-5
0 1 2 3 4 5 6 7 8 9 10

>> x0=10;
>> v0=15;
>> w0=5;
>> h=0.3;
>> w=sqrt(w0.^2-h.^2)

w=

4.9910

>> A=sqrt(x0.^2+((v0+h.*x0).^2)./w.^2)

A=

10.6305

>> eps=atan((w.*x0)./(v0+h.*x0))

eps =

1.2247

>> T=(2.*pi)/w

T=

1.2589
>> f=1/T

f=

0.7943

>> n=exp(-h.*T)

n=

0.6855

>> D=h.*T

D=

0.3777

4c caz general

Failfunctia
function dxdt=difer3(t,x);
dxdt=zeros(2,1); % a column vector
dxdt(1)=x(2);
w0=5;
H0=8;
p=3;
dxdt(2)=-w0.^2.*x(1)+H0.*sin(p.*t);
programul

>> [t,x]=ode45(@difer3,[0 10],[-5;0]);


>> plot(t,x(:,1),'-');
>> title('Oscilatii fortate in lipsa rezistentei mediului, caz general')
Oscilatii fortate in lipsa rezistentei mediului, caz general
6

-2

-4

-6
0 1 2 3 4 5 6 7 8 9 10

Oscilatie bataie
Failfunctia
function dxdt=difer3(t,x);
dxdt=zeros(2,1); % a column vector
dxdt(1)=x(2);
w0=5;
H0=8;
p=5.03;
dxdt(2)=-w0.^2.*x(1)+H0.*sin(p.*t);
program
>> [t,x]=ode45(@difer3,[0 300],[-5;0]);
>> plot(t,x(:,1),'-');
>> title('Oscilatii fortate in lipsa rezistentei mediului, oscilatii-bataie')
Oscilatii fortate in lipsa rezistentei mediului, oscilatii-bataie
60

40

20

-20

-40

-60
0 50 100 150 200 250 300

Oscilatia bataie
Fail functia
function dxdt=difer3(t,x);
dxdt=zeros(2,1); % a column vector
dxdt(1)=x(2);
w0=5;
H0=8;
p=5;
dxdt(2)=-w0.^2.*x(1)+H0.*sin(p.*t);
program
>> [t,x]=ode45(@difer3,[0 10],[-5;0]);
>> plot(t,x(:,1),'-');
>> title('Oscilatii fortate in lipsa rezistentei mediului, rezonanta')
Oscilatii fortate in lipsa rezistentei mediului, rezonanta
15

10

-5

-10

-15
0 1 2 3 4 5 6 7 8 9 10

>> p=3;
>> H0=8;
>> w0=5;
>> A=H0/(abs(w0.^2-p.^2))

A=

0.5000

4d
failfunctia
function dxdt=difer4(t,x);
dxdt=zeros(2,1); % a column vector
dxdt(1)=x(2);
w0=5;
h=9;
H0=8;
p=3;
dxdt(2)=-w0.^2.*x(1)-2.*h.*x(2)+H0.*sin(p.*t);
program
>> [t,x]=ode45(@difer4,[0 10],[-5;0]);
>> plot(t,x(:,1),'-');
>> title('Oscilatii fortate in prezenta rezistentei mediului')
Oscilatii fortate in prezenta rezistentei mediului
1

-1

-2

-3

-4

-5
0 1 2 3 4 5 6 7 8 9 10

>> w0=5;
>> H0=8;
>> p=3;
>> h=9;
>> A=H0./(sqrt((w0.^2-p.^2).^2+4.*h.^2.*p.^2))

A =

0.1420

>> g=(2.*h.*p)./(w0.^2+p.^2)

g =

1.5882

You might also like