4620 Homework 3

Kristin Schmidtke

You can use any programing language or tool that you want.

Desolve

Clear[u,x]
DSolve[ 
{
u''''[x]==x Sin[x],
u[0]==0,
u'[0]==0,
u[π]==0,
u'[π]==0
},
u[x],
x]

n=6

Clear[n,Δx,A,b,i,u,F,ueval,xsol]
n=6;
Δx=N[π/n];
A=SparseArray[
Join[
Table[ {i,i}->6.,{i,3, n+1}],
Table[{i,i+1}->-4.,{i,3,n-1}],
Table[{i+1,i}->-4.,{i,n-2}],
Table[{i+2,i}-> 1,{i,n-3}],
Table[{i,i+2}-> 1,{i,3,n-1}]
]
];
A[[1,1]]=1;
A[[1,2]]=-1;
A[[2,1]]=1;
A[[n+1,n]]=-1;
A[[n,n+1]]=1;
A[[n+1,n+1]]=1;
A[[n,n]]=0;
MatrixForm[A]

Define the matrix with the 1,-4,6,-4,1 pattern in the middle to represent the forth derivative. The extraneous 1's are to represent the boundry conditions given by the problem.

F[x_]=x Sin[x];
b=Δx^4*Table[F[i*Δx],{i,2,n-2}];
b=Join[{0},{0},b,{0},{0}];
xsol=LinearSolve[A,b];
err=A.xsol-b;
ListPlot[Abs[err]]

Define the forcing function F and the b vector. The b vector is joined with the inital conditions of 0,0,0, and 0. Plotted is the error from the matrix.

u[x_]=((-4 (π^3)+24 π (x^2)-(π^3) (x^2)-16 (x^3)+(π^2) (x^3)+4 (π^3) Cos[x]+(π^3) x Sin[x])/(π^3));
ueval=Table[u[i*Δx],{i,0,n}];
ListPlot[Abs[ueval-xsol]]

Plotted above is the error in our approximation to the exact answer as calculated above.

ListPlot[{ueval,xsol}]

Plotted is the Exact and approximate solution.

n=60

Clear[n,Δx,A,b,i,u,F,ueval,xsol]
n=60;
Δx=N[π/n];
A=SparseArray[
Join[
Table[ {i,i}->6.,{i,3, n+1}],
Table[{i,i+1}->-4.,{i,3,n-1}],
Table[{i+1,i}->-4.,{i,n-2}],
Table[{i+2,i}-> 1,{i,n-3}],
Table[{i,i+2}-> 1,{i,3,n-1}]
]
];
A[[1,1]]=1;
A[[1,2]]=-1;
A[[2,1]]=1;
A[[n+1,n]]=-1;
A[[n,n+1]]=1;
A[[n+1,n+1]]=1;
A[[n,n]]=0;

Define the matrix with the 1,-4,6,-4,1 pattern in the middle to represent the forth derivative. The extraneous 1's are to represent the boundry conditions given by the problem.

F[x_]=x Sin[x];
b=Δx^4*Table[F[i*Δx],{i,2,n-2}];
b=Join[{0},{0},b,{0},{0}];
xsol=LinearSolve[A,b];
err=A.xsol-b;
ListPlot[Abs[err]]

Define the forcing function F and the b vector. The b vector is joined with the inital conditions of 0,0,0, and 0. Plotted is the error from the matrix.

u[x_]=((-4 (π^3)+24 π (x^2)-(π^3) (x^2)-16 (x^3)+(π^2) (x^3)+4 (π^3) Cos[x]+(π^3) x Sin[x])/(π^3));
ueval=Table[u[i*Δx],{i,0,n}];
ListPlot[Abs[ueval-xsol]]

Plotted above is the error in our approximation to the exact answer as calculated above.

ListPlot[{ueval,xsol}]

Plotted is the Exact and approximate solution.

n=6000

Clear[n,Δx,A,b,i,u,F,ueval,xsol]
n=6000;
Δx=N[π/n];
A=SparseArray[
Join[
Table[ {i,i}->6.,{i,3, n+1}],
Table[{i,i+1}->-4.,{i,3,n-1}],
Table[{i+1,i}->-4.,{i,n-2}],
Table[{i+2,i}-> 1,{i,n-3}],
Table[{i,i+2}-> 1,{i,3,n-1}]
]
];
A[[1,1]]=1;
A[[1,2]]=-1;
A[[2,1]]=1;
A[[n+1,n]]=-1;
A[[n,n+1]]=1;
A[[n+1,n+1]]=1;
A[[n,n]]=0;

Define the matrix with the 1,-4,6,-4,1 pattern in the middle to represent the forth derivative. The extraneous 1's are to represent the boundry conditions given by the problem.

F[x_]=x Sin[x];
b=Δx^4*Table[F[i*Δx],{i,2,n-2}];
b=Join[{0},{0},b,{0},{0}];
xsol=LinearSolve[A,b];
err=A.xsol-b;
ListPlot[Abs[err]]

Define the forcing function F and the b vector. The b vector is joined with the inital conditions of 0,0,0, and 0. Plotted is the error from the matrix.

u[x_]=((-4 (π^3)+24 π (x^2)-(π^3) (x^2)-16 (x^3)+(π^2) (x^3)+4 (π^3) Cos[x]+(π^3) x Sin[x])/(π^3));
ueval=Table[u[i*Δx],{i,0,n}];
ListPlot[Abs[ueval-xsol]]

Plotted above is the error in our approximation to the exact answer as calculated above.

ListPlot[{ueval,xsol}]

Plotted is the Exact and approximate solution.

Conclusion

As we increase n, therefore increasing the number of grid points our approximation gets better. Though n=6 does not seem to approximate the exact solution very well, when we increase n by a factor of 10 the grid points look much better and closer to the exact answer. I'm just glad I have a computer program to complete n=6000 otherwise this assignment would look incomplete to me.