Script M-Files - Modern Differential Equations - Lecture Notes | MAT 275, Study notes of Differential Equations

Material Type: Notes; Professor: Vaz; Class: Modern Differential Equations; Subject: Mathematics; University: Arizona State University - Tempe; Term: Unknown 1989;

Typology: Study notes

Pre 2010

Uploaded on 09/02/2009

koofers-user-gpw
koofers-user-gpw 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Script M-Files
Generally, MATLAB requires the use of several commands to produce a complicated
graphic. Improving these graphics need repeated use of a large number of commands. To
get around this, we enter the commands into a text file (called M-files), and execute them
with one command. M-files used to create complicated graphics are called script M-files.
Example: Plot the solutions to the differential equation 2+=
xy with initial conditions
2,1,0,1,2)0( =yover the interval 22 x
The general solution to the differential equation is Cx
x
xy ++= 2
2
)( 2. The initial
condition Cy =)0( . We create a script file as follows:
1. From the menu, choose File New M-file
2. The MATLAB editor will open as a blank page.
3. Enter the following commands
)'2)0(','1)0(','0)0(','1)0(','2)0(('
).'2/to('
)'('
)'('
)'',2
2
2
)'',2
2
1
)'',2
2
0
)'',2
2
1
)'',2
2
2
2:.01:2-
2
2
2
2
2
=====
+=
++=
++=
−−++=
++=
++=
=
yyyyylegend
xdxdySolutionstitle
yylabel
txlabel
ongrid
Cx
x
; plot(x,C
Cx
x
; plot(x,C
Cx
x
; plot(x,C
Cx
x
; plot(x,-C
onhold
Cx
x
; plot(x,-C
;x
:
.
.
Save as mfilenamein Current Directory
Execute by typing filename in Command Window and enter
AcroPDF - A Quality PDF Writer and PDF Converter to create PDF files. To remove the line, buy a license.

Partial preview of the text

Download Script M-Files - Modern Differential Equations - Lecture Notes | MAT 275 and more Study notes Differential Equations in PDF only on Docsity!

Script M-Files

Generally, MATLAB requires the use of several commands to produce a complicated

graphic. Improving these graphics need repeated use of a large number of commands. To

get around this, we enter the commands into a text file (called M-files ), and execute them

with one command. M-files used to create complicated graphics are called script M-files.

Example : Plot the solutions to the differential equation y ′=^ x + 2 with initial conditions

y ( 0 )=− 2 ,− 1 , 0 , 1 , 2 over the interval^ − 2 ≤ x ≤ 2

The general solution to the differential equation is x C

x y x = + 2 + 2

2

. The initial

condition y ( 0 )= C. We create a script file as follows:

  1. From the menu, choose FileNewM-file
  2. The MATLAB editor will open as a blank page.
  3. Enter the following commands

(' to / 2 .')

2

2

2

2

2

legend y y y y y

title Solutions dy dx x

ylabel y

xlabel t

gridon

x C

x C ; plot(x,

x C

x C ; plot(x,

x C

x C ; plot(x,

x C

x C -; plot(x,

hold on

x C

x C -; plot(x,

x ;

  • Save as filenamem in Current Directory
  • Execute by typing filename in Command Window and enter

AcroPDF - A Quality PDF Writer and PDF Converter to create PDF files. To remove the line, buy a license.