In: Advanced Math
Euler’s Method and Introduction to MATLAB
>> 2+2
If you want to suppress the output of a command follow it with ‘;”. For example >>2+2;
Practice evaluating a few expressions in the command window. (In MATLAB multiplication is represented by * so 3*2=6).
Variables can be vectors. For example >>x=[1 2 3] creates a row vector with three components: x(1)=1, x(2)=2, and x(3)=3. Try it. What happens when you set x=[1;2;3]?
Now that you have created the function g(x,y) you can evaluate it at different x and y values. For example, to compute g(1,2), just type: >>g(1,2) and hit enter. Also compute g(2,2). Why is g(1,2)=g(2,2)?
When you open the file euler_method.m you will see that the lines of the function are numbered along the left hand side of the window. Look at the first line:
function [x,y] = euler_method(f,h,x0,y0,xn).
This line creates a function called euler_method in MATLAB.
The variables in square brackets are the outputs of the function. These variables are returned to the command window after the function is called. This function returns variables called x and y. The variables in round brackets are the inputs of the function. This function has five inputs. What are they?
The % symbol is used to comment out text. This means that whatever appears after a % sign is not executed as part of the code. Explanations are placed after a % symbol. Read the comments that describe how the function euler_method.m works.
Note: MATLAB updates the value of the index i with each iteration of the loop, so the command i=i+1 need not appear inside the loop.
In the command window type [x,y]=euler_method(g,h,0,1,1) to solve the initial value problem, dy/dx=g(x,y); y(0)=1, for h=.25, .125, .0625, and .03125. Each time you run euler_method, a plot showing the approximate solution as a function of x will be produced. Edit these plots to include axes labels and titles, and insert them here.
To Draw the Phase line, you have to plot the values of in the x-axis and those of in y-axis. Since this is a qualitative analysis, you can copy the plot from MATLAB and draw it by hand.
Now, the places where
make an arrow in the x-axis pointing towards the positive
direction.
And, the places where
make an arrow in the x-axis pointing towards the negative
direction
The places where
, make a circle. These are the stationary points of the
Differential Equation
If there is a stationary point on your phase line which has arrows from both sides going into it, then it is a stable fixed point and at the value of will stabilize at that value, otherwise the stationary point is unstable and the value of will go to either depending on the direction of the arrows and the initial condition.