1.1K views

Original Title: MAT275 Matlab4

Uploaded by nav4evr

- lab6
- Matlab Lab 1
- WW1 Vector Fields
- Ch 09
- Lecture 2
- 2014 2 PENANG SMJK Chung Ling BW MATHS QA
- Lab 2
- MAT 275 MATLAB Assignment Lab2.Docx (1)
- Lecture 2
- C4 Solomon G MS mark scheme
- Lab 5
- Two Mass Spring System
- phy lab
- Con 15-16 V -5
- ABSTRACT - (SHELL) Bending Analysis of Hyperbolic Paraboloid Shell - Articles - The Institution of Structural Engineers
- Technical Analysis of MTNL
- WI3150TUinhoud
- courses
- pmath_p1q02
- Advanced Topics in Inequalities - Franklyn Wang Et Al. - AoPS 2015

You are on page 1of 9

Question 1

Part a

function LAB04ex1

clc

t0 = 0; tf = 40; y0 = [-1;0]; %sets time initial and final and initial

conditions

[t,Y] = ode45(@f,[t0,tf],y0,[]);

[t,Y]

u1 = Y(:,1); u2 = Y(:,2); % y in output has 2 columns corresponding to u1 and

u2

figure(1); %sets first figure

plot(t,u1,'b.-',t,u2,'r.-'); %plots figures

grid on

ylim([-1.5,1.5]);

legend('y(t)','v(t)=y''(t)'); %puts up legend for first plot

figure(2)

plot(u1,u2,'black.-'); axis square; xlabel('y'); ylabel('v=y''');

axis([-1,1,-1.5,1.5]); %sets the axis limits

set(gca,'XTick',-1:.2:1)

%sets the ticks on the plot on the x axis

grid on

%puts the grid on

end

%---------------------------------------------------------------------function dYdt = f(t,Y) %defines the ODE

y=Y(1); v=Y(2);

%sets the vectors for each y and v

dYdt = [v; cos(t)-4*v-3*y];

%the IVP equation

end

1.5

y(t)

v(t)=y'(t)

1

0.5

-0.5

-1

-1.5

10

15

20

25

30

35

40

1.5

v=y'

0.5

-0.5

-1

-1.5

-1

0

y

0.2

0.4

0.6

0.8

%Part b

Y is a maximum when t=2.1340, 7.3562, 13.6632, 19.9324, 26.2151, 32.4983, 38.7814

2.0365 -0.0931 0.0448

2.1340 -0.0903 0.0125

2.2316 -0.0905 -0.0162

7.2771

7.3562

7.4353

7.5057

0.2210 0.0265

0.2224 0.0087

0.2224 -0.0091

0.2212 -0.0248

13.6632 0.2236 0.0023

13.7398 0.2231 -0.0148

19.9324 0.2235

20.0093 0.2233

26.1381 0.2225

26.2151 0.2235

26.2920 0.2233

32.4213 0.2225

32.4983 0.2235

32.5752 0.2233

38.7045 0.2225

38.7814 0.2235

38.8584 0.2233

0.0054

-0.0118

0.0227

0.0056

-0.0117

0.0227

0.0056

-0.0117

0.0227

0.0056

-0.0117

Part c

The long term behavior of y seems sinusoidal fluctuating from -.2 to .2235

Part d

1.5

y(t)

v(t)=y'(t)

1

0.5

-0.5

-1

-1.5

10

15

20

25

30

35

40

1.5

v=y'

0.5

-0.5

-1

-1.5

-1

0

y

0.2

0.4

0.6

0.8

Based on the graphs, the equation stabilizes at the same frequency and amplitude as it does with

the initial conditions of y(0)=0,v(0)=-1. Based on the picture of y vs y, we can see that y starts

positively while y starts negatively compared with the old initial conditions.

Question 2

Part a

function LAB04ex2

clc

t0 = 0; tf = 40; y0 = [-1;0];

[t,Y] = ode45(@f,[t0,tf],y0,[]);

[t,Y]

u1 = Y(:,1); u2 = Y(:,2); % y in output has 2 columns corresponding to u1 and

u2

figure(1);

plot(t,u1,'b.-',t,u2,'r.-');

grid on

ylim([-1.5,1.5]);

legend('y(t)','v(t)=y''(t)');

figure(2)

plot(u1,u2,'black.-'); axis square; xlabel('y'); ylabel('v=y''');

axis([-1,1,-1.5,1.5]);

set(gca,'XTick',-1:.2:1)

grid on

end

%---------------------------------------------------------------------function dYdt = f(t,Y)

y=Y(1); v=Y(2);

dYdt = [v; cos(t)-4*v*y^2-3*y];

end

1.5

y(t)

v(t)=y'(t)

1

0.5

-0.5

-1

-1.5

10

15

20

25

30

35

40

1.5

v=y'

0.5

-0.5

-1

-1.5

-1

-0.8

-0.6

-0.4

-0.2

0

y

0.2

0.4

0.6

0.8

Part b

In the short term, the solution of figs L4g become stable much more quickly, reaching the cyclic

solution. On the other hand, the solution of Figs L4h reach stability much more slowly. The

behavior of the equation is much more erratic and takes longer to reach steady state.

Part c

The long term behavior shows that the solution of L4.4 has an amplitude of .47 while the

solution of L4.5 has an amplitude of double that, .95 or so. Both, however, have the same period

for their oscillations.

Part d

function LAB04ex2d

clc

clear all

t0 = 0; tf = 40; y0 = [-1;0];

[t,Y] = ode45(@f,[t0,tf],y0,[]);

[t,Y]

u1 = Y(:,1); u2 = Y(:,2); % y in output has 2 columns corresponding to u1 and

u2

[te,Ye]=euler(@f,[0,40],y0,400);

%calls eulers method using the function

f, initial conditions and number of steps

u3=Ye(:,1); u4=Ye(:,2);

figure(1);

plot(t,u1,'black.-',te,u3,'r.-');

grid on

ylim([-1.5,1.5]);

legend('y(t)','euler');

grid on

end

%---------------------------------------------------------------------function dYdt = f(t,Y)

y=Y(1); v=Y(2);

dYdt = [v; cos(t)-4*v*y^2-3*y];

end

1.5

y(t)

euler

1

0.5

-0.5

-1

-1.5

10

15

20

25

30

35

40

The solutions are nearly identical. The ode45 solution is a little more accurate and approaches

the cyclic behavior a little faster than the euler solution.

Question 3

function LAB04ex3

clc

clear all

t0 = 0; tf = 40; y0 = [-1;0];

[t,Y] = ode45(@f,[t0,tf],y0,[]);

u1 = Y(:,1); u2 = Y(:,2); % y in output has 2 columns corresponding to u1 and

u2

[te,Ye]=euler(@f,[0,40],y0,400);

u3=Ye(:,1); u4=Ye(:,2);

figure(1);

plot(t,u1,'black.-',te,u3,'r.-');

grid on

ylim([-1.5,1.5]);

legend('y(t)','euler');

grid on

end

%---------------------------------------------------------------------function dYdt = f(t,Y)

y=Y(1); v=Y(2);

dYdt = [v; cos(t)-4*v*y-3*y];

end

When solving numerically for the solution of the IVP, the solution looks somewhat different to

that of L4.7. For one, the solution looks as if it deviates much more at the beginning than the

solution of L4.7. When trying to run the numerically solving of this IVP, MATLAB gave the

error message of Warning: Failure at t=3.774765e+000. Unable to meet integration tolerances

without reducing the step size below the smallest value allowed (7.105427e-015) at time t. As a

result, beyond the when t=3.77, the numerical solution of this ode could not be solved. Initial

behavior is known, but final behavior is not because of this.

Question 4

Part a

function LAB04ex4

clc

t0 = 0; tf = 40; y0 = [-1;0;4];

[t,Y] = ode45(@f,[t0,tf],y0,[]);

u1 = Y(:,1); u2 = Y(:,2); u3=Y(:,3); % y in output has 2 columns

corresponding to u1 and u2

figure(1);

plot(t,u1,'b.-',t,u2,'r.-',t,u3,'.-k');

grid on

ylim([-1.5,1.5]);

legend('y(t)','v(t)=y''(t)','w=y''''');

figure(2)

plot3(u1,u2,u3,'k.-'); axis square;

xlabel('y'); ylabel('v=y'''); zlabel('w=y''''');

axis([-1,1,-1.5,2,-4,4]);

grid on

view(-40,60);

end

%---------------------------------------------------------------------function dYdt = f(t,Y)

y=Y(1); v=Y(2); w=Y(3);

dYdt = [v;w; -sin(t)-4*y^2*w-8*y*v^2-3*v];

end

1.5

y(t)

v(t)=y'(t)

w=y''

0.5

-0.5

-1

-1.5

10

15

20

25

30

35

40

4

w=y''

2

0

-2

-4

2

1

0.5

0

v=y'

0

-0.5

-1

-1

Part b

At the beginning, it looks as if L4i is more erratic than L4h, but both quickly go to the same

oscillation in roughly the same time. The amplitude of the solution of each of them is nearly

identical as is the period. In addition, looking at the phase plots of each, it seems as if they are

nearly identical with the one from Fig L4i

Part c

2

d d2 y 4 y 2 dy

d3 y

dy 2 dy

2 d y

+

+3

y=cos

(

t

)

=

+

4

y

+

8

y

+3 =sint

dt d t 2

dt

dt

dt

dt3

dt2

( )

When differentiated, the ODE of L4.7 is the same as the ODE in L4.8. They are identical

equations.

Part d

The equation in L4.7 satisfies the initial condition of L4.8 because when you set t=0

d2 y

dy

+ 4 y +3 y=1 . When we take the initial conditions of L4.8

2

dt

dt

2

( 0 )=1, dy ( 0 )=0, d y2 ( 0 )=4

,

dt

dt

d2 y

d2 y

3=1=

=4 , which is exactly the same as the

dt2

dt2

- lab6Uploaded bytuananh2410
- Matlab Lab 1Uploaded byGarrett Knapp
- WW1 Vector FieldsUploaded byalex_palmieri_5
- Ch 09Uploaded bychaitanyachegg
- Lecture 2Uploaded byTebsu Tebsuko
- 2014 2 PENANG SMJK Chung Ling BW MATHS QAUploaded bySK
- Lab 2Uploaded byAJ Verbin
- MAT 275 MATLAB Assignment Lab2.Docx (1)Uploaded byPranay Goswami
- Lecture 2Uploaded byTopan Setiadipura
- C4 Solomon G MS mark schemeUploaded bySachitra Wijethunga
- Lab 5Uploaded bymhasanjafry
- Two Mass Spring SystemUploaded byAratz Hernandez
- phy labUploaded byReddyvari Venugopal
- Con 15-16 V -5Uploaded bynandhakumarme
- ABSTRACT - (SHELL) Bending Analysis of Hyperbolic Paraboloid Shell - Articles - The Institution of Structural EngineersUploaded byBalaji Nallaval Chinnaswamy
- Technical Analysis of MTNLUploaded byGaurav Kumar
- WI3150TUinhoudUploaded byhoilolol
- coursesUploaded byapi-280370699
- pmath_p1q02Uploaded byapi-19979554
- Advanced Topics in Inequalities - Franklyn Wang Et Al. - AoPS 2015Uploaded byPRATIK ROY
- Tutorial 01Uploaded byAndrew Ip
- 2.3. PICKSTONE. a Brief IntroductionUploaded byMiguel Ángel Amador
- my storyUploaded byAnonymous HQ8FCwI
- 6 PhD Viva PreparatnDr JamaludinUploaded byMohd Saiffuddeen Abd Aziz
- Intervensi Mathematics SPM KeynotesUploaded byLim Wai Wai Smktp
- TLaw10UUploaded bydogggg6269341
- PralkhaUploaded bySaiful Islam Tamim
- PChem > F2002-E2Uploaded byapi-3707297
- Lesson-2.GenMath.1stqrt.pptxUploaded byTerence Guiritan
- elizabeth thompson class averageUploaded byapi-403419937

- Bioelectricity Quiz - BME 111Uploaded bynav4evr
- HW6 SolutionUploaded bynav4evr
- BME Chapter 17Uploaded bynav4evr
- BME 111 quizUploaded bynav4evr
- sm ch7Uploaded bynav4evr
- Buddhism Terminology REL 100Uploaded bynav4evr
- Judaism Terminology REL 100Uploaded bynav4evr
- MEE-342-HW8Uploaded bynav4evr
- 7B49Dd01Uploaded bylotchan
- MAE 400 Syllabus Spring 2015Uploaded bynav4evr
- MUS 354 - Beatles After BeatlesUploaded bynav4evr
- EEE 120 Quiz1 SolutionUploaded bynav4evr
- 1st_211_HW_F12Uploaded bynav4evr
- Pneumatically Actuated PDMS FingersUploaded byAnonymous PufNjg
- 2nd_211_HW_F12Uploaded bynav4evr
- BME Chapter 16Uploaded bynav4evr
- ARS_300_exam3Uploaded bynav4evr

- Neural NetworkUploaded byJournalNX - a Multidisciplinary Peer Reviewed Journal
- Iso And Itil Best Practices In It Services And Quality ManagementUploaded byNorman Dicket
- Ugc Net Library and information science Solved Paper II j5910Uploaded byRaajkuumar Khatri
- f90introUploaded byElaine Camilo
- The Future of Comminution Modelling IJMP 2007Uploaded byMauricio Ignacio García Morales
- Amadeus BAsic Manual.pdfUploaded byHanningKeithCastelino
- PHARMADAVAO03-0910-2017.pdfUploaded byPhilBoardResults
- V3I2-0232.pdfUploaded bypaul
- FA3GuideUploaded bytobyopfer
- 01_Ch1 (Introduction) - NotesUploaded byAnhchàng Hạt Bí Trần
- ch03Uploaded byxcygon
- Customer Creation API Sample CodeUploaded byeanuradha
- AI Questions Unit 1Uploaded byN.Vivekananthamoorthy
- Atv71 Communication Parameters en v5.7 Ie67Uploaded byCarlosOtiniano
- MCAsyllabusUploaded bynareyugam
- Hack Whatsapp MsgsUploaded byKittupkl
- 62805039 Attendance Monitoring SystemUploaded byChristian Arada
- fireexpo-emails1Uploaded bysuccesskim
- Tuto3 (1)Uploaded byaravind
- RFPUploaded bybireshward
- SCADAUploaded byraghu_mn
- IncompatibleUploaded byMohd Faizan Ahmad
- EHP-QuickStartGuideUploaded byLiladhar Ganesh Dhoble
- srsUploaded bybonsla
- jourUploaded byroguelemental3384
- Dr Poster v2Uploaded byeagleni
- chap2 - [Finite Difference Method].pdfUploaded byCepa Ugol
- Reservation system componentsUploaded byd3lict
- Expert Forenex PDFUploaded byBob
- PiUploaded by71_arturo