Block 6

May 13, 2009

After a semester full of discovering new ways to solve differential equations, we have now come to the end. In block 6 we will cover the last method this semester of solving differential equations. We will be taking a look at the laplase transform to linear diff. eq. This method uses a transformation to change the domain of the differential equations.  To transform and then convert the problems back and forth a list of identities can be used. Another way is to simply solve the problems using matlab or mathematica.

In this block I will be choosing 6 examples  in which will be completed. 2 first-order equations, 2 second-order equations, and 2 linear systems will be chosen in order to show the use and function of these laplase transforms

laplasesolver.m:

function [x] = laplasesolver (f,y_final,y_mult)
syms s t
laplace(f,t,s);
b=1/(s+(y_mult))
x=ans+(y_final);
figure
ezplot(x,[-20,20])
final=x*(b)
ilaplace(final,s,t);
a=ans;
figure
ezplot(a,[10,15])
end

 

  FIRST ORDER EQUATION EXAMPLES

1.   $\latex \frac{dy}{dt}+y=3cos(t)$ ,y(0)=-1

>> laplasesolver(3*cos(t),-1,1)

b =
1/(s + 1)

final =
((3*s)/(s^2 + 1) – 1)/(s + 1)

ans =
(3*cos(t))/2 – 5/(2*exp(t)) + (3*sin(t))/2

 

Using ilaplace to transform the function to the time domanin

$\latex y(t)=7cos(4*t)$ 

612

2.  $\latex\frac{dy}{dx}-y=e^(3t), y(0)=2 $

entering this into the m file produces:

b =
1/(s – 1)

final =
(1/(s – 3) + 2)/(s – 1)

ans =
exp(3*t)/2 + (3*exp(t))/2

 

solution graph:

 622

SECOND ORDER EQUATION EXAMPLES:

1. $\latex \frac{d^2y}{dt^2}+16y=0$ , y(0)=7, y’(0)=0

$\latex L{\frac{d^2y}{dt^2}}=s^2L{y(s)}-7s$

$\latex s^2L{y(s)}-7s+16L{y(s)}=0$

$\latex (s^2+4)L{y(s)}=7s$

$\latex L{y(s)}=\frac{7s}{(s^2+16)}$

 

 

Using ilaplace to transform the function yeilds the solution:

 

$\latex y(t)=7cos(4*t)$

SOLUTION GRAPH:

632

2. $\latex \frac{d^2y}{dt^2}+4y=0$ , y(0)=2 , y’(0)=3

$\latex L{\frac{d^2y}{dt^2}}=s^2L{y(s)}-2s-3$

$\latex s^2L{y(s)}-2s-3+4L{y(s)}=0$

$\latex (s^2+4)L{y(s)}=2s+3$

$\latex L{y(s)}=\frac{2s+3}{(s^2+4)}$

 

 

the simplified laplace transform yeilds the final solution:

 

$\latex y(t)=2cos(2*t)+ \frac{3}{2}sin(2*t)$

SOLUTION GRAPH:

642


Block 5

May 1, 2009

In Block 5, I will be looking at systems of Differential Equations.  Systems of Differential Equations are linked by multiple variables as opposed to just one like in previous blocks. In order to study and solve complicated systems we need to use more than one dependent variable as well as multiple equations.

Problem 1: T(x,y)=(x+y,x)

We can seperate this equation in two:

dx/dt=x+Y

dx/dt=x

The first thing we  need to do is set (x+y,x)=(λx,λy)

This simplifies into two separate equations of

x+y = λx                         x = λy

In order to solve for the value/s of λ I set the two equations equal to zero

(1-λ)x+y=0

xλy=0

The next step we used the equation ad-bc=o solve for λ where

a=(1-λ), b=1, c=1 and d=-λ

These values are found by setting the two equations equal to ax+by=0 and cx+dy = 0.

For this example  we will use the values λ=+.6103 and λ=-.6103

Finally, plug the final λ value into one of the original equations of

(1-λ)x+y=0

x-λy=0

then we  solve for y to get thesolutions for the equation as follows;

     y=0.618034x and         y=-1.618034x

Here is the code that I wrote to graph the solutions along with the vector field:

[x,y]=meshgrid(-1:1/10:1,-1:1/10:1);
>> u=2*x+y;
>> v=x+y;
>> w=sqrt(u.^2+v.^2);
>> quiver(x,y,u./w,v./w,.5,’.’)
>> hold on
>> f=@(x).618034*x;
>> fplot(f,[-1,1],’r’)
>> hold on
>> f=@(x)-1.61803*x;
>> fplot(f,[-1,1],’g’)
>> hold off
>> hold off

51

Example 2: 

dx/dt=x+3y

dy/dt=y

λ-1

Solution: Red: y=0

52

Example 3:

dx/dt=2x+5y

dy/dt=x-2y

λ=-0.23606 and λ=4.23607

Soutions:

Red: y= -1         Green: y=0.2

53

Example 4:

dx/dt=-4x-3y

dy/dt=-2x+4y

λ=√22

Solution: Red: y= -2.8968x

54

Example 5:

dx/dt=2x+2y

dy/dt=2x+y

λ=-0.56155 and λ=3.5616

Solutions:

Green: y= -1.2807x                Red: y= 0.7807x

55

Example 6:

dx/dt=2x-2y

dy/dt=2x+y

λ=(3+√-15)/4 and λ=(3-√-15)/4
56

Solution: non – real


Block 4

April 12, 2009

In this block, I will be choosing a total of six examples from the text, page 76. In these examples, I will carry out the intergrations using the varables seperable method, and comparing my solutions to those given by Mathematicas dsolve method.

1:  4xydx+(x^2+1)dy=0

The first step is to subtract (x^2+1)dy from both sides.

 W get, 4xydx=-(x^2+1)dy.

Next  I divided both sides by y and -(x^2+1),

this yields (4xydx)/-(x^2+1))=dy/y.

After this, I integrated both sides(4xdx)/(-(x^2+1)=∫dy/y.

Using the U-Substitution method we get -2ln|(x^2+1)| = ln |y| +C.

 I then rewrite the functions in terms of y by raising both sides to the exponent of e, the ln functions disappear 

y=e^-2ln(x^2+1)+C

 

 

Simplifying it even further I get y=(1/x^2+1)^2+C=(1/(x^2+1)^2)+C

 

Now, we can compare our solution to that given by Mathematica using dsolve,

>> dsolve(’Dy = -(4*x*y)/(x^2 + 1)’,’x’)

ans =

C6/(x^2 + 1)^2

 

2:  4xydx + (x^2 + 1)dy = 0

 

Solving by hand:

4xydx = -(x^2 + 1) dy

4x / -(x^2+1) dx =1/y dy

4x / -(x^2+1) dx = ∫1/y dy

4x – 4ln(x+1) + C = ln(y) 

Solving With dsolve:

dsolve(’dy=’4*x*y/(x+1),’x’)

ans =
 
4*x*y-4*y*log(x+1)+C1

 

3:  y ‘ = 10^x + y

Solved by hand:

dy/dx =  (x+y)ln(10)

dy/dx = xln(10) + yln(10)

-ln(10) ∫ ydy = ln(10)∫xdx

-ln(10)/2 * y^2 = ln(10)/2 * x^2 + C

Solved by dsolve:

dsolve(’dy= 10^(x+y)’,’x’)

ans =
 
C1+1/log(10)*10^(x+y)

 

4: tan(x)dy+2ydx=0

Solve by Hand:

tan(x)dy=-2ydx .

dy/-2t=dx/tan(x).

ln|y|=-2ln|sin(x)|

|y|=C/sin^2(x) 

Solve by dsolve: 

>> dsolve(’Dy/y = -2*cot(x)’,’x’)

ans =

C12/sin(x)^2

 

5:  x  dx/dy  + t = 1 

Solved by hand:

xdx = 1- tdt

∫ xdx = ∫ 1 – tdt

x^2/2 = t – t^2/2 + C

x^2 = 2t – t^2 + C

Solved by dsolve:
dsolve(’dy=(1-t)/x’,’t’)

ans =
 
1/2*(-t^2+2*t+2*C1*x)/x

 

6: y’ = exp(x^2)

Solved by hand:

∫dy = ∫ e^ (x^2) dx

xe^(x^2) – 2x + C

Solved by dsolve:

dsolve(’dy=exp(x^2)’,’x’)

ans =
 
log(x^2)*x-2*x+C1


THIRD BLOCK

March 2, 2009

In the third block we will be looking at the three dimensional graphs using both Euler’s method and the Ode45 method from last block. The lorenz equations are the given examples we will be analyzing with these graphs. The block will conclude with an analysis of the Rossler system of differential equations. 

The Lorenz Attractor is made up of three equations, which are 

dx/dy=σ(y-x)

dx/dt=x(ρ-x)

dz/dt=xy-βz 

The first step we need to take before we can get any of our approximations we must modify our m files from previous blocks. We use the following code: 

function[t,y] = eulerpm (f,t_range, y_initial, nstep)

dt = (t_range(2) – t_range(1)) / nstep;

t = t_range;

y(:,1) = y_initial;

fori = 1 :nstep

t(i+1) = t(i) + dt;

y(:,i+1) = y(i) + dt * feval( f, t(i), y(i) );

plot(t,y)

plot3( y(1,:), y(2,:), y(3,:) )

xlabel(‘t’)

ylabel(‘y’)

end

In order to evaluate the systems of equations we must change the y axis into an array input. The next step is to use the plot3 matlab command. After this the next file that must be changed is the example problem m-file called pmexample.m.

 functionyprime= pmexample(t,y)

yprime = [10.0* (y(2)-y(1)); y(1)*(28.0-y(3))-y(2);y(1)*y(2)-8*y(3)/3];

end

We must note that these values are default values to ensure that our euler program is running properly.

>> y_init = [rand(),rand(),rand()];

>> [ t, y ] = eulerpm ( ‘pmexample’, [ 0.0, 20.0 ], y_init, 1000 );

The following was graph was yeilded by MATLAB as a result,

1

As you can see, much like graphs from previous blocks, euler’s method produces rigid graphs that are not very accurate. Now let us use the Ode45 method and compare the two graphs.

Our first step is to create two m. files for this method. The first file is so we can evaluate the differential equation, and the second file we create allows us to modify the ode45 program in MATLAB, making life much easier for us.

 

pmlorenz.m:

functionxdot = pmlorenz(t,x)

xdot = zeros(3,1);

sig = 10.0;

rho = 28.0;

bet = 8.0/3.0;

xdot(1) = sig*(x(2)-x(1));

xdot(2) = rho*x(1)-x(2)-x(1)*x(3);

xdot(3) = x(1)*x(2)-bet*x(3);

pmlorenz2.m:

functionpmlorenz2(time)

[t,x] = ode45(‘pmlorenz’,[0 time],[1;2;3]);

disp(‘press any key to continue ?’)

pause

plot3(x(:,1),x(:,2),x(:,3))

After we enter the lorenz code into the command screan in MATLAB we can see the following lorenz equation graph produced by the ode45 method.

2

Much, much better. It is actually difficult to beleive that this is the same as the graph above but believe it so. We can see, just like the previous blocks, the ode45 method of solving these differential equations produces a much smoother, more detailed graph of the function. As you follow through the rest of this block, we will be further proving this conclusion using three more examples. In these examples, I will be using the same m. files as in the problem above with changes only in the rho sigma and beta of each. Because of this, to avoid redundency I will just include the new values of these three.

The first example will use:

Example #2:

ρ = 18

σ = 10

β = 8/3

 Euler’s Method Approximation

 4

Ode45 Method Approximation

 

5

Example 3:

σ = 10

β = 8/3

ρ = 8

Euler’s Method Approximation

euler1

Ode45 Method Approximation

ode11

Now that we have seen a few examples using the lorenz attractor it has become apparent that there is a significant difference between euler’s method and the ode45 method if solving. Each example shows how much smoother and more accurate the ode45 method is when analyzing lorenz’s system of equations.

The next step we will be taking is to show that this is not only the case for Lorenz’s system of equations, but also for Rossler’s system of equations as well. This will demonstrate that another Ode system of equations that creates an attractor as well as furthering our conclusion that euler’s method is not nearly as accurate or reliable for our use.

In order to do this, we must take similar steps as creating the lorenz system. We create two m. files, one to create a graph of the attractor and the other to set the variables and equation.

rossler.m:

function xdot = rossler(t,x)

a = 0.2;
b = 0.2;
c = 5.7;

xdot(1) = -x(2)-z;
xdot(2) = x(1)+ax(2);
xdot(3) = b+x(3)*(x(1)-c);

rossler2.m:

function rossler2(time)
[t,x] = ode45(’rossler’,[0 time],[1;2;3]);
disp(’press any key to continue ?’)
pause
plot3(x(:,1),x(:,2),x(:,3))
print -deps rossler.eps

Example 1:

a = 0.2

b = 0.2

c = 5.7

ode21

As you can see by the graph above, this approximation has a different shape as the lorenz examples. This attractor draws the point verticaly away from the xy plane at one point allong its circular path creating a bumb or hill.

Example 2:

a = 0.1

b = 0.1

c = 4

ode3

Much like the previous problem, once again we see a similar shape with circular path and an annomoly conatined within.

We conclude with analyzing the roles of the three variables a, b and c.

Variable a is responsible for controling the spot where the annomaly enters the center. The larger the value of a is, the further from the center the path is. Variable a also controls the proximity of each revolution in comparison to the last. When we increase or decrease variable a from the value .2, it creates a swirl effect in the graph that groups the revolutions together in a circular path.

Variable b seems as though it has a direct correlation with the height of the annomoly in the graph. By varying the value of b we can see the anomoly going up or down in height.

Variable c similar to variable, controls the proximity of the revolutions as well.


block 2

February 20, 2009

In this block we will use three different methods to solve six differential equations. The first method we will be using is Euler’s method, just as we did in block 1. The next two methods, the ode45 equation solver and the dsolve function in MATLAB will both be used an compared to Euler’s method.

PROBLEM 1. : dy/dx=x^4*y ; y(1)=1; expression solution $ latex y= \frac {1}{sin(x)+1} $

In these problems, using Euler’s method, i will be using the MATLAB code that i created in the previous block. The written m file was as follows,

function [x,y] = euler (f,x_range, y_initial, nstep)

dx = (x_range(2) – x_range(1)) / nstep;

x = 1;

y = y_initial;

for i = 1 :nstep

x(i+1) = x(i) + dx;

y(i+1) = y(i) + dx * feval( f, x(i), y(i) );

plot(x,y)

xlabel(‘x’)

ylabel(‘y’)

end

When i entered the first problem into the code,

exmplepm.m :

function yprime = pmexmple(x,y)

yprime = (x^4*y)

end

In the command screan, entered

>> eulerpm(‘pmexample’,[0,1],1,100);

MATLAB then yielded the following graph,

ee2
The next step was to use the ode45 method for the same problem. Since ode45 is already programed in MATLAB all that is necessary to yield a graph the following code in the command screan,

>>ode45(‘pmexample,1,100);

The following graph is created,

ff

After getting both graphs, in order to get a better comparison, the next step is to overlay the two. We use the following code,

>> eulerpm(‘pmexample’,[0,1],1,100);

>> hold on

>> [x,y]=ode45(‘pmexample’,[0,1],1);

>> hold off

the overlay graph:

fff

As you can see, the two graphs were so similar, they overlap each other making it seem as though there is only one equation line. This shows that both methods yielded the same answer to the equation.

The MATLAB solution using the dsolve method which evaluates differential equations used the following code,

dsolve(‘DY=x^4*y’,'x’)

the answer = 1/5*x^5y+C1

PROBLEM 2. : dy/dx = (x^4)*(y)

Using the same MATLAB codes as in the first problem, all that was changed were the codes to fit this problem. The same m files were used in this problem as in the first.

Euler’s Method produces the following graph:

2-euler-x4y

By using a smaller step size, we can see how inaccurate Euler’s method is. As you can see, this method uses a series of lines instead of curves to approximate the solution.

The ode45 method, using the same code as problem 1 with a slight change then yields,

2-x4y-ode45

This graph is much more fluid in its curves and more accurate than the first. Now we can look at the over lay of the two graphs,

overlay1

As we can see, the approximations are close to one another, however they are not equal. The Euler’s approximation is nice, but not quite as accurate as the ode 45 method.

Our next step is to look at this equation using the dsolve method in MATLAB

dsolve(’DY=Y*X^4′,’Y(1)=1′,’X’)

ans =

exp(X^5/5)/exp(1/5)

PROBLEM 3. : dy/dx = x + y ; y(0) = 0 expression solution y = 1 – x + e^x

Euler’s Method:

asa

The graph displays the function as a slowly upward sloping curve. The graph looks as though it is a pretty good depiction, however, let’s take a look at the graph produced by the ode 45 method,

Ode45 Method:

asb1

Once again, we see a similar, yet smoother and more accurate graph produced by the ode45 method as opposed to Euler’s method.

The Overlay Graph:

asc

The two curves of this function are very close to each other, but are not equal to each other. The ode45 method has produced the more accurate graph yet again.

The MATLAB dsolve method of solving this problem has given the following solution,

dsolve(’DY=x+y’,’x’)

ans =

1/2*x^2+y*x+C1

PROBLEM 4. : dy/dx = x*y^2 ; y(0)=1

Again, by changing the examplepm to fit the equation we can plot the graphs as follows,

Eulers Method:

block2s2q1-11

The graph shows a curve function that looks similar to the curve in problem one. This is because the only difference in the two equations is the exponential power of x. This creates the graph to rise at a steeper pace than the previous curve. The next step is to look at the ode45 method and compare the graphs,

ode45 Method:

adsaaa

The graph is much similar to that of Euler’s method. In order to get a better visual understanding of the relations between the two, we must overlay the two functions on one graph. As it has been in the previous problems, I believe the ode45 method has produced the more accurate depiction of the equation.

The overlay graph of the two functions looks as follows,

adsaassa

As you can see, the ode 45 method, just as it has been in the previous problems, produces a more accurate graph of the function. Euler’s method produces a graph that is very similar but not quite as accurate as the ode45 method.

The dsolve method in MATLAB yields,

dsolve(’DY=x^2*y’,’x’)

ans =

(y*x^3)/3 + C2


PROBLEM 5. :
dy/dx = e ^ -x ; y(0)=1

For this equation, the first method i used to solve the equation was the MATLAB dsolve method, which yielded the following,

dsolve(’DY=exp(-x)’,’x’)

ans =

-exp(-x)+C1

The next step was to change the Euler’s method equation to fit the problem, after which, we can see the graph of the function as follows,

Euler’s Method:

ada

As you can see, the curve of the line looks like a reasonable solution to the problem. However, our next step is to use the ode45 method once again, and then compare the two graphical solutions.

Ode45 Method:

adb

This graph looks pretty similar to that of Euler’s method, but when we overlay them for a closer look,

adc

We can see that while the curves are very close in this particular problem, as we have found throughout this block, the ode45 method has once again produced the smoother, more accurate solution curve

PROBLEM 6. : dy/dx = x^3 * y – x^2 * y^2 ; y(-1) = 1

When we take a look at Euler’s method for this problem, the graph yielded is,

af1

As you can see, the Euler’s method has produced a very jagged graph of this problem. The next step we took the ode45 method and graphed the equation which produced a much better graph. I skipped right to overlaying them and they look as follows,

ag

The ode45 method has produced the much smoother graph of the line once again which leads us to the conclusion of this block. As you can see throughout the problems above, the euler method is not a very accurate way t solve problems. The ode45 method or Runge-Kutta method is a much more smooth and accurate depiction of the problems. 



First Block

January 28, 2009

In my first post there will be two problems analyzed, one from the text dy/dx = xy (#17) and the given problem dy/dx = y^2 + t .

The first thing I will do is plot a direction field for the first differential equation using MATLAB. Using the text, on page 85, the code used to create the direction feild in MATLAB is the following,

[X,Y]= meshgrid(-2*pi:.25:2*pi,-2*pi:.25:2*pi);

DY=X.*Y

DX=ones(size(DY));

DW=sqrt(DX.^2 +DY.^2);

quiver(X,Y,DX./DW,DY./DW,.33,‘.’);

xlabel(‘x’);

ylabel(‘y’);

The direction field I got for this equation is as follows,

euler1

In order to attain the euler approximation for this equation, I used the following MATLAB code as it was stated in the text.

function [xout,yout]=euler(fname,xvals,y0,h)
x0=xvals(1);xf=xvals(2);
xn=x0;
yn=y0;
xout=xn;
yout=yn;
steps=(xf-x0)/h;
for j=1:steps
fn=feval(fname,xn,yn);
xn=xn+h;
yn=yn+h*fn;
xout=[xout;xn];
yout=[yout;yn];
end

The euler approximation that MATLAB created is as follows,

euler17

The next step was to plot the euler method over the directional feild, which created the follwing graph,

prob17final

As you can see, the euler curve follows the directional feild lines pretty closely.   We can notice the directional feild lines are actually tangential to the solution curve created using the euler method. This tells us that the graph produced is a viable solution to this equation.

 

After completing the first differential equation, the same steps were taken for the second differential equation. The MATLAB code for the directional feild for dy/dx = y^2 + t is the same as the last equation, as follows,

[T,Y]= meshgrid(-2*pi:.25:2*pi,-2*pi:.25:2*pi);

DY=Y.^2+T

DT=ones(size(DY));

DW=sqrt(DT.^2 +DY.^2);

quiver(T,Y,DT./DW,DY./DW,.33,‘.’);
xlabel(‘x’);
ylabel(‘y’);

secondproblemgraph

After getting the directional feild for this equation, I used the same general equation for the Euler method as the previous problems. Some changes in the euation were necessary to yeild the graph below.

euler-correct1

As done in the previous problem, the directional feild and euler method were plotted together.

euler-final

As you can see the relationship between the two, we can notice that once again the directional feild lines are tangential to the curve created using the Euler method. Because of this, we can conclude that this is another successful solution to the given differential euqation.


Follow

Get every new post delivered to your Inbox.