Mathematica assignment 1
Mathematica assignment 1
Q 1. Plot the graph of following functions using PlotRange, AxesLabel , PlotStyle and other com-
mands
(i) Sin(x)/x , x€[-300 Pi, 300 Pi]
0.005
Out[1]=
-500 500
-0.005
Using PlotRange:-
2
0.8
0.6
0.4
Out[2]=
0.2
-500 500
-0.2
Using AxesLabel:-
In[3]:= PlotSin[x] x, x, - 300 Pi, 300 Pi, AxesLabel → {- 10, 10}
10
0.005
Out[3]=
-10
-500 500
-0.005
Using PlotStyle:
3
In[4]:= PlotSin[x] x, x, - 300 Pi, 300 Pi, PlotStyle → Green, Thick[0.3]
0.005
Out[4]=
-500 500
-0.005
Observation: The plot of this function show oscillation that decay as x increases. As x->infinity , the
oscillations become smaller and smaller indicating that the function approaches 0.
(ii) Sin(x)/x^2 , x€[-30 Pi,30 Pi]
0.002
0.001
Out[5]=
-50 50
-0.001
-0.002
Using PlotRange:
4
15
10
Out[6]=
-50 50
-5
-10
-15
Using AxesLabels:-
0.002
0.001
Out[7]=
-5
-50 50
-0.001
-0.002
Using PlotStyle:-
5
0.002
0.001
Out[8]=
-50 50
-0.001
-0.002
Observation:-This plot show a similar behavior to first plot but with more rapid oscillations due to
square of sin(x).
Out[9]=
Using PlotRange:-
6
In[11]:=
Using AxesLabels:-
-3
0.5 1.0 1.5 2.0 2.5 3.0
Using PlotStyle:-
7
Observation :- This plot is a linear function combined with oscillations from the sine term. The linear
form dominates, so the graph increases steadily with smaller fluctuations.
0.5
0.4
0.3
0.2
0.1
-10 -5 5 10
Using PlotRange-
8
1.0
0.8
0.6
0.4
0.2
-10 -5 5 10
Using AxesLabel:-
0.5
0.4
0.3
0.2
0.1
15
-10 -5 5 10
Using PlotStyle:-
9
0.5
0.4
0.3
0.2
0.1
-10 -5 5 10
Observation:- This is a bell shaped curve centred at x=0. This function approaches zero as mod of x
approaches infinity.
-10 -5 5 10
-2
-4
Using PlotRange:-
10
In[19]:= PlotSin[1 / x], x * Sin[x], Abs[x] x, {x, - 10, 10}, PlotRange → All
Out[19]=
-10 -5 5 10
-2
-4
-6
Using AxesLabels:-
In[20]:= PlotSin[1 / x], x * Sin[x], Abs[x] x, {x, - 10, 10}, AxesLabel → {20, 10}
Out[20]=
10
20
-10 -5 5 10
-2
-4
Using PlotStyle:-
11
-10 -5 5 10
-2
-4
Observation:- These functions show interesting behavior near x=0. The first function oscillates
rapidly near 0, while second function combines this oscillation with a linear component and third
function is a sign function which is -1 for x<0 and 1 for x>0.
(vi) e^xCos(x)
-3 -2 -1 1 2 3
-2
-4
-6
-8
-10
-12
Using PlotRange:-
12
-3 -2 -1 1 2 3
-5
-10
-15
-20
Using AxesLabel:-
-10
-3 -2 -1 1 2 3
-2
-4
-6
-8
-10
-12
In[25]:=
Using PlotStyle:-
13
-3 -2 -1 1 2 3
-2
-4
-6
-8
-10
-12
Observation:- This function oscillates but grows exponentially as x->infinity leading to a graph that
shows oscillations with increasing amplitude.
Q 2. (i) Plot the graph of polynomial f(x)= x^4+x^3-x+1 and its derivative and second derivative
graphs on the same plane for x€[-10,10].
In[27]:= f[x_] = x ^ 4 + x ^ 3 - x + 1
f1[x_] = D[f[x], x]
f2[x_] = D[f1[x], x]
Out[27]=
1 - x + x3 + x4
Out[28]=
-1 + 3 x2 + 4 x3
Out[29]=
6 x + 12 x2
In[30]:= Plot{f[x], f1[x], f2[x]}, {x, - 10, 10}, PlotStyle → Red, Green, Yellow, Thick[0.5, 0.7, 0.9]
Out[30]=
4000
2000
-10 -5 5 10
-2000
-4000
Observations:-
1. f(x): The original function has a quartic nature. So it will have general "W" or "M" shape depending
14
Q 2. (ii) Plot the graphs of f(x)=x(x-3)(x+3) and g(x)= Cos 2x together on the same set of axes and over
the interval [-20,20]. Use the PlotRange option to adjust the viewing window so that intersection
points are visible.
In[31]:= f[x_] = x (x - 3) (x + 3)
g[x_] = Cos2 x
Plot{f[x], g[x]}, {x, - 20, 20}, PlotStyle → Red, Green, Thick[0.4, 0.6]
Out[31]=
(- 3 + x) x (3 + x)
Out[32]=
Cos2 x
Out[33]=
600
400
200
-20 -10 10 20
-200
-400
-600
Using PlotRange:-
15
In[34]:= Plot[{f[x], g[x]}, {x, - 20, 20}, PlotRange → All, PlotStyle → {Red, Green}]
Out[34]=
5000
-20 -10 10 20
-5000
Observations:-
1. f(x): Red graph
2. g(x) : Green graph
3. Intersection points: between x = -4 to 4
Q 3. Use the animate command to plot the graph of f(x) by varying the parameters a,b,c,d and e for
each of the following functions. Discuss how each parameter affects the shape of graph.
(i) f(x) = ax^2+bx+c
16
In[35]:=
AnimatePlota x ^ 2 + b x + c, {x, - 10, 10}, {a, - 5, 5}, {b, - 5, 5}, {c, - 10, 10}
Out[35]=
40
30
20
10
-10 -5 5 10
Observations:
1. Parameter a controls the curvature of parabola.As a increases , the parabola becomes steeper and
as a decreases, the parabola flips and becomes steeper in opposite direction.
2. Parameter b controls the tilt of the parabola. Positive b values tilt it to left and negative values tilt
it to right.
3. Parameter c controls the vertical shift. Increasing c shifts the graph upward while decreasing it
shift the graph downwards.
-10 -5 5 10
-10 000
-20 000
-30 000
Observations:-
1. Parameter a controls the steepness and concavity of quartic curve. A positive a results in curve
opening upwards while a negative a results in opening curve downwards.
2. Parameter b affects the asymmetry of the graph introducing more complex changes in the slope.
3. Parameter c impacts the curvature similarly to the quadratic case but in combination with higher
order terms.
4. Parameter d affects the linear tilt of the graph.
5. Parameter e shifts the graph vertically.
Q 4. Plot the graph of the following functions using PlotRange, AxesLabel, PlotLabel and other
commands. Discuss how each parameter affects the shape of graph
(i) c+|ax+b|
18
{-20, 20}
15
14
12
10
2
-15
-10 -5 5 10
Observations:-
1. Parameter a controls the slope of the lines forming the V-shape. Increasing a makes the V-shape
steeper while decreasing a flattens the V-shape.
2. Parameter b horizontally shifts the graph. Positive b shifts the graph to left while negative b shifts
it to right.
3. Parameter c vertically shifts the entire graph. Increasing c raises the graph while decreasing c
lowers it.
Q 4 (ii) Sin(ax)
19
{-10, 10}
5
10
-5
-6 -4 -2 2 4 6
-5
-10
Observations:-
1. Parameter a controls the frequency of sine wave. As a increases the wave oscillates more rapidly.
As a decreases the wave oscillates more slowly.
Q 4. (iii) 1/(ax+b)
20
{-10, 10}
5
100
50
-5
-10 -5 5 10
-50
-100
In[40]:=
Observations-
1. Parameter a controls the slope of asymptote. As a increases the steepness of graph around asymp-
tote increases.
2. Parameter b shifts the vertical asymptote horizontally.Increasing b shift it to left while decreasing
b shift it to right.
Q 4. (iv) e^ax
21
{-5, 5}
10
15
4 × 10
15
3 × 10
15
2 × 10
15
1 × 10
-10
-4 -2 2 4
Observations-
1. Parameter a controls the rate of exponential growth or decay.
Q 5. Analyse the effect of shift f(x+a),f(x)+a,f(bx) and bf(x) for the various values of a and b for func-
tion f(x)= Cos x.
(i) f(x+a)
1.0
0.5
-6 -4 -2 2 4 6
-0.5
-1.0
Observations:
Horizontal shift: The parameter a shifts the graph horizontally .Positive values of a shifts the graph to
22
the left while negative value shift it to the right. This is because adding a to x modifies the phase of
cosine wave moving its peaks and troughs through x axis.
(ii) f(x)+a
-6 -4 -2 2 4 6
-2.0
-2.5
-3.0
-3.5
Observations-
Vertical Shift: The parameter a shifts the graph vertically. Increasing a moves the entire graph
upwards while decreasing a shifts the graph downwards.The shape of graph remains same but its
position on y axis changes.
(iii) f(bx)
23
1.0
0.5
-6 -4 -2 2 4 6
-0.5
-1.0
Observations:-
Horizontal stretch/compression: The parameter b controls the frequency of the wave. When b>1 the
graph is compressed horizontally increasing the frequency of oscillations . When 0<b<1 the graph
stretches decreasing the frequency of oscillations. The amplitude of wave remains unchanged.
(iv) bf(x)
1.5
1.0
0.5
-6 -4 -2 2 4 6
-0.5
-1.0
-1.5
Observations:-
Vertical Stretch/compression: The parameter b affects the amplitude of wave. When |b|>1 the graph
24
is stretched vertically making the peaks and troughs more pronounced. When 0<|b|<1 the graph is
compressed vertically reducing the amplitude. Negative values of b reflect the graph about x axis
flipping the troughs and peaks.
Q 6. Show [Plot 1, Plot 2] displays the graphics plot 1, plot 2 on one coordinate system. Use show
command to display the graph of function Sin x, x€[-Pi,Pi] and the points (0,0) ,(Pi/2,Pi),(Pi,0)
together on same set of axes.
In[46]:=
plot2 = ListPlot0, 0, Pi 2, Pi, Pi, 0, PlotStyle → Red, PointSize[Large];
Showplot1, plot2
Out[49]=
Graph of Sin(x)
f(x)
1.5
1.0
0.5
x
-3 -2 -1 1 2 3
-0.5
-1.0
-1.5