Hw 1

Q1

Structure plots for one matrix.

SetDirectory["/home/campus03/struther/Desktop/Link to Courses/4620/ClassSampleMathematica/Sep6"];
A=Import["494_bus.mtx.gz"]
MatrixPlot[A,
PlotLabel->"494Bus"]

{Dimensions[A],1666./(494^2),ByteCount[A]}

Q2

x=RandomReal[{-1,1},Length[A]];
Timing[Do[y=A.x,{10000}];]

ADense=Normal[A];
ByteCount[ADense]
Timing[Do[y=ADense.x,{10000}];]

The storage is a lot more!

Q3

Timing[Do[y=LinearSolve[A,x],{100}];]
Timing[Do[y=LinearSolve[ADense,x],{100}];]

Q4

A= Import["e05r0000.mtx"];
Length[A]
x=RandomReal[{-1,1},Length[A]];
Timing[Do[y=A.x,{100}];]
Timing[Do[y=LinearSolve[A,x],{1}];]

A= Import["e20r0000.mtx"];
Length[A]
x=RandomReal[{-1,1},Length[A]];
Timing[Do[y=A.x,{100}];]
Timing[Do[y=LinearSolve[A,x],{1}];]

A= Import["e30r0000.mtx"];
Length[A]
x=RandomReal[{-1,1},Length[A]];
Timing[Do[y=A.x,{100}];]
Timing[Do[y=LinearSolve[A,x],{1}];]

A= Import["e40r0000.mtx"];
Length[A]
x=RandomReal[{-1,1},Length[A]];
Timing[Do[y=A.x,{100}];]
Timing[Do[y=LinearSolve[A,x],{1}];]

LinSolTimeData={
{236, 0.012997999999999607`},
{4241,0.22196599999999697`},
{9661,0.53292},
{17281,1.0348419999999985`}
};
ListLogLogPlot[LinSolTimeData,
FrameLabel->{"n","time (Sec)"},
Frame->True,
GridLines->Automatic
]

FileNames[]

Q4 (Automated)

TimeMatrix[FileName_]:= Module[
{A,x,y},
A= Import[FileName];
(* ADense=Normal[A]; May suck up all the memory!  *)
x=RandomReal[{-1,1},Length[A]];
(* Outputs length, and times for sparse mul and sparse solve *)
{Length[A], 
Timing[Do[y=A.x,{100}];][[1]],
Timing[Do[y=LinearSolve[A,x],{1}];][[1]]
}
]

Data=Table[
TimeMatrix[FileName],
{FileName, FileNames[]}
]

ListLogLogPlot[
{Data[[All,{1,2}]],Data[[All,{1,3}]]},
FrameLabel->{"n","time (Sec)"},
Frame->True,
GridLines->Automatic,
PlotLabel->"Driven Cavity Flow family times",
PlotStyle->{Red, Green, Blue}
]

FileNames[]

Hw 2

Here be descriptions.

SetDirectory["/home/campus03/struther/Desktop/Dump/NodeFiles"];
DataTriangle=Take[Import["AClean.1.ele","TABLE"],{2,-2}][[All,{2,3,4}]]
DataNode=Take[Import["AClean.1.node","TABLE"],{2,-2}][[All,{2,3}]]

DotPic=ListPlot[DataNode,
Frame->True,
AspectRatio->Automatic,
PlotStyle->{PointSize[0.02],Red}
]

Show[
Graphics[
Table[
{EdgeForm[Directive[Thick,Black]],
Hue[i/29],
Polygon[
DataNode[[DataTriangle[[i]]]]
]
},
{i, 29}
]
],
DotPic
]

HW 3

n=7;
A= SparseArray[{},{n,n}];
Do[
A[[i,i]]=-2.0;A[[i,i+1]]=1.0;A[[i+1,i]]=1.0,
{i,1,n-1}
]
A[[1,n]]=A[[n,1]]=1.0;
A[[n,n]]=-2.0;
MatrixForm[A]

n=12;
A2= SparseArray[
{
Band[{1,1}]-> -2.0,
Band[{2,1}]-> 1.0,
Band[{1,2}]-> 1.0,
{1,n}->1.0,
{n,1}->1.0
},{n,n}];
MatrixForm[A2]

MakeHw3Matrix[n_]:= SparseArray[
{
Band[{1,1}]-> -2.0,
Band[{2,1}]-> 1.0,
Band[{1,2}]-> 1.0,
{1,n}->1.0,
{n,1}->1.0
},{n,n}]
A3=MakeHw3Matrix[7];
MatrixForm[A3]

ListPlot[Eigenvalues[MakeHw3Matrix[100]],
PlotRange->All]