Quarter 4: Example 4

December 4, 2008

Introduction: Prof. Davis has been explaining Laplace Transformations and providing examples of this technique. Prof. Davis also showed two interesting movies on the projector. The films were very entertaining s well as educational.

Using the “syms” function on Matlab, I obtained solutions using a Laplace Transformation:

A.) >> syms A B s t; ilaplace(3*(2+s)/(s^2+2*s-1)+4/(s^2+2*s-1)+1/(s*(s^2+2*s-1)))
ans =
(4*(cosh(2^(1/2)*t) + 2^(1/2)*sinh(2^(1/2)*t)))/exp(t) – 1

B.) >> syms A B s t; x=ilaplace(A*(2+s)/(s^2+2*s-1)+B/(s^2+2*s-1)+1/(s*(s^2+2*s-1)),s,t)
x =
((cosh(2^(1/2)*t) + (2^(1/2)*sinh(2^(1/2)*t)*((2*A + B + 2)/(A + 1) – 1))/2)*(A + 1))/exp(t) – 1

q44

To graph this equation in Matlab, I used the ezplot function with the solution derived by Matlab:

>> ezplot(‘(4*(cosh(2^(1/2)*t) + 2^(1/2)*sinh(2^(1/2)*t)))/exp(t) – 1′, [-9, -5])

Situation 1 : A=-2 B=2

>> ezplot(‘((cosh(2^(1/2)*t) + (2^(1/2)*sinh(2^(1/2)*t)*((2*(-2) + 2 + 2)/((-2) + 1) – 1))/2)*((-2) + 1))/exp(t) – 1′, [-9, -5])

q45

Situation 2: A=2 B=-2

>> ezplot(‘((cosh(2^(1/2)*t) + (2^(1/2)*sinh(2^(1/2)*t)*((2*(2) + -2 + 2)/((2) + 1) – 1))/2)*((2) + 1))/exp(t) – 1′, [-9, -5])

q46

Situation 3: A=2    B=2

>> ezplot(‘((cosh(2^(1/2)*t) + (2^(1/2)*sinh(2^(1/2)*t)*((2*(2) + 2 + 2)/((2) + 1) – 1))/2)*((2) + 1))/exp(t) – 1′, [-9, -5])

q47

Situation 4: A=-2   B=-2

>> ezplot(‘((cosh(2^(1/2)*t) + (2^(1/2)*sinh(2^(1/2)*t)*((2*(-2) + (-2) + 2)/((-2) + 1) – 1))/2)*((-2) + 1))/exp(t) – 1′, [-9, -5])

q48

Quarter 3: Example 3

October 30, 2008

Positive/Negative

>> [x,y]=meshgrid(-1:1/10:1,-1:1/10:1);

>> u=2*x+y;

>> v=7*x+3*y;

>> quiver(x,y,u,v,1)

graph-5

After using the two two equations to set up a quadratic, I set the quadratic equation to zero and used the quadratic formula to find the zeros. In doing so I derived two answers: 5+5.4 and 5-5.4. One result is negative and the other is positive. The graph shows some positive direction vectors as well as some in the negative direction.

Entering the system into Matlab to obtain the exact solution is much simpler than doing it out by hand. It is a matter of plugging the equation into the dsolve feature and pressing enter. Below is exactly what I entered into Matlab as well as the exact solution:

SOL: >> [x,y]=dsolve(‘Dx=2*x+y’,'Dy=7*x+3*y’,'t’)
x =
(29^(1/2)*C8*exp((5*t)/2 + (29^(1/2)*t)/2))/14 – (C9*exp((5*t)/2 – (29^(1/2)*t)/2))/14 – (C8*exp((5*t)/2 + (29^(1/2)*t)/2))/14 – (29^(1/2)*C9*exp((5*t)/2 – (29^(1/2)*t)/2))/14
y =
C8*exp((5*t)/2 + (29^(1/2)*t)/2) + C9*exp((5*t)/2 – (29^(1/2)*t)/2)

Negative/Negative

>> [x,y]=meshgrid(-1:1/10:1,-1:1/10:1);

>> u = -3*x + 2*y;

>> v = 4*x – 3*y;

>> quiver(x,y,u,v,1)

Using the same technique as in the first example, I used the quadratic formula to retrieve the zeros. I derived the zeros as being: -6+5.7 and -6-5.7. Both answers are negative. It is evident that the slopes of the vectors are indeed negative.

Every time I use Matlab to get an exact solution I appreciate its capabilities more and more.  It’s very  simple and always accurate. It tells us how the differential  unfolds numerically while the direction field  shows  the path of the curve at any  given time:

SOL: >> [x,y]=dsolve(‘Dx=-3*x+2*y’,'Dy=4*x-3*y’,'t’)
x =
(2^(1/2)*C6*exp(2*2^(1/2)*t – 3*t))/2 – (2^(1/2)*C7)/(2*exp(3*t + 2*2^(1/2)*t))
y =
C6*exp(2*2^(1/2)*t – 3*t) + C7/exp(3*t + 2*2^(1/2)*t)

Positive/Positive

>> [x,y]=meshgrid(-1:1/10:1,-1:1/10:1);

>> u = 2*x + y;

>> v = x + 3*y;

>> quiver(x,y,u,v,1)

Using the quadratic formula yields positive answers for the two equations. The graph shows evidence of the positive answers.

SOL: >> [x,y]=dsolve(‘Dx=2*x+y’,'Dy=x+3*y’,'t’)
x =
(5^(1/2)*C4*exp((5*t)/2 + (5^(1/2)*t)/2))/2 – (C5*exp((5*t)/2 – (5^(1/2)*t)/2))/2 – (C4*exp((5*t)/2 + (5^(1/2)*t)/2))/2 – (5^(1/2)*C5*exp((5*t)/2 – (5^(1/2)*t)/2))/2
y =
C4*exp((5*t)/2 + (5^(1/2)*t)/2) + C5*exp((5*t)/2 – (5^(1/2)*t)/2)

Second 3 Week Quarter

September 30, 2008

Using Euler’s Method to obtain a solution to a first order differential equations is helpful in that it is simple and answers can be found at any point when plotted on excel. Finding an exact solution using separation of variables or any other numerical approach is more challenging, but more precise. When an exact answer is necessary, Euler’s Method can yield a greater margin of error the further you stray from the initial condition.

Using the differential equation from the first three week block Euler’s Method yielded an x y table:

x y
1 2
1.01 2.04
1.02 2.08039604
1.03 2.121188119
1.04 2.162376238
1.05 2.203960396
1.06 2.245940594
1.07 2.288316832
1.08 2.331089109
1.09 2.374257426
1.1 2.417821782
1.11 2.461782178
1.12 2.506138614
1.13 2.550891089
1.14 2.596039604
1.15 2.641584158
1.16 2.687524752
1.17 2.733861386

The problem with Euler’s method occurs when finding a result way down the list at say x=50. Euler’s method is not nearly as accurate as finding the solution using separation of variables. Inputing the initial condition sets the tone for Euler’s Method and the accuracy decreases proportionately to how far down the list you go.

In some cases an exact solution is not attainable by any method. Finding a solution to one of these problems requires one to numerically approximate the solution.

Graphs using excel:

X Y Z

0.185319355 0.146301433 0.784226924
0.181417563 0.195274514 0.763585331
0.182803258 0.242733408 0.743577318
0.188796273 0.290131703 0.724192314
0.198929816 0.338726094 0.705428277
0.212909444 0.389635875 0.687290683
0.230582087 0.443890853 0.669792503
0.251912964 0.502470508 0.652954903
0.276968718 0.566336554 0.63680856
0.305905502 0.636460669 0.621395574
0.338961018 0.71384872 0.606771993
0.376449789 0.799562597 0.593011076
0.41876107 0.894740523 0.580207399
0.466359015 1.000616535 0.568482026
0.519784767 1.118539727 0.557988971
0.579660263 1.249993722 0.548923264
0.646693609 1.396616769 0.541531028
0.721685925 1.560222765 0.536122032
0.805539609 1.742823479 0.533085352

x(t) vs. y(t) vs.z(t)

x(t) vs. y(t) 

 


I found using excel to graph X, Y, Z equations to be challenging at first. At first I was confused as to why the statistics kept changing until Prof. Davis reminded me the chart was set on random. I didn’t realize this was the reason the graphs would also change as the results did. The only downfall to using excel is a 3-D graph is not attainable. The first graph above shows the relationship between all three equations. A 3-D graph would show the relationship more clearly, but I got a good sense of what was going on. The second graph in blue show the relationship between x(t) and y(t). This graph helps me understand the randomness of the two equations. I also graphed x(t) vs. z(t) and y(t) vs. z(t) and the graphs were quite similar except for different rotations.

 

Example 1 using Matlab: function yprime = test_example ( t, y )
yprime = y*(2./t-1);

Example 2 using Matlab: function yprime = new_example ( t, y )
yprime = (2*t^2)-(y);

Example 3 using Matlab: function yprime = new_example ( t, y )
yprime = (y*(4./t+2));

Matlab is extremely helpful when using multiple DE’s. The M-file feature made life a lot more simple. By creating an M-file it is possible to write the steps in Matlab one time and plug in any saved equation from the M-file. Instead of having to re-type the lines required to attain the three graphs above, you type it one time. After an equation is entered and saved in an M-file, I went to Matlab and simply typed in what I saved the equation as and replaced the old equation. This made it possible to explore multiple differential equations in a short period of time with less mistakes and less hassle. This is the first time I’ve used an the M-file feature and it definitely will not be the last.

Quarter 1: Example 1

September 11, 2008

I am working on the differential equation: \frac{dy}{dx}=\frac{2y}{x}

Solution using Matlab: >> dsolve(’Dy=2*y/x’,’x’) ans = C1*x^2

To solve the above equation, I used the “dsolve” command in Matlab. Dsolve is most useful when it expresses ‘Y’ explicitly in terms of built in Matlab Functions of ‘x’. I inputed my equation into the program in the proper syntax and the computer solved the problem properly.

Direction Field using Matlab: >> S = 2*y./x;

??? Undefined function or variable ‘y’.

>> S = (2*y)./x;

??? Undefined function or variable ‘y’.

>> S = (2*Y)./X;

>>

>> [X, Y] = meshgrid(1:0.2:5, 1:0.2:5);

>> S = (2*Y)./X;

>> quiver(X, Y, ones(size(S)), S), axis tight

>> [X, Y] = meshgrid(1:0.2:5, 1:0.2:5);

>> S = (2*Y)./X;

>> L = sqrt(1 + S.^2);

>> quiver(X, Y, 1./L, S./L, 0.5), axis tight

>> xlabel ‘x’, ylabel ‘y’

>> title ‘Direction Field for dy/dx = (2*y)./x’

To the exact mistakes that were made as well as the steps that were taken, I copied the stats from Matlab exactly. I originally planned on cutting the mistakes out and cleaning it up along with entering everything in Latex. Along with the rest of the class I am familiar with the terms and format of Matlab. I decided to leave it exactly as seen in Matlab for everyone to get  a clear picture of exactly what I experienced.

At first obtaining the direction field was a real pain. I could not seem to enter S=(2*y)/x.

Then I realized we entered [X, Y] into our meshgrid so I had to use capital X’s and Y’s in S=(2*Y)/X. I still could not obtain a direction field so I figured out a period was necessary after the (2*Y) term in the numerator. After doing so I obtained a direction field, but you could hardly see the slope rays. After adjusting the quiver command I created a direction field that could actually be read without using a microscope.

Direction Field

Direction Field

The direction field lines are important to understand when dealing with a differential equation. I’m getting it more and more as the semester continues. Before this class I could solve a differential equation, but I wasn’t 100% sure what I actually found. A direction field shows the slope of the curve at any given time. This amazes me when I see a crazy graph going every which way yet it is possible to back track and find exactly where the graph is going at any point. Looking at a slope field like my example above makes it easier to understand what exactly is going on. I look at the direction field and I draw a picture in my head of what the graph looks like by following the rays. The direction field maps out what the solution curve will look like. When I follow the rays drawn above the solution curve will be drawn out. For me I like to have both in front of me to tie them together. It is easier for me to learn when pieces of the puzzle are right in front of me and they’re all somehow connected.
Euler’s Method using Excel:
x y
1 2
1.01 2.04
1.02 2.08039604
1.03 2.121188119
1.04 2.162376238
1.05 2.203960396
1.06 2.245940594
1.07 2.288316832
1.08 2.331089109
1.09 2.374257426
1.1 2.417821782
1.11 2.461782178
1.12 2.506138614
1.13 2.550891089
1.14 2.596039604
1.15 2.641584158
1.16 2.687524752
1.17 2.733861386
Euler’s Method is a great tool for solving DE’s. Finding the exact solution can be very difficult or sometimes impossible. Euler’s method is a quick approach that is relatively simple. Simple DE’s are ideal when solving using Euler’s method. By using the proper format I entered my equation along with some commands for excel to read. When I entered these few lines, I included the equation for euler’s method along with an initial condition and stepsize. The beauty of using excel is simply dragging the mouse down the page will yield any solution using euler’s method. Euler’s method takes a bit of time and excel can give you an answer in one second. Excel was very useful and I also obtained a graph of the solution curve above. Euler’s method is not always as accurate as I’d like, but when I am using Euler’s method excel makes life a whole lot easier and takes way less time. I’ve enjoyed the hands on approach to differential equations in this class. I actually understand what I’m solving for by looking at the graphs and direction fields.

Hello world!

September 2, 2008

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!


Follow

Get every new post delivered to your Inbox.