You are on page 1of 7

Problem 1

In[1]:=

gs[a_, b_, xinit_] :=


Module{m, j, n = Length[a], x, this},
x = N[xinit];
this = ConstantArray[0, Length[a]];
Form = 0, m < 10 ^ 6, m ++,
Forj = 1, j < n + 1, j ++,
x[[j]] =
1
a[[j, j]]

j-1

k=1

k=j+1

b[[j]] - a[[j, k]] x[[k]] - a[[j, k]] x[[k]]

If[Max[Abs[(x - this) / x]] < 10 ^ - 6, Break[], this = x]


Print["The error for each X is:
" <> ToString[(x - this) / x]]
Print["This took " <> ToString[m] <> " iterations."];
x
In[2]:=

A = {{5, 1, 2},
{1, 4, - 2},
{2, 3, 8}};

In[3]:=

b = {19, - 2, 39};

In[4]:=

xinit = {1, 1, 1};

In[5]:=

gs[A, b, xinit]
The error for each X is:
-8
{-6.12272 10

, -6.76053 10

-7

-8

, 7.10333 10

This took 10 iterations.


Out[5]=

{2., 1., 4.}

Printed by Wolfram Mathematica Student Edition

Problem set 4.nb

Problem 2
T ' (t) = k1 (T(t) - Ta ) + k2 (T(t) - T ) + P
equation =
T '[t] k1 T[t] - A - c Cos

Pi
12

+ k2 (T[t] - Tw) + P;

thing = DSolve[equation, T[t], t]


T[t] (k1+k2) t C[1] +
144 k12 + 288 k1 k2 + 144 k22 + 2 (A k1 - P + k2 Tw) - 144 c k1 (k1 + k2)2 Cos
12 c k1 (k1 + k2) Sin

t
12

12

-P+k1 A+k2 T
k1 +k2

T[t] = C[1] Expk1 + k2 t +


12
Pi

Sin

Pi
12

t -

Sin 12 t1+

144 (k1 +k2 )

2
144 (k1 +k2 )2
2

Cos 12 t

- P + k1 A + k2 Tw
k1 + k2

144 k1 + k2
Pi2

12

(k1 + k2) 12 k1 + 12 k2 - 12 k1 + 12 k2 +

For the written portion, I obtained:


T(t) = C[1] e(k1 +k2 ) t +

Cos

Pi
12

1+

Printed by Wolfram Mathematica Student Edition

144 k1 + k22
Pi2

Problem set 4.nb

Problem 3
Here, we have the differential equation: y - y = 0. If we set the initial conditions to y(0)=1 and y(0)= -1,
we obtain the following solution and graph.
In[6]:=
Out[6]=

In[7]:=

DSolve[{f ''[x] - f[x] 0, f[0] 1, f '[0] - 1}, f[x], x]


{{f[x] -x }}
Plot[Exp[- x], {x, 0, 10}]
0.4

0.3
Out[7]=

0.2

0.1

10

Next, if we solve the same differential equation with initial conditions of y(0)=1.001 and y(0)= -0.999,
we obtain a different solution and a completely different graph.
In[8]:=
Out[8]=

In[9]:=
In[10]:=

DSolve[{f ''[x] - f[x] 0, f[0] 1.001, f '[0] - 0.999}, f[x], x]


f[x] 0.001 -x 1000. + 1. 2 x
diff = 0.001 Exp[- x] 1000 + Exp[2 x];
Plot[diff, {x, 0, 10}]

6
Out[10]=

10

This is known as chaos theory. A small change in initial conditions can lead to a huge change down the
road. In this particular example, the original intial conditions of (1) and (-1) caused the solution to
reduce into a decaying function because the C1 went to zero. However, in the second set of initial
conditions, the growth function and the decaying function made its way into the solution, making the
graph completely different the second time around because the growth function took over.

Printed by Wolfram Mathematica Student Edition

Problem set 4.nb

Problem 4
a)
In[11]:=

G[x] = y '''[x] + p y ''[x] + q y '[x] + r y[x];

In[12]:=

yh = C1 y1[x] + C2 y2[x] + C3 y3[x];


y1 '[x] = D[y1[x], x];
y2 '[x] = D[y2[x], x];
y3 '[x] = D[y3[x], x];
y1 ''[x] = D[y1 '[x], x];
y2 ''[x] = D[y2 '[x], x];
y3 ''[x] = D[y3 '[x], x];

Now to put the functions of Y and their derivatives in a matrix 3x3, because it is third order.
In[19]:=

trix = {{y1[x], y2[x], y3[x]}, {D[y1[x], x], D[y2[x], x], D[y3[x], x]},
{D[y1[x], {x, 2}], D[y2[x], {x, 2}], D[y3[x], {x, 2}]}};

In[20]:=

MatrixForm[trix](*To see it in matrix form*)

Out[20]//MatrixForm=

y1[x] y2[x] y3[x]


y1 [x] y2 [x] y3 [x]
y1 [x] y2 [x] y3 [x]

So now we must find the Wronskian, which is the determinant of this matrix.
In[21]:=
Out[21]=

WW = Det[trix]
- y3[x] y2 [x] y1 [x] + y2[x] y3 [x] y1 [x] + y3[x] y1 [x] y2 [x] y1[x] y3 [x] y2 [x] - y2[x] y1 [x] y3 [x] + y1[x] y2 [x] y3 [x]

Now we must make some constraints to solve our particular solution. First of all, our particular solution
is defined by:
In[22]:=

yp[x] = j1[x] y1[x] + j2[x] y2[x] j3[x] y3[x];

The constraints I will make are in order to get rid of any term associated with the deriative of j (i.e. j', j'').
This means:
In[23]:=

cstr1 = j1 '[x] y1[x] + j2 '[x] y2[x] j3 '[x] y3[x] 0;

similarly:
In[24]:=

cstr2 = j1 '[x] y1 '[x] + j2 '[x] y2 '[x] j3 '[x] y3 '[x] 0;

This leaves us with the following equations for the particular solution and its derivatives:
In[25]:=

yp '[x] = j1[x] y1 [x] + j2[x] y2 [x] + j3[x] y3 [x];

In[14]:=

yp ''[x] = j1[x] y1 [x] + j2[x] y2 [x] + j3[x] y3 [x];

Printed by Wolfram Mathematica Student Edition

Problem set 4.nb

In[15]:=

yp '''[x] = D[yp ''[x], x];

After this, we need to find the Wronskian of y1, y2, and y3. This is done using cramers rule. The
matrix will consist of the same matrix as seen above, but the column for each respective y will be
replaced with a column of (0,0,g(x))T. The g(x) is in the third row because it corresponds to the second
derivative, or the last row in the Wronskian matrix. To simplify this, we can pull out the g(x) from the
matrix and put it into the final equation later. So the Wronskian for each function of y will be equal to the
determinant of the respective matrix. By doing this, we will receive three determinants of matrices that
will correspond to the three functions y (y1, y2, y3):
In[26]:=

w1 = Det[{{0, y2[x], y3[x]}, {0, y2 '[x], y3 '[x]}, {1, y2 ''[x], y3 ''[x]}}];


w2 = Det[{{y1[x], 0, y3[x]}, {y1 '[x], 0, y3 '[x]}, {y1 ''[x], 1, y3 ''[x]}}];
w3 = Det[{{y1[x], y2[x], 0}, {y1 '[x], y2 '[x], 0}, {y1 ''[x], y2 ''[x], 1}}];

Now finally, we can obtain our particular solution by the sum of the integrals of dividing each y-Wronskian by the total Wronskian, and multiplying by the g(x) for each one:
Yp = nk=1 yk (x)

Wk (x)
W(x)

g(x) x

For third order:


Yp = y1 (x)
In[29]:=

W1 (x)
W(x)

g(x) x + y2 (x)

YParticular = y1[x] Integrate


y2[x] Integrate

Out[29]=

W2 (x)
W(x)

w2
WW

g(x) x + y3 (x)

w1
WW

W3 (x)
W(x)

g(x) x

g[x], x +

g[x], x + y3[x] Integrate

w3
WW

g[x], x

((g[x] (- y3[x] y2 [x] + y2[x] y3 [x])) /

(- y3[x] y2 [x] y1 [x] + y2[x] y3 [x] y1 [x] + y3[x] y1 [x] y2 [x] y1[x] y3 [x] y2 [x] - y2[x] y1 [x] y3 [x] + y1[x] y2 [x] y3 [x])) x y1[x] +

((g[x] (y3[x] y1 [x] - y1[x] y3 [x])) / (- y3[x] y2 [x] y1 [x] +

y2[x] y3 [x] y1 [x] + y3[x] y1 [x] y2 [x] - y1[x] y3 [x] y2 [x] y2[x] y1 [x] y3 [x] + y1[x] y2 [x] y3 [x])) x y2[x] +

((g[x] (- y2[x] y1 [x] + y1[x] y2 [x])) / (- y3[x] y2 [x] y1 [x] +

y2[x] y3 [x] y1 [x] + y3[x] y1 [x] y2 [x] - y1[x] y3 [x] y2 [x] y2[x] y1 [x] y3 [x] + y1[x] y2 [x] y3 [x])) x y3[x]

B)
Now for the solution of the differential equation as given by: y - 2y - y + 2y = e 4 x

Printed by Wolfram Mathematica Student Edition

Problem set 4.nb

In[30]:=

y1[x] = E ^ 2 x;
y1 '[x] = D[y1[x], x];
y1 ''[x] = D[y1 '[x], x];
y2[x] = E ^ x;
y2 '[x] = D[y2[x], x];
y2 ''[x] = D[y2 '[x], x];
y3[x] = E ^ (- x);
y3 '[x] = D[y3[x], x];
y3 ''[x] = D[y3 '[x], x];
g[x] = E ^ (4 x);

The homogenous solution is given by:


Yh = C1e1 x + C2e2 x + C3e3 x
We can obtain these lambdas using the characteristic equation:
In[40]:=
Out[40]=

In[43]:=
Out[43]=

In[44]:=
Out[44]=

characteristic = L ^ 3 - 2 L ^ 2 - L + 2 0
2 - L - 2 L2 + L3 0
Factor[characteristic]
(- 2 + L) (- 1 + L) (1 + L) 0
Solve[characteristic]
{{L - 1}, {L 1}, {L 2}}

Therefore: 1 = -1, 2 = 1, 3 = 2
Now using the equation yh as derived in part a:
In[45]:=
Out[45]=

yh
C3 -x + C2 x + C1 2 x

And now for the particular solution, we can use the formula for yp as derived in part a:
In[46]:=

YParticular
4 x

Out[46]=

30

Therefore our final general solution is given by the homogeneous solution plus the particular solution, Y
= Yp + Yh
In[41]:=

Out[41]=

Ygeneral = YParticular + yh
C3 -x + C2 x + C1 2 x +

4 x
30

Printed by Wolfram Mathematica Student Edition

Problem set 4.nb

C)
And now to check the answer by utilizing the DSolve function:
In[42]:=

Out[42]=

DSolve2 y[t] - y [t] - 2 y [t] + y(3) [t] 4 t , y[t], t


y[t]

4 t
30

+ -t C[1] + t C[2] + 2 t C[3]

Printed by Wolfram Mathematica Student Edition

You might also like