On Functional Programming

Initialization cells

Cell | Cell Properties | Initialization Cell

SetDirectory[NotebookDirectory[]]

AppendTo[$Path, ToFileName[NotebookDirectory[]<>"\\Homeworks"]];

Do not forget submitting the data you use.

Path

SetOptions[Plot,AxesStyle->Arrowheads[Automatic]];

?*Gauge*

$Path

Fixed points

NestList[ff,x0,3]

NestList[Cos,-23.6,12]

Nest[Cos,-23.6,12]

FixedPoint[Cos,-23.6]

FixedPointList[Cos,-23.6]

ListPlot[%]

FixedPoint[(Sqrt[#])&,3.]

NestList[(Sqrt[#])&,3,5]

1.//x_->Cos[x]

Euler method

step[{x_,y_}]:={x+h,y+h f[x,y]}

f[x_,y_]:=2y;h=0.1;
NestList[step,{0,2},4]

pl=Plot[2 Exp[2x],{x,0,0.8}]

lp=ListPlot[%31]

Show[lp,pl]

Eratosthenes

erato[n_]:=Join@@Nest[{Append[#[[1]],Min[#[[2]]]],Complement[#[[2]],Min[#[[2]]]Range[(n/(Min[#[[2]]]))]]}&,{{},Range[2,n]},IntegerPart[(Sqrt[n])]]

erato[100]

erato2[n_]:=NestList[{Append[#[[1]],Min[#[[2]]]],Complement[#[[2]],Min[#[[2]]]Range[(n/(Min[#[[2]]]))]]}&,{{},Range[2,n]},IntegerPart[(Sqrt[n])]]

erato2[30]

On Lists

Generation

ClearAll[l1,n,l,e];l1={n,l,e};

l1[[2]]

l2=l1/.{n->{1,2},l->{-1,2},e->{11,2}}

MatrixForm[%]

l2[[3,1]]

l2[[3]][[1]]

Table[i^3,{i,23,27,2}]

Table[i^3,{i,23,27}]

Table[i^3,{i,27}]

Table[1/(i+j-1),{i,3},{j,3}]

HilbertMatrix[3]

Det[%]//N

Array[#^3&,3]

Array[#^3&,3,4]

Array[#1^3-#2&,{3,4}]

Range[23,45,6]

Transformations

Reverse[l1]

Take[l1,2]

Drop[l1,-2]

Reverse[ff[ss,dd,ffj]]

Important special cases

HilbertMatrix

ConstantArray[1,{2,3}]

IdentityMatrix[5]

?*Matrix

Solutions to the homeworks

Everybody

0. Read, modify, use and understand the solutions of the problems given by others. If you do not understand something not even using the help, ask the author or ask me.

Newcomers should solve the first two problems.

1. Find a nice application in demonstrations.wolfram.com, and write down why you like it.

Carlos Henrique Cazagrande

Area between curves

I chose this demonstration because this graphic help to understand different types of curves. Of course I saw a lot of others examples, as I will be a teacher of math in Brazil (at least in the begin of my career), I think Mathematica will help the students to understand areas, graphics, and a bunch of others aplications, because the difficult to understand and to visualize what the teacher is explaining in the mind is the big problem of some areas of math. I hope with Mathematica the students will be more interested to learn.

Xuan

Nice demonstration from demonstrations.wolfram.com
After looking through different demonstrations, I got impressed with the Population Cube demonstration (Link http://demonstrations.wolfram.com/PopulationCube/)
The things I like from this demonstrations are that I easily observe the population of many different countries with their corresponding position on the map. I can also compare populations of two selected countries with the Cube

2. Write a personal introduction into a Mathematica notebook. (Your studies, your experience with either Mathematica, or Maple, Matlab, Origine, Derive, R, Sage, Spyder etc.) If the program is not availabel yet, use TEX, Word or whatever.

Carlos Henrique Cazagrande

As a student of BSc in Mathematics I am interested in learning this program because it will be very useful for my studies and for my career. I don´t have experience with this program or another, but I pretend to do my best to learn. I think with some knowledge in Mathematica I will be a teacher more dynamic, with Mathematica  my future students will understand easier graphics, functions, and a lot of things.

Xuan

My name is Tran Thi Xuan. I am 27 years old. I come from Vietnam. Now I started PhD program at Faculty of Electrical Engineering and Informatics, BME from this semester. My specialization is InfoCommunication System.
I am very new beginner with Mathematic and this is the first time I have learnt and used it. I had a little bit work with R to analysis my used data set. But it was just a particular work.

3. Consult functions.wolfram.com about the trigonometric functions, like sin (or Bessel functions, if you are interested). Cite a statement about the trigonometric functions that  is new for you.

Asli Ummuhan Ileri

Bence Bogdola

As part of my homework I’ve looked up the trigonometric functions at functions.wolfram.com and chose the cosecant trigonometric function as I have not seen it being used during my studies, only heard about it. Upon browsing through the numerous options I found out that this function is in fact the reciprocal of the sine function, explaining why it is not seen commonly. I have also found many charasteristics of this function such as integral, representation, differentation, 2D plots and many more. I believe the website gives as much  information related to functions as possible .

Carlos Henrique Cazagrande

Dávid Horváth

Format

A surprising property of the Bessel-K functions is that they can be defined with the Legendre transform of the cosine hyperbolic of a 
(1/x) lim  1/x type function: (Subscript[K, ν])(z)= 
(Underscript[lim , λ->∞]) (λ^(-ν)) (e^(⋁πi  )) (Subscript[Q, λ]^ν) (cosh((z/λ))) .

István Mester

The connection between trigonometric and Bessel functions:
“Sin(z) and Cos(z) have the following representations through Bessel:

Sin(z)=(Sqrt[((π z)/2)])(Subscript[J, 1/2])(z), Cos(z)=(Sqrt[((π z)/2)])(Subscript[J, -1/2])(z)”

Tamás Mezei

Hyperlink["Product Representations of Function Sine", "http://functions.wolfram.com/ElementaryFunctions/Sin/08/"]

I found the following interesting product representations of the function sine:

sin(z)=z(∏_(k=1)^∞)(1-((z^2)/((π^2)(k^2))))

sin(z)=z(∏_(k=-∞
k≠0)^∞)(1-(z/(π k)))(e^(z/(πk)))

Carsten Olm

Marco Antonio Pederzini Pereira

Sin(z) is an entire analytical function of z which is defined over the complex z-plane

z-> sin(z):: \[ConstantC]-> \[ConstantC]

DomainAndRange[Function[z,Sin[z]]]==Complexes⟶Complexes

Tamás Pölöskei

I didn’t know yet that there are closed form expressions for angles different from the well known ones. ( 0, (π/6), (π/4),(π/3), (π/2),...)

Hyperlink["Values at fixed points","http://functions.wolfram.com/ElementaryFunctions/Sin/03/02/"]

sin((π/9))=-(1/2)(((-1))^(7/18))(-1+(((-1))^(2/9)))

Sin[π/9]//FunctionExpand

Bence Tipary

I looked for the sine function, and found the following statement:

“The following famous infinite product representation for sin(z) clearly illustrates that sin(z)==0 at z=π k Λ k ∈ ℤ:”

"Sin[z]==z(∏_(k = 1)^∞)(1-((z^2)/((π^2) (k^2))))"

Here is the link:

Hyperlink["sine function","http://functions.wolfram.com/ElementaryFunctions/Sin/introductions/Sin/05/"]

Tamás Török

Property of tangent function:

I didn’t know how look like csc (cosecant) function so I look for it. 
I got the following result:

Hyperlink["csc function","http://functions.wolfram.com/webMathematica/Evaluated.jsp?name=Csc&plottype=1&vars={0}&type=0&line=0&free=z&xMin=-2*Pi&xMax=2*Pi"]

Then I looked for what is the connection with tangent function and I searched the following infinite summary of tangent’s square:

Hyperlink["connection between scs and summary of (tan^2)","http://functions.wolfram.com/ElementaryFunctions/Tan/23/02/0002/MainEq1.L.gif"]

András Vértesaljai

Xuan Tran Thi

Lamvan Thanh Binh

4. Show one example for each group in the Fundamental calculations. Use the options of the functions.

Asli Ummuhan Ileri

Bence Bogdola

Fundamental calculations

In this section I am going to show one example for each group in the Fundamental calculations section in the notebook given, also use the options of the functions.

Algebra

index:=Round[RandomReal[{1,10}]];

ClearAll[p]
polyn[p]=(p^index)+(p^index)+index

Factor[polyn[p],Modulus->3]

Calculus

meshing=ConvexHullMesh[RandomReal[{0,0.1},{10000,2}],Method->"Jarvis"]

Differential equations

StreamPlot[{Tan[x],(y^2)+(x^2)-1},{x,-3,3},{y,-3,3},GridLines->None,PlotTheme->"Marketing"]

Limit and extrema

Limit[((E^x)/(x!)), x->Infinity, Direction-> -1]

Linear algebra

matrix:={{1,2,3},{1,4,9},{1,16,81}}

MatrixForm[matrix,TableHeadings->{{Square1,Square2,Square3},{No1,No2,No3}},TableSpacing->{1,5}]

Carlos Henrique Cazagrande

Algebra - Polynomial Functions

a=(1+x)*(1+x+(x^2)+(x^3))

Solve[a==0]

Calculus - Integrate

myIntegrate=Integrate[1/(x^2),x]

Plot[myIntegrate,{x,-8,8}]

Differential Equations

NDSolve[{D[u[t,x,y],{t,2}]==D[u[t,x,y],{x,2}]+D[u[t,x,y],{y,2}]/2+(1-((u[t,x,y])^2))(1+2u[t,x,y]),u[0,x,y]==(E^(-((x^2)+(y^2)))),u[t,-5,y]==u[t,5,y],u[t,x,-5]==u[t,x,5],Derivative[1,0,0][u][0,x,y]==0},u,{t,0,4},{x,-5,5},{y,-5,5}]

%23[[1,1,2]]

Limit

myLimit=Limit[Sin[x]/x,  x->0]

Linear Algebra

m={{1,2,3},{4,3,6},{-3,4,5}}

m//MatrixForm

Det[m]

Dávid Horváth

Algebra

poly=(x^2+3)(x^4-4x^2+3)

Solve[poly==0, x, Integers]

Solve[poly==0, x, Reals]

Solve[poly==0, x, Complexes]

Calculus

ClearAll[f]

f[x_, y_]:= Cos[x]*y^2

NIntegrate[f[x,y], {x, -π/2, π/2},{y, 0,4},Method->{"NewtonCotesRule","Type"->"Open"}]

Differential equations

DSolve[D[y[x1, x2], {x1,2}]-D[y[x1, x2], {x2,2}]==0,y[x1, x2],{x1, x2},GeneratedParameters->(Subscript[c,#]&)]

ClearAll[y]

sol=NDSolve[{x'[t]==y[t],y'[t]==-Sin[x[t]],x[0]==1.2, y[0]== -0.2} ,{x[t], y[t]},{t, 0, 50}, Method->"Adams"]

Plot[Evaluate[x[t]/.sol], {t, 0, 50}]

Limit

Limit[(x-i π/2) Tanh[x+i π/2]/Tanh[x-i π/2], x ->i π/2]

Linear Algebra

m={{Cosh[η], Sinh[η],0}, {Sinh[η], Cosh[η],0},{0,0,1}}//MatrixForm

Eigenvalues[(({{Cosh[η], Sinh[η], 0}, {Sinh[η], Cosh[η], 0}, {0, 0, 1}}))]

Eigenvectors[(({{Cosh[η], Sinh[η], 0}, {Sinh[η], Cosh[η], 0}, {0, 0, 1}}))]

István Mester

Algebra

Separate the polynomial thats not given in axpanded form:

MonomialList[(((x-1))^9)]

Reduced coefficents to modulo 3:

MonomialList[(((x-1))^9),x,Modulus->3]

Calculus

NIntegrate[Csch[2/Sin[(x^2)]],{x,-2,2}]

NIntegrate[Csch[2/Sin[(x^2)]],{x,-2,2},WorkingPrecision->30]

Block[{k=0},{NIntegrate[Csch[2/Sin[(x^2)]],{x,-2,2},WorkingPrecision->30,EvaluationMonitor:>k++],k}]

Plot[Csch[2/Sin[(x^2)]],{x,-2,2}]

Plot[{Csch[2/Sin[(x^2)]],Csch[3/Sin[(x^2)]]},{x,-2,2},Filling->Axis,FillingStyle->Automatic]

Differential equations

Lord Rayleigh’s model for the oscillation of a clarinet is:
m(Overscript[x, ..])+kx=a(OverDot[x])-b((OverDot[x])^3)
Solving it in the form of first order system of ODE’s:

f1={y,(-k x+a y-b (y^3))/m};

data={m->1,k->1,a->2,b->3,T->10,h->4/100};

init={x0->0.5,y0->0.5};

sol=NDSolve[{x'[t]==(f1[[1]]/.x->x[t]/.y->y[t]/.data),
y'[t]==(f1[[2]]/.x->x[t]/.y->y[t]/.data),
x[0]==x0/.init,
y[0]==y0/.init},
{x,y},{t,0,T/.data},MaxSteps->Infinity,Method->"ExplicitRungeKutta"];

ParametricPlot[Evaluate[{x[t],y[t]}/.sol],{t,0,T/.data},PlotStyle->{Directive[Red,Thickness[0.003]]},PlotRange->{{-2,2},{-1.5,1.5}},AspectRatio->3/4,AxesLabel->{Style["x",16],Style["y",16]},LabelStyle->Directive[Medium,11],AxesStyle->Arrowheads[{0.05}]]

Limit and extrema

Limit[(1-Cos[x])/(x^2), x->0]

Limit[(a-Cos[x])/(x^2), x->0,Assumptions->a>1]

Limit[(a-Cos[x])/(x^2), x->0,Assumptions->a<1]

Linear algebra

ma={{1,3,5,0},{5,2,0,5},{7,1,2,0},{1,0,0,9}};
ma//MatrixForm

Tr[Inverse[ma.ma,Method->"CofactorExpansion"]];

Tamás Mezei

Algebra

RuleCoeffs={a0->20, a1->10, a2->8, a3->6, a4->4, a5->0.5};

Pol=((a0+a1 x)/(x+a0))+a2 (x^2)+((a3 (x^3)+a4 (x^4))/(x-a0));

NewPol=Pol/.RuleCoeffs

Together[NewPol]//FullSimplify

solpol=Solve[Denominator[Together[NewPol]]==0, x]

Plot[NewPol, {x, -60, 80}, Exclusions->{20, -20}]

Plot[NewPol, {x, -22, -18}, Exclusions->{20, -20}, ColorFunction->ColorData["SunsetColors"]]

Calculus

Func=(e^(x^2));

D[Func]

Integrate[Func, x]

Plot[Erfi[x], {x, -5, 5}, PlotLabel->"Imaginary Error Function"]

Differential equations

DSolve[{x'[t]==2x[t]+2y[t], y'[t]==x[t]-y[t]}, {y[t], x[t]}, t, GeneratedParameters->xxx]//FullSimplify

Limit and extrema

Limit[((n/x)/((n^7)-n x)), n->Infinity, Assumptions-> x>0]

Limit[((n/x)/((n^7)-n x)),n->Infinity, Assumptions-> x==0]

Limit[((n/x)/((n^7)-n x)),n->Infinity, Assumptions-> x<0]

Maximize[((n/x)/((n^7)-n x)), n]

Linear algebra

matr=Table[Table[RandomInteger[{-10, 10}], {3}], {3}];

matr//MatrixForm

Det[matr]

ListPlot3D[N[Eigenvectors[matr]], Mesh->Full, ColorFunction->"FuchsiaTones"]

Carsten Olm

Marco Antonio Pederzini Pereira

Tamás Pölöskei

Algebra

Block[{s=0},{FindRoot[x==Tan[x],{x,6},StepMonitor:>s++],s}]

Block[{s=0},{FindRoot[x==Tan[x],{x,6},DampingFactor->0.5,StepMonitor:>s++],s}]

Calculus

ClearAll[f,x]
f[x_]:=(E^(Sin[x]))

NIntegrate[f[x],{x,0,10},Method->"AdaptiveMonteCarlo",PrecisionGoal->3]

NIntegrate[f[x],{x,0,10},Method->{"RiemannRule","Type"->"Right"},PrecisionGoal->3]//Quiet

Plot[f[x],{x,0,10}]

Differential equations (Lotka-Volterra)

eqs = {x'[t]==x[t] (α-β y[t]),y'[t]==-y[t](γ-δ x[t])};
ics = {x[0]==5,y[0]==5};
params = {α->1.5,β->1,γ->3,δ->1};

eqs/.params

Trun = 3.52;
sol1 = NDSolve[Flatten[{eqs/.params,ics}],{x,y},{t,0,Trun}];
plot1 = ParametricPlot[Evaluate[{x[t],y[t]}/.sol1],{t,0,Trun},GridLines->Automatic,PlotStyle->Thick,ColorFunction->Function[{x,y,u},Hue[u]]]

Manipulate[StreamPlot[{x (α-β y),-y(γ-δ x)},{x,0,10},{y,0,10}],{{α,1.5},0,5,0.5},{{β,1},0,5,0.5},{{γ,3},0,5,0.5},{{δ,1},0,5,0.5}]

Limit

Hyperlink["Natural logarithm","http://functions.wolfram.com/ElementaryFunctions/Log/09/0001/"]

Limit[(((z^ϵ)-1)/ϵ),ϵ->0]

Linear algebra

M=RandomReal[{-10,10},{3,3}]
Eigenvalues[M]
Eigenvectors[M]

Det[M]

Bence Tipary

Algebra

Solution for third order polynomial (and for its special cases)

sol=Solve[a (x^3)+b (x^2)+ c x + d ==0,x,MaxExtraConditions->2]

Calculus

Definite integrale of the hyperbole

Integrate[(1/x),{x,x1,x2}]

Integrate[(1/x),{x,x1,x2},GenerateConditions->False]

Differential equations

Solution of a differential equations

DSolve[y'[x]==y[x]*x+5x,y[x],x, GeneratedParameters->c]

With initial condition:

dsol=DSolve[{y'[x]==y[x]*x+5x,y[0]==2},y[x],x]

Plot[Evaluate[y[x]/.dsol], {x,-1,1},PlotRange->All,PlotLegends->{y[x]/.dsol}]

Limit and extrema

Minima of the second order polynomial

min=Minimize[a (x^2)+b x + c,x]

For positive coefficients:

Simplify[min,Assumptions->{a>0,b>0}]

Linear algebra

Matrix decomposition to symmetric and antisymmetric part

m={{a,b,c},{d,e,f},{g,h,i}};
%//MatrixForm

Transpose[m];
%//MatrixForm

sm=(1/2)(m+Transpose[m]);
%//MatrixForm

asm=(1/2)(m-Transpose[m]);
%//MatrixForm

m==Simplify[sm+asm]

Tamás Török

Algebra

I would like to now the all coefficient of the following polinom:

ClearAll[f]

f=((x^3)+7x*(x^2)-4)*(3+4x+7(x^3))*((6/2)*(x^2)-4(x^3))

MonomialList[f]

As control, I expand the f polinom

Expand[f]

Calculus

I check the following function double derivate then double integrate is the same function

g[x_]=((E^(x^2))+(x^4)*6*x)

dg=D[g[x],x]

ddg=D[dg,x]

dg2=Integrate[ddg,x]

g2=Integrate[dg2,x]

Simplify[%]

Equal[g2==g]

Differential equations

I would like to evaulate my math exam’s example :)

DSolve[x*y'[x]+y[x]==4x,y[x],x]

Limit and extrema

Limit[Log[(x^2)]/(x+1),x->-1]

As control:

Plot[Log[(x^2)]/(x+1),{x,-2,1}] (*why isn't a hole in the function at -1*)

Linear algebra

m={{21,24,21},{12,41,31}}

MatrixForm[m]

Import

SetDirectory[NotebookDirectory[]]

Erasmus=Import["Tamas_Torok03.xls"](*too big table*)

TableForm[%]

András Vértesaljai

Xuan Tran Thi

4. Example for each group in Fundamental calculations

Algebra

NSolve[{x^2 +2y == 3,x-5y==1},{x,y},Reals]

Calculus

diffcal =D[x/Log[x],x]

Differental Equations

Clear[z]

DSolve[{z'[x]==1,z[0]==0},z[x],x]

Limit and extrema

({{Minimize[x^4 - x^3 +5x+ 2,x ]}, {\[Placeholder]}})

Linear Algebra

?RandomInteger
mymatrix=RandomInteger[{1,10},{4,4}]

Det[mymatrix]

MatrixForm[mymatrix]

Lamvan Thanh Binh

(* Problem 4: Show one example for each group in the Fundamental calculations.Use the options of the functions. *)
poly=xx^2+5*xx+7
Result=Solve[poly==0]
Solve[poly==xx^3+4,xx]

lambda=2.;
n=6;
nu=1/30;
evec = Table[1,{i,1,n}];
MatrixA=SparseArray[{{i_,j_}/;i-j==1->2*j,{i_,j_}/;j-i==1->lambda},{n,n}];
MatrixB=SparseArray[{n,n}->lambda,{n,n}];
MatrixC=SparseArray[{i_,j_}/;j-i==1->nu,{n,n}];
MatrixDBA=DiagonalMatrix[MatrixA.evec]+MatrixB-MatrixA;
Print[MatrixForm[MatrixA]];
Print[MatrixForm[MatrixB]];
Print[MatrixForm[MatrixC]];
Print[MatrixForm[MatrixDBA]];
Print[Det[MatrixDBA]];

Advanced problems

5. Give a neat (streamlined) solution for the numerical integration problem (choose any method).

Asli Ummuhan Ileri

Bence Bogdola

To solve this task I’ve looked up the numerical integration methods and chose the composite rule (also known as extended rule or iterated rule) to solve.

ClearAll[a,b,n,Funct];
Funct[x_]:=(x^2);
NumInteg[a_,b_,n_]:=((b-a)/n)(((Funct[a]+Funct[b])/2)+(∑_(k=1)^(n-1))Funct[a+k((b-a)/n)])//N

NumInteg[-2,2,100]

NumericInt[Func_,c_,d_,e_]:=((d-c)/e)(((Func@c+Func@d)/2)+(∑_(k=1)^(e-1))Func@(c+k((d-c)/e)))//N

NumericInt[Function[z,(z^2)],-2,2,5]

NumericInt[#^2&,-2,2,5]

Carlos Henrique Cazagrande

Dávid Horváth

István Mester

Previously made (last semester) for a differential equation course.
Explicit Euler method, can be used to solve a 2D system of ODE’s:

f1={y,(-k x+a y-b (y^3))/m};

data={m->1,k->1,a->2,b->3,T->10,h->4/100};

init={x0->0.5,y0->0.5};

NDSolveEE[f_,x0_,y0_,h_,t_]:=Module[
{sol},
sol=Table[{0.,0.},{(t/h)}];
sol[[1]]={x0,y0};
Do[sol[[i]]=sol[[i-1]]+h f/.{x->sol[[i-1,1]],y->sol[[i-1,2]]}
,{i,2,(t/h)}];
sol]

ndEE=NDSolveEE[f1/.data,x0/.init,y0/.init,h/.data,T/.data];//AbsoluteTiming

ndEEPlot=Table[{ndEE[[i,1]],ndEE[[i,2]]},{i,1,Length[ndEE]}];
ListPlot[ndEEPlot,PlotStyle->Black,PlotRange->{{-2.,2.},{-1.5,1.5}},AspectRatio->3/4,AxesLabel->{Style["x",16],Style["y",16]},LabelStyle->Directive[Medium,11],AxesStyle->Arrowheads[{0.05}]]

Tamás Mezei

Carsten Olm

Marco Antonio Pederzini Pereira

Tamás Pölöskei

Arbitrary function

ClearAll[f,x]
f[x_]:=E^(Sin[x])

Start of the interval of integration

xSTART = 0;

End of the interval of integration

xEND = 10;

Takes the value of the function in the middle of the subinterval
Numerical integration stepsize : Δx

Manipulate[Total[Table[f[x] Δx,{x,xSTART+((Δx)/2),xEND-((Δx)/2),Δx}]],{Δx,0.001,1,0.001}]

Bence Tipary

Consider the following function:

f[x_]:=(((((Sin[x])/x)))^2)
Plot[f[x],{x,-3π,3π},PlotRange->All]

The numerical integral of the function in the whole domain:

NIntegrate[f[x],{x,-∞,∞}]

The result using the Rieman rule:

NIntegrate[f[x],{x,-∞,∞},Method->{"RiemannRule","Type"->"Right"},PrecisionGoal->2]

Tamás Török

András Vértesaljai

Xuan Tran Thi

g[x_,y_] := x^2 + y^2 -4x -2y

NIntegrate[g[x,y],{x,-2,2},{y,-2,2}]

Lamvan Thanh Binh

(* Problem 5: Give a neat solution for the numerical integration problem *)
Function[Integrate[x^2/(x^3+1),x]]
Integrate[x^2/(x^3+1),x]
Integrate[x^2/(x^3+1.),{x,1,5}]
NIntegrate[x^2/(x^3+1),{x,1,5}]
NIntegrate[x*Sin[x]/(Sin[x]+Cos[x]),{x,0,Pi/2}]
Print["==========================================="];

6. Find a data file in EXCEL form on the net or use your own data being collected in an EXCEL file, Import it, and create a nice table using the options of Import (without string manipulations).

Asli Ummuhan Ileri

Bence Bogdola

SetDirectory[NotebookDirectory[]]

imported=Import["BenceBogdola03.xlsx"]

TableForm[imported]

Options[Import]

Import["BenceBogdola03.xlsx","Elements"]

Import["BenceBogdola03.xlsx","FormattedData"]

Import["BenceBogdola03.xlsx","Images"]

How have you created the EXCLE file?

Carlos Henrique Cazagrande

Dávid Horváth

István Mester

Measurement data of a water pump (the measurement was taken by me):

data6 = SystemDialogInput["FileOpen", WindowTitle -> "Válassza ki a táblázatot"];

table=Import[data6,"Data"];

Grid[Transpose[table[[1]]],Frame->All,ItemSize->{7.5,1.5},ItemStyle->{Automatic,{Directive[14,Red,Bold]}},Background->{{LightBlue,None},{LightBlue,None}}]

Tamás Mezei

Carsten Olm

Marco Antonio Pederzini Pereira

Tamás Pölöskei

Hyperlink["Relative earnings (Search:Salary)","http://www.oecd.org/statistics/"]

Relative earnings of workers, by educational attainment and gender
25-64 year-olds with income from employment
Tertiary education

SetDirectory[NotebookDirectory[]];

(* Import["Tamas_Poloskei_03_RELATIVE.csv","List"]; *)
(* Import["Tamas_Poloskei_03_RELATIVE.csv","Table"]; *)
(* Import["Tamas_Poloskei_03_RELATIVE.csv","String"]; *)

Using the previous import options the result is not that “nice”.

import1 = Import["Tamas_Poloskei_03_RELATIVE.csv"];
TableForm[import1[[All,{2,3}]],TableHeadings->{import1[[All,1]],{"Men","Women"}}]

Bence Tipary

Importing the Excel file : "BenceTiparyhw03.xlsx" which contains the points scored by Jason Kidd (Dallas Mavericks) in the NBA season 2010-2011 with the date of the matches:

xls = SystemDialogInput["FileOpen"];
SystemOpen[xls]
data = Import[xls, "Data"];

Creating new table:

n=Length[data[[1,All,1]]]-1;
k=5;
TableForm[Transpose[Table[{Join[{data[[1,1]]},Delete[data[[1]],1][[IntegerPart[(n/k)(l-1)+1];;IntegerPart[(n/k)l]]]]},{l,1,k}]]]

Tamás Török

SetDirectory[NotebookDirectory[]]

table=Import["Tamas_Torok03b.xls"]

TableForm[table]

Dimensions[table]

table[[1]]

TableForm[Transpose[table[[1]]]]

TableForm[table[[1]]]

TableForm[Transpose[table],TableDirections->Row]

András Vértesaljai

Xuan Tran Thi

SetDirectory[NotebookDirectory[]]
myimport = Import["MathBrasil.xlsx"]
TableForm[myimport[[1]]]

Lamvan Thanh Binh

SetDirectory[NotebookDirectory[]];
res=Import["Lam06.xlsx"];
Import["Lam06.xlsx","Elements"];
res[[1]]//TableForm


Print["==========================================="];

7. Write a program to apply Eratosthenes’ sieve for obtaining primes between 1 and 100.

Asli Ummuhan Ileri

Bence Bogdola

Due to shortage of time, I was not able to complete this task even though I had several attempts, but I have found a complete solution while searching for functions to help my case.

Attempts

These are my failed attempts, I will return to them, but I had to submit the tasks because of the deadline.

ClearAll[primes1to100];
primes1to100:=Range[2,100];

PrimeQ[primes1to100]

Max[primes1to100]

primes1to100

(*If[PrimeQ[primes1to100[[num]]],Delete[primes1to100,num*i],None]*)

primes:=For[num=2,num≤99,num++,If[PrimeQ[primes1to100[[num]]],For[i=2,num*i≤100,i++,ReplacePart[primes1to100,num*i->"0"]],None]]

TableForm[primes]

(*For[num=2,num≤100,num++,If[PrimeQ[primes1to100[[num]]],For[i=2,num*i≤100,i++,Delete[primes1to100,num*i]],None]]*)

(*primenum:=For[num=2,num≤100,num++,If[PrimeQ[primes1to100[[num]]],For[i=2,num*i≤100,i++,ReplacePart[primes1to100,num*i->0]],None]]*)

primenum:=If[PrimeQ[primes1to100[[4]]],For[i=2,i*4≤100,i++,ReplacePart[primes1to100,primes1to100[[4]]*i->0]],None]

primenumb:=If[PrimeQ[primes1to100[[4]]],ReplacePart[primes1to100,{(primes1to100[[4]]*3)-1->"NaP",(primes1to100[[4]]*2)-1->"NaP"}],None]

numbers2to100:=Range[2,100];

primenums:=Module[{num=2,i=2,primenums,NaP},[Return[primenums]]]]

Complete solution

primenumbers[n_]:=Module[ {t,P,i=1,x},t=N[Sqrt[n]];P=Range[2,n];While[ P[[i]] ≤ t,x=Table[k P[[i]],{k,P[[i]], Floor[n/P[[i]]]}];P=Complement[P,x];i++];"name"->P]

Return is not needed.

primenumbers[100]

2 "name"+1/.%82

Carlos Henrique Cazagrande

Dávid Horváth

István Mester

The code has already been written, it is in the previous homework (copied here):

n=100;

num=Table[i,{i,1,n}];

Do[switch=0;
If[num[[j]]≠0,
Do[If[switch<2,If[Mod[num[[j]],num[[i]]]==0,switch++]],{i,1,j-1}]];
If[switch==1,Do[num[[k]]=0,{k,2*j,n,j}]],
{j,2,n}]//Quiet

primes=DeleteCases[num,0];

TableForm[primes[[2;;]],TableDirections->Row,TableHeadings->{Range[1,Length[num]],None}]

Unfortunately this code is computationally intensive on larger domains (> 10000).

Tamás Mezei

List of Primes

ClearAll[Excluder, Numbers];

IntervalFrom1=100; (*Variable to change!*)

ListAll=Table[i, {i, IntervalFrom1}];

ExcludedElements=ReplacePart[ListAll, 1->0];

Excluder[pos_]:=If[ExcludedElements[[pos]]≠0, ExcludedElements[[Table[pos(j+1), {j, 1, Floor[(IntervalFrom1/pos)-1]}]]]=0]

Excluder/@ListAll;

PrimeList=Complement[ExcludedElements, {0}]

Checking=TrueQ[Prime[Range[1,Length[PrimeList]]]==PrimeList]

Graphic Display

InitialRect[pos_]:=Graphics[{EdgeForm[{Thick}],Opacity[0], Rectangle[{If[IntegerQ[(pos/BreakLineAt)], (BreakLineAt-0.5), ((pos-BreakLineAt Floor[(pos/BreakLineAt)])-0.5)], (-Ceiling[(pos/BreakLineAt)]-0.5)}, {If[IntegerQ[(pos/BreakLineAt)], (BreakLineAt+0.5), ((pos-BreakLineAt Floor[(pos/BreakLineAt)])+0.5)], (-Ceiling[(pos/BreakLineAt)]+0.5)}]}];

BreakLineAt=10; (*Number of elements in a row*)

Numbers[pos_]:=Graphics[Text[pos, {If[IntegerQ[(pos/BreakLineAt)], BreakLineAt, (pos-BreakLineAt Floor[(pos/BreakLineAt)])], -Ceiling[(pos/BreakLineAt)]}]];

RedRect[pos_]:= If[ExcludedElements[[pos]]==0, Graphics[{Red,Opacity[0.8], Rectangle[{If[IntegerQ[(pos/BreakLineAt)], (BreakLineAt-0.5), ((pos-BreakLineAt Floor[(pos/BreakLineAt)])-0.5)], (-Ceiling[(pos/BreakLineAt)]-0.5)}, {If[IntegerQ[(pos/BreakLineAt)], (BreakLineAt+0.5), ((pos-BreakLineAt Floor[(pos/BreakLineAt)])+0.5)], (-Ceiling[(pos/BreakLineAt)]+0.5)}]}], Graphics[{Opacity[0], Point[{1,-1}]}]];

ShowGraphics=Show[RedRect/@ListAll,  InitialRect/@ListAll, Numbers/@ListAll]

Carsten Olm

Marco Antonio Pederzini Pereira

Tamás Pölöskei

It is enough to check the numbers of the list containing the possible prime numbers until the square root of the upper limit.

The number 1 is “crossed out” manually, because it would give a false result.

pEND = 100;
primes = Flatten[{0,Range[2,pEND]}];
For[n=2,n≤Floor[(Sqrt[pEND])],n=n+1,If[primes[[n]]≠0,primes[[Range[2 n,pEND,n]]]=0]]
Flatten[SparseArray[primes]["NonzeroPositions"]]

primes = Flatten[{0,Range[2,pEND]}];
For[n=2,n≤pEND,n=n+1,If[primes[[n]]≠0,primes[[Range[2 n,pEND,n]]]=0]]
Flatten[SparseArray[primes]["NonzeroPositions"]]

Bence Tipary

Definining a table consists of the first hundred integer (starting from 2)

primes=Table[p,{p,2,100}];
newprimes=primes;

Finding prime numbers by applying Eratosthenes’ sieve:

Manipulate[If[p=="reset",newprimes=primes,Do[If[Divisible[newprimes[[q]],p]&&newprimes[[q]]≠p,newprimes[[q]]=x,None],{q,1,99}]];newprimes,{p,{"reset",2,3,5,7,9,11}},ControlType->Setter]

Tamás Török

András Vértesaljai

Xuan Tran Thi

Description of Eratosthenes’ sieve - Step by step:
1.Create a list of consecutive integers from 2 through n: (2, 3, 4, ..., n).
2. Initially, let p equal 2, the first prime number.
3. Starting from p, enumerate its multiples by counting to n in increments of p, and mark them in the list (these will be 2p, 3p, 4p, etc.; the p itself should not be marked).
4. Find the first number greater than p in the list that is not marked. If there was no such number, stop. Otherwise, let p now equal this new number (which is the next prime), 
   and repeat from step 3.

Program:

n =100
mylist = Range[2,n]
droplength = Length[mylist]
myprimelist = Range[0]
p=2
For[i=p,i≤droplength,i++,
	If[Mod[i,p]==0 ,
{mydroplist = Delete[mylist,{i}],droplength= Length[mydroplist]}]
]
Append[myprimelist,p]
p=mydroplist[[1]]

It does not work to the end of program. Please help me to check the errors.

Lamvan Thanh Binh

(* First solution *)
t0=TimeUsed[];
ClearAll;
MatrixA=Table[1,{100}];

For[i=2,i≤Sqrt[100],i++,
If[MatrixA[[i]]==1,
k=0;
j=0;
While[j<=100,
j=i^2+k*i;
If[j≤100,
k=k+1;
MatrixA[[j]]=0;
]
]
]
]
ListOfPrime={};
For[i=1,i≤100,i++,
If[MatrixA[[i]]==1,
ListOfPrime=AppendTo[ListOfPrime ,i];
]
]

Print["First Solution: ",ListOfPrime];
t1=TimeUsed[];
Print["Time Uses is: ",t1-t0, " seconds"]

(* Second solution *)
Grid[Partition[If[PrimeQ[#],Framed[#],#]&/@Range[100],10]]

Print["==========================================="];

Reamarks

Wikipedia

Input:an integer n>1

Let A be an array of Boolean values,indexed by integers 2 to n,initially all set to true.for i=2,3,4,...,not exceeding √n:if A[i] is true:for j=i2,i2+i,i2+2i,...,not exceeding n:A[j]:=false

Output:all i such that A[i] is true.

Array[True&,7,2]

era[n_]:=Module[{},A=Array[True&,n+1,2];For[i=2,i≤(Sqrt[n]),i++,If[A[[i]],For[j=(i^2),j≤n,j+=j+i,A[[j]]=False]]];Select[Range[2,n],A[[#]]&]]

era[99]

A

New homeworks

Everybody

Consider a 3×4 matrix and conctruct the one obtained from it by a 90 degree rotation.

Using a positive definite matrix (how do you check this property) define a new scalar product.

Beginners

Construct a Vandermonde matrix from a list of real numbers, and calculate its determinant.

Study FoldList and show an application.

Calculate the first ten powers of 2 using NestList.

Advanced

Calculate GCD using functional programming tools based on the euclidean algorithm.

Write a program for the Runge-Kutta method. Try to get the same results what you have obtained in the case of a concrete problem using the options of NDSolve.

Write another FoldList which takes the composition in its second variable.