1+1=```````````````````````````

NBA重磅栏目
新赛季刚开始,库里就令人惊艳…
全新赛季开场,各种惊喜、纪录…
烧钱,新规,看新季诸强百态…
2014年夏天,安东尼选择留守纽约,这份5年1.29亿美元的顶薪合同让安东尼会一直在这里呆到2019年...
那时候,迷恋火箭和姚明的我们就像饿了几个礼拜的流浪汉一样到处觅食,而获取比赛...
技术可以打磨,身体可以锻炼,但是心理关始终是重伤运动员难以逾越的一道坎...
萎靡的奥多姆,醉生梦死,恍如隔世,他太彷徨了,彷徨得飘忽、迷离,灵魂出窍...
像《教父》里大佬们一样,点起雪茄,传承朴素、霸道、坚韧而高傲...
排名球队赢输胜率
排名球队赢输胜率
您为林书豪大胜公牛比赛表现打几分?
您认为湖人是否真的选到了水货榜眼?
NBA球队资料
NBA记录大全
个人荣誉记录MATHEMATICA TUTORIAL, part 1.1
Part 1: Plotting
This tutorial contains many Mathematica scripts. You, as the user, are free to use all codes for your needs, and have the
right to distribute this tutorial and refer to this tutorial as long as
this tutorial is accredited appropriately. I would like to extend my gratitude to all of the students that aided me in
developing this tutorial. The coding, testing, and debugging required a concerted effort, and the
following students deserve recognition for their input: Emmet and Jesse Golden-Marx (Fall 2011), Pawel Golyski (Fall 2012). Any comments and/or contributions for this
you can send your remarks to &&
Part I. Plotting
Plotting functions
Implicit plot
Vertical and horizontal lines
Lables and texts
Pollar plot
Direction fields
tutorial page for the first course
tutorial page for the second course
Return to the (APMA0330)
Return to the
(First Order ODEs)
Return to the
(Numerical Methods)
Return to the
(Second and Higher Order ODEs)
Return to the
(Series and Recurrences)
Return to the
(Laplace Transform)
I. Analytic functions
One of the best characteristics of Mathematica is its plotting ability. It is very easy to plot a variety of functions using Mathematica. For a plot, it is necessary to define the independent variable that you are graphing with respect to. Mathematica automatically adjust
the range over which you are graphing the function.
Plot[2*Sin[3*x]-2*Cos[x], {x,0,2Pi}]
In this command sequence, the independent variable is x and the range is 0 to
\( 2\pi \). For Plot, after entering the function that you wish to graph, you separate the equation and add {independent variable, lower bound, upper bound}.
This is a simple Plot command. In this example, we are just plotting a function using Mathematica default capabilities, but it is possible to specify the range with PlotRange command. The above graph can also be obtained with the following script:
Plot[2*Sin[3*x]-2*Cos[x], {x,0,2Pi}, PlotRange -& Automatic]
For multiple plots, use either command Show or you can use {} with commas:
When you need to restrict the vertical range, use PlotRange command as the following example shows.
Plot[Exp[10*x], {x, -.5, .5}, PlotStyle -& {Black, Thick}, AxesLabel -& {x, Exp[10 x]}]
Plot[Exp[10*x], {x, -.5, .5}, PlotRange -& {0, 10}, PlotStyle -& {Black, Thick}]
II. Plotting discontinuous functions
There are two types of discontinuous functions. There are piecewise functions and functions that are discontinuous at a point. A piecewise function is a function defined by different functions for each part of the range of the entire function. A discontinuous function is a function that has a discontinuity at one or more values mainly because of the denominator of a function is being zero at that points. For example, if the denominator is (x-1), the function will have a discontinuity at x=1.
Using Mathematica, it is easy to plot a piecewise discontinuous function.
An example of a Piecewise function is given below. There are three different functions that have been generated in this graph.
Plot[Piecewise[{{x^2 - 1, x & 1}, {x^3 - 5, 1 & x & 2}, {5 - 2 x, x & 2}}], {x, -3, 5}]
This code is very similar to the Plot command. The only difference is that you add the Piecewise Command and after this command you enter the different components of the piecewise equation and the range for each of these components.
This code creates a graph that shows all three of the different piecewise components over the range of -3 to 5. Piecewise graphing does not create vertical lines at the boundary lines of each of the piecewise components.
Discontinuous Functions can be plotted in Mathematica using the following command sequence.
Plot[1/(x - 1), {x, 0, 2}]
For plotting a function with a point discontinuity, Mathematica will generate a vertical line at the point discontinuity to represent that the value at x=1 goes to infinity.
When you are graphing these kinds of functions, often times, it can be useful to generate a vertical or horizontal asymptote. To do this, you can use the following commands: &&&Plot[c,{x,c1,c2}]&&&&&&& for horizontal asymptotes. In this command, c is the value of the horizontal asymptote and c1 and c2 are the range of the graph.
It is more difficult to graph a vertical line using Mathematica than a horizontal line. One way to do this is:
Plot[0, {x, 1, 3}, GridLines -& {{2}, None}]
In this command sequence, I am telling Mathematica to graph the image x=2 so I just get the vertical line. The range of this function is 1 to 3. Then the command calls for Mathematica to create a straight vertical gridline at x=2. None is part of the command that tells Mathematica to just make it a straight dark, non dashed line.
Let’s plot a piecewise function:
Function is undefined at the points of discontiuity x=1. For plotting a function with a point discontinuity, Mathematica will generate a vertical line at the point discontinuity to represent that the value at x=1 goes to infinity.
f[t_] := Piecewise[{{t^2, 0 & t & 2}, {4 - t, 2 & t & 4}}, 2]
Plot[f[t], {t, 0, 10}, PlotRange -& Full]
The same function with the value of 1 at t=2:
f[t_] := Piecewise[{{Piecewise[{{t^2, 0 & t & 2}, {1, t == 2}}], 0 & t &= 2}, {Piecewise[{{4 - t, 2 & t & 4}, {2, t & 4}}], t & 2}}]
Plot[f[t], {t, 0, 10}, PlotRange -& Full]
To show the discrete value at t=2, we have two options:
pts := ListPlot[{{2, 1}}]
a := Plot[f[t], {t, 0, 10}, PlotRange -& Full]
Show[a, pts]
dp := DiscretePlot[1, {k, 2, 2}]
Show[a, dp]
II. Plotting
The solution to an initial value problem can be plotted as follows
a = DSolve[{y'[x] == -2 x y[x], y[0] ==1}, y[x],x];
Plot[y[x] /.a, {x,-2,2}]
In this command sequence, I am first defining the differential equation that I want to solve. In this line, I define the equation and the initial condition as well as the independent and dependent variables.
In the second line, I am commanding Mathematica to evaluate the given differential equation and plot its result. I then command Mathematica to solve the equation and plot the given result of the initial value problem for the range listed above. Typing these two commands together allows Mathematica to solve the initial value problem for you and to graph the initial value problem's solution.
If you need to plot a sequence of solutions with different initial conditions, one can use the following script:
myODE = t^2*y'[t] == (y[t])^3 - 2*t*y[t]
IC = {{0.5, 0.7}, {0.5, 4}, {0.5, 1}};
Do[ansODE[i] =
Flatten[DSolve[{myODE, y[IC[[i, 1]]] == IC[[i, 2]]}, y[t], t]];
myplot[i] = Plot[Evaluate[y[t] /. ansODE[i]], {t, 0.02, 5}];
Print[myplot[i]]; , {i, 1, Length[IC]}]
In this command, you define the differential equation that you want to solve and the initial conditions (the respective x and y values). Flattening creates a list of the equations. Then you are asking Mathematica to evaluate the different equations according to their different initial conditions.
Finally, the Print command tells Mathematica to plot the graphs and the size that you want the lines on the graphs to be.
When you enter these commands, you may receive a line saying that some of the branches lead to empty solutions, but this just means that DSolve cannot find a unique solution for part of the equation. However, this does not appear to affect the final graph.
To plot a family of solutions:
f1[x_] = x*c + c/Sqrt[c*c + 1]
samples1 = Table[f1[x], {c, -20/3, 8, 1}]
Plot[Evaluate[samples1], {x, -3, 3}, PlotStyle -& {Black}]
In this command, I am plotting a family of solutions to a differential equation. This command is not really any different from a normal plot command. The primary difference is that I have created a list of samples in a table. These samples have the variable c and then I can plug in different values of c to create the values in this table. This means that I am asking Mathematica to plot solutions with different values of the differential constant c. This command will plot a variety of different graphs over the range of c. The command on the second line also yields the different members of this family of equations associated with each value of c.
I can further complicate this problem by plotting a family of solutions to a differential equation along with the singular solution of the Initial Value Problem y' = 2sqrt(y), y(0)=0. To do this, use the following Mathematica code.
q1 = Plot[Evaluate[(x + C[1])^2 /. C[1] -& {0, 1, -1}], {x, -3.5, 3.5}, AxesLabel -& {x, y}]
q2 = Plot[y = x^2, {x, -3.5, 3.5}, PlotStyle -& Thick]
Show[q2, q1]
In this sequence of command, I am first entering the family of differential equations. Since I entered three values of C[1] I will get three graphs, each will be a different color. Then the second command will graph the solution to the initial value problem. By making this line thick, it will be easier for me to distinguish it. The final command graphs all of these curves on one graph.
Plot sine function downward:
data1 = Table[{x, Sin[x]}, {x, -5, 5, 0.1}];
ListLinePlot[data1, PlotRange -& All];
ticks = Table[{-x, x}, {x, -5, 5, .2}];
ListLinePlot[{#, -#2} & @@@ data1, PlotRange -& {All, 1}, Ticks -& {All, ticks}, Axes -& True, PlotStyle -& Thick]
data1 = Table[{x, Sin[x]}, {x, -5, 5, 0.1}];
ListLinePlot[data1, PlotRange -& All];
ticks = Table[{-x, x}, {x, -5, 5, .2}];
ListLinePlot[{#, -#2} & @@@ data1, PlotRange -& {-1.3, 1.3},
Ticks -& {All, ticks}, Frame -& False, PlotRange -& All,
Epilog -& {Text[&x&, {5.5, 0}], Text[&y&, {0, -1.4}]},
PlotRangeClipping -& False, ImagePadding -& {{20, 20}, {20, 20}}]
Now plot with arrows, but without units:
axes[x_, y_, f_, a_] :=
Graphics[Join[{Arrowheads[a]},
Arrow[{{0, 0}, #}] & /@ {{x, 0}, {0, y}}, {Text[
Style[&x&, FontSize -& Scaled[f]], {0.95*x, 0.1*y}],
Text[Style[&y&, FontSize -& Scaled[f]], {0.1 x, 1*y}]}]]
data1 = Table[{x, Sin[x]}, {x, 0, 5, 0.1}];
ListLinePlot[data1, PlotRange -& All];
ticks = Table[{-x, x}, {x, -5, 5, .2}];
Show[ListLinePlot[{#, -#2} & @@@ data1, PlotRange -& {-1.3, 0},
Ticks -& {None, None}, Frame -& False, PlotRange -& All,
PlotRangeClipping -& False, ImagePadding -& {{20, 20}, {20, 20}}],
axes[5.3, -1.33, .06, .05], Axes -& False]
Example. Tractrix (from the Latin verb trahere &pull, drag&; plural: tractrices) is the curve along which an object moves, under the influence of friction, when pulled on a horizontal plane by a line segment attached to a tractor (pulling) point that moves at a right angle to the initial line between the object and the puller at an infinitesimal speed. By associating the object with a dog, the
string with a leash, and the pull along a horizontal line with the
dog's master, the curve has the descriptive name hundkurve (dog curve)
in German. It is therefore a curve of pursuit. It was first introduced by Claude Perrault (1613 -- 1688) in 1670. Trained as a physician, Claude
was invited in 1666 to become a founding member of the French Academie des
Sciences, where he earned a reputation as an anatomist. The first known solution was given by Christian Huygens (1692), who also named the curve the tractrix. Its parametric equation is
x = a sin(t), &&&&y = a (cos(t) + ln(tan(t/2))).
To plot tractrix curve, we use the following code:
tractrix[a_][t_] := a*{Sin[t], Cos[t] + Log[Tan[t/2]]};
Manipulate[
ParametricPlot[tractrix[a][t] // Evaluate, {t, 0, .99*\[Pi]},
PlotRange -& {0, 7}], {a, 1, 6}]
Export["tractrix1.gif",%]
Manipulate[
Plot[y'[x] = -Sqrt[a^2 - x^2]/x, {x, 0, 20},
PlotRange -& {-10, 10}], {a, 0, 20}]
sol = DSolve[{y'[x] == -Sqrt[a^2 - x^2]/x, y[a] == 0}, y, x]
Out[2]= {{y -& Function[{x}, -Sqrt[a^2 - x^2] + a Log[a] - a Log[a^2] -
a Log[x] + a Log[a^2 + a Sqrt[a^2 - x^2]]]}}
Manipulate[
Plot[-Sqrt[a^2 - x^2] + a Log[a] - a Log[a^2] - a Log[x] + a Log[a^2 + a Sqrt[a^2 - x^2]], {x, 0, 20}, PlotRange -& All], {a, 1, 20}]
A cycloid is the curve traced by a point on the rim of a circular
wheel e of radius a rolling along a straight line. It was studied and named by Galileo in
1599. Its curve can be generalized by choosing a point a not on the rim, but at any distance b from the center on a fixed radius. If b=a, we get a usual cycloid.
The Parametrization of the cycloid can be made through the following equations:
cycloid[a_, b_][t_] := {a*t - b*Sin[t], a - b*Cos[t]}
Manipulate[
ParametricPlot[
cycloid[a, b][t] // Evaluate, {t, -\[Pi]/2, 5*\[Pi]/2}], {a, 1, 5}, {b, 1, 5}]
axes[x_, y_, f_, a_] :=
Graphics[Join[{Arrowheads[a]},
Arrow[{{0, 0}, #}] & /@ {{x, 0}, {0, y}}, {Text[
Style[&x&, FontSize -& Scaled[f]], {0.9*x, .15*y}],
Text[Style[&y&, FontSize -& Scaled[f]], {0.07 x, 1*y}]}]]
data1 = Table[{t, cycloid[1, 1][t][[1]], cycloid[1, 1][t][[2]]}, {t,
0, 2 \[Pi], 0.01}];
Show[ListLinePlot[{#2, #3} & @@@ data1,
PlotRange -& {{-\[Pi]/4, 3 \[Pi]}, {0, 3}},
AspectRatio -& Automatic, Ticks -& {None, None}, Frame -& False,
PlotRange -& All, PlotRangeClipping -& False,
ImagePadding -& {{20, 20}, {20, 20}}], axes[9.7, 3.2, .07, .07],
Graphics[{{Dashed, Circle[{0, 1}, 1]}, Point[{\[Pi] + .5, 1}],
Point[{4.123, 1.9}], Circle[{\[Pi] + .5, 1}, 1],
Line[{{0, 0}, {0, 1}}], Point[{0, 0}], Point[{\[Pi]*2, 1}],
Point[{\[Pi]*2, 0}],
Point[{0, 1}], {Dashed, Circle[{\[Pi]*2, 1}, 1]},
Line[{{\[Pi]*2, 0}, {\[Pi]*2, 1}}],
Line[{{\[Pi] + .5, 1}, {4.123, 1.9}}]}]]
Now we plot cycloid downward:
axes[x_, y_, f_, a_] :=
Graphics[Join[{Arrowheads[a]},
Arrow[{{0, 0}, #}] & /@ {{x, 0}, {0, y}}, {Text[
Style[&x&, FontSize -& Scaled[f]], {0.9*x, .08*y}],
Text[Style[&y&, FontSize -& Scaled[f]], {0.1 x, 1*y}]}]]
data1 = Table[{t, cycloid[1, 1][t][[1]], cycloid[1, 1][t][[2]]}, {t,
0, 2 \[Pi], 0.01}];
Show[ListLinePlot[{#2, -#3} & @@@ data1,
PlotRange -& {{-\[Pi]/4, 3 \[Pi]}, {-3, 0}},
AspectRatio -& Automatic, Ticks -& {None, None}, Frame -& False,
PlotRange -& All, PlotRangeClipping -& False,
ImagePadding -& {{20, 20}, {20, 20}}], axes[9.7, -3.2, .07, .07],
Graphics[{{Dashed, Circle[{0, -1}, 1]}, Point[{\[Pi] + .5, -1}],
Point[{4.123, -1.9}], Circle[{\[Pi] + .5, -1}, 1],
Line[{{0, 0}, {0, -1}}], Point[{0, 0}], Point[{\[Pi]*2, -1}],
Point[{\[Pi]*2, 0}],
Point[{0, -1}], {Dashed, Circle[{\[Pi]*2, -1}, 1]},
Line[{{\[Pi]*2, 0}, {\[Pi]*2, -1}}],
Line[{{\[Pi] + .5, -1}, {4.123, -1.9}}]}]]
Now we plot orthogonal curves to cycloid:
axes[x_, y_, f_, a_] :=
Graphics[Join[{Arrowheads[a]},
Arrow[{{0, 0}, #}] & /@ {{x, 0}, {0, y}}, {Text[
Style[&x&, FontSize -& Scaled[f]], {0.9*x, .08*y}],
Text[Style[&y&, FontSize -& Scaled[f]], {0.1 x, 1*y}]}]]
data1 = Table[{\[Tau], Cycloid[1, \[Tau]][[1]],
Cycloid[1, \[Tau]][[2]]}, {\[Tau], 0, 2 \[Pi], 0.01}];
data2 = Table[{\[Tau], Cycloid[1.5, \[Tau]][[1]],
Cycloid[1.5, \[Tau]][[2]]}, {\[Tau], 0, 3.14^2 - 0.6, 0.01}];
data1a = Table[{\[Rho], Cycloid[\[Rho], 2][[1]],
Cycloid[\[Rho], 2][[2]]}, {\[Rho], .3, 10, .01}];
data2a = Table[{\[Rho], Cycloid[\[Rho], 3][[1]],
Cycloid[\[Rho], 3][[2]]}, {\[Rho], .5, 10, .01}];
data3a = Table[{\[Rho], Cycloid[\[Rho], 4][[1]],
Cycloid[\[Rho], 4][[2]]}, {\[Rho], .65, 10, .01}];
Show[ListLinePlot[{#2, -#3} & @@@ data1, AspectRatio -& Automatic,
PlotRange -& {{-\[Pi]/4, 5*\[Pi]}, {-5, 0}},
PlotStyle -& {Black, Thick}, Ticks -& {None, None}, Frame -& False,
PlotRange -& All, PlotRangeClipping -& False,
ImagePadding -& {{20, 20}, {20, 20}}],
ListLinePlot[{#2, -#3} & @@@ data2, PlotStyle -& {Black, Thick},
PlotRange -& {{-\[Pi]/4, 2*\[Pi] + \[Pi]/4}, {-5, 0}},
Ticks -& {None, None}, Frame -& False, PlotRange -& All,
PlotRangeClipping -& False, ImagePadding -& {{20, 20}, {20, 20}}],
ListLinePlot[{#2, -#3} & @@@ data1a,
PlotRange -& {{-\[Pi]/4, 2*\[Pi] + \[Pi]/4}, {-5, 0}},
Ticks -& {None, None}, Frame -& False, PlotRange -& All,
PlotStyle -& {Blue}, PlotRangeClipping -& False,
ImagePadding -& {{20, 20}, {20, 20}}],
ListLinePlot[{#2, -#3} & @@@ data2a,
PlotRange -& {{-\[Pi]/4, 2*\[Pi] + \[Pi]/4}, {-5, 0}},
Ticks -& {None, None}, Frame -& False, PlotRange -& All,
PlotStyle -& {Blue}, PlotRangeClipping -& False,
ImagePadding -& {{20, 20}, {20, 20}}],
ListLinePlot[{#2, -#3} & @@@ data3a,
PlotRange -& {{-\[Pi]/4, 2*\[Pi] + \[Pi]/4}, {-5, 0}},
Ticks -& {None, None}, Frame -& False, PlotStyle -& {Blue},
PlotRange -& All, PlotRangeClipping -& False,
ImagePadding -& {{20, 20}, {20, 20}}], axes[16.5, -5.2, .07, .07]]
For plotting a function with a point discontinuity, Mathematica will generate a vertical line at the point discontinuity to represent that the value at x=1 goes to infinity.
When you are graphing these kinds of functions, often times, it can be useful to generate a vertical or horizontal asymptote. To do this, you can use the following commands:
Plot[c,{x,c1,c2}] for horizontal asymptotes. In this command, c is the value of the horizontal asymptote and c1 and c2 are the range of the graph.
It is more difficult to graph a vertical line using Mathematica than a horizontal line. One way to do this is:
Plot[0, {x, 1, 3}, GridLines -& {{2}, None}]
In this command sequence, I am telling Mathematica to graph the image x=2 so I just get the vertical line. The range of this function is 1 to 3. Then the command calls for Mathematica to create a straight vertical gridline at x=2. None is part of the command that tells Mathematica to just make it a straight dark, non dashed line.
If you're actually using Plot (or ListPlot, etc.), the easiest solution is to use the GridLines option,
which lets you specify the x- and y-values where you want the lines drawn.
Plot[Cos[x], {x, 0, 2 \[Pi]}, GridLines -& {{0, \[Pi]/2, \[Pi], 3 \[Pi]/2, 2 \[Pi]}, {-1, -Sqrt[3]/2, -1/2, 0, 1/2, Sqrt[3]/2, 1}}]
For the case of horizontal lines when using Plot the easiest trick is to just include additional constant functions
Plot[{Cos[x], .75}, {x, 0, 2 Pi}]
For vertical lines, there's the Epilog option for Plot and ListPlot:
Plot[Sin[x], {x, 0, 2 Pi}, Epilog -& Line[{{Pi/2, -100}, {Pi/2, 100}}]]
Plot[Sin[x], {x, 0, 2 Pi}, Epilog -& {Dashed, Line[{{Pi/2, -100}, {Pi/2, 100}}]}] &&&&&&&&&&&&&&(*dashed vertical line *)
Another, perhaps even easier, option would be using GridLines:
Plot[{Cos[x]}, {x, 0, Pi}, GridLines -& {{0.5}, {Pi/2}}, PlotRange -& All]
f[x_] := (x^2 z)/((x^2 - y^2)^2 + 4 q^2 x^2) /. {y -& \[Pi]/15, z -& 1, q -& \[Pi]/600}
Plot[{f[x], f[\[Pi]/15],f[\[Pi]/15]/Sqrt[2]}, {x, \[Pi]/15 - .01, \[Pi]/15 + .01}]
V. Plotting with axes, without axes
There are times when the axes could interfere with displaying certain functions and solutions to ODEs. Fortunately, getting rid of axes in recent versions of Mathematica is very easy.
One method of specifying axes is to use the above options, but there is also a visual method of changing axes.
VI. Implicitplot command
You can use a variety of different plot functions to make graphs. In this command, I will introduce you to contour plot. The contour plot command gives a contour diagram similar to a topographical map for a function.
ContourPlot[3 x^2 + y^2 == 9, {x, -2, 2}, {y, -4, 4},
PlotRange -& {{-2, 2}, {-4, 4}}, AspectRatio -& 1.5/2.1,
ContourStyle-& Green, ContourStyle -& Thickness[0.005],
FrameLabel -& {&x&, &y&}, RotateLabel -& False]&&&&&&&&&&&&&&&&& (* Thickness is .5% of the figure's length *)
After I entered the ContourPlot command, I used a variety of different commands to modify the graph and create a more aesthetically pleasing graph. When you add the added details for plotting, you do not close the ContourPlot command until all of the adjustments have been made.
Plot Range tells me the range that I want to plot. This is different from the x and y ranges before it because those numbers give the ranges that should be used to solve the given equation.
AspectRatio tells me the ratio between the height and the width of the graph. This describes how you want to scales of the x-axis and y-axis to look in comparison with one another.
ContourStyle describes how you want the lines of the contour plot to look.
This command can also be used to change the color of the graph. If you do this, you need to add a second command with ContourStyle like I did above. For the Thickness command, this describes the percent thickness you want of the line, I have it set at .5% of the figure's length *)
FrameLabel tells me what I want to be placed on the borders of the graph. For example, if I was graphing a Potential Energy Function, I could set the vertical frame to say U(x) and the horizontal frame to say x.
RotateLabel tells me whether or not I want to rotate the label that I designated using the FrameLabel Command.
Changing variables:
ans1 = DSolve[{y'[x] == 1/(2*x - 3*y[x] + 5), y[0] == 1}, y[x], x]
Out[1]= {{y[x] -& 1/6 (7 + 4 x - 3 ProductLog[1/3 E^(1/3 + (4x)/3)])}}
Plot[y[x] /. ans1, {x, -1, 1}, PlotRange -& {0.4, 1.5}, AspectRatio -& 1]
Here is the solution to the inverse problem:
ans2 = DSolve[{x'[y] == 2*x[y] - 3*y + 5, x[1] == 0}, x[y], y] // Simplify
Out[3]= {{x[y] -& 1/4 (-7 + E^(-2 + 2 y) + 6 y)}}
Plot[x[y] /. ans2, {y, 0.4, 1.5}, PlotRange -& {-1, 1}, AspectRatio -& 1]
Here is a way to flip the above graph:
ParametricPlot[Evaluate[{x[y], y} /. ans2], {y, 0, 2}, PlotRange -& {{-1, 1}, {0.4, 1.5}}, AspectRatio -& 1]
As you can see, you can practically plot any implicit function using the implicitplot command. Explicit functions can be plotted using the regular plot command.
With[{q = Pi/6},
Graphics[{Circle[{0, 0}, 1, {q, 2 Pi - q}],
Arrowheads[{{.05, .8}}],
Arrow[{{Cos[q] + 2, Sin[q]}, {Cos[q], Sin[q]}}],
Arrow[{{Cos[q], Sin[-q]}, {Cos[q] + 2, Sin[-q]}}],
FontSize -& Medium, Text[&\[ScriptCapitalC]&, {2, Sin[q]}, {0, -2}]},
Axes -& True, PlotRange -& {{-4, 6}, {-2, 2}}]]
If you want the actual function for contour, then maybe something like the following:
contour[t_, t0_: (5 Pi/6)] := Piecewise[{ {Exp[I (t + Pi)], -t0 & t & t0},
{t - t0 + Exp[I (t0 + Pi)], t &= t0}, {-t - t0 + Exp[-I (t0 + Pi)], t &= -t0}}]
ParametricPlot[Through[{Re, Im}[contour[t]]], {t, -8, 8}, PlotPoints -& 30]
Another option:
t0 = ArcSin[c];
PolarPlot[If[Abs[t] & t0, Abs[Sin[t0]/Sin[t]], 1], {t, -\[Pi], \[Pi]},
Epilog -& { Arrow[{{2, c}, {1, c}}], Arrow[{{1, -c}, {2, -c}}], Arrow[{{-1, .1}, {-1, -.1}}],
Text[&C&, {1.5, c + .1}], Text[&C&, {1.5, -(c + .1)}] }]
Label lines:
To see the equation of the line when cursor reaches the graph, use Tooltip command:
Plot[Tooltip[Sin[x]], {x, 0, 8 Pi}]
To put text/title on the picture, use Epilog command:
Plot[Sin[x], {x, 0, 8 Pi}, Epilog -& Text[&My Text&, Offset[{32, 0}, {14, Sin[14]}]]]
(*This line is to display the circuit that we will create:*)
display[Table[rcElement // at[{i, 0}], {i, 0, 17, 3}]]
(* The following line adds a connecting wire for a list of points
within a framework defined by the Map. The Map is defined by the text
and point list. The Text is defined by the Style. *)
connect[pointList_] := {Line[pointList],
Map[Text[Style[&&, FontSize -& 18]] &, pointList[[{1, -1}]]]}
(*The following segment of code is to instantiate each of the
elements that will be used in the circuit. If you wanted to include a
switch or any other new element, this would be the section to add it.*)
gap[l_: 1] := Line[l {{{0, 0}, {1/3, 0}}, {{2/3, 0}, {1, 0}}}]
resistor[l_: 1, n_: 3] :=
Line[Table[{i l/(4 n), 1/3 Sin[i Pi/2]}, {i, 0, 4 n}]]
coil[l_: 1, n_: 3] := Module[{
scale = l/(5/16 n + 1/2),
pts = {{0, 0}, {0, 1}, {1/2, 1}, {1/2, 0}, {1/2, -1}, {5/
16, -1}, {5/16, 0}} },
Append[Table[BezierCurve[scale Map[{d 5/16, 0} + # &, pts]], {d, 0,
BezierCurve[scale Map[{5/16 n, 0} + # &, pts[[1 ;; 4]]]]]]
(*This portion of the code dictates the specifics of the display of
the circuit. In particular, I have a grid with dotted lines.*)
capacitor[l_: 1] := {gap[l],
Line[l {{{1/3, -1}, {1/3, 1}}, {{2/3, -1}, {2/3, 1}}}]}
battery[l_: 1] := {gap[
l], {Rectangle[l {1/3, -(2/3)}, l {1/3 + 1/9, 2/3}],
Line[l {{2/3, -1}, {2/3, 1}}]}}
contact[l_: 1] := {gap[l],
Map[{EdgeForm[Directive[Thick, Black]], FaceForm[White],
Disk[#, l/30]} &, l {{1/3, 0}, {2/3, 0}}]}
Options[display] = {Frame -& True, FrameTicks -& None,
PlotRange -& All, GridLines -& Automatic,
GridLinesStyle -& Directive[Orange, Dashed],
AspectRatio -& Automatic};
display[d_, opts : OptionsPattern[]] :=
Graphics[Style[d, Thick],
Join[FilterRules[{opts}, Options[Graphics]], Options[display]]]
(*This line sets up the framework for adding components to the
circuit at specific positions.*)
at[position_, angle_: 0][obj_] :=
GeometricTransformation[obj,
Composition[TranslationTransform[position],
RotationTransform[angle]]]
(*This generates the specific circuit, which all prior code was \
designed to allow us to do. This is the only part that needs to be \
changed to alter the circuit, providing no new unique elements need \
to be added.*)
label[s_String, color_: RGBColor[.3, .5, .8]] :=
Text@Style[s, FontColor -& color, FontFamily -& &Geneva&,
FontSize -& Large];
battery[] // at[{0, 0}, Pi/2],
connect[{{0, 1}, {0, 2}, {2, 2}}],
resistor[] // at[{2, 2}],
connect[{{3, 2}, {4, 2}, {4, 1}}],
coil[] // at[{4, 0}, Pi/2],
connect[{{4, 0}, {4, -1}, {3, -1}}],
capacitor[] // at[{2, -1}],
connect[{{2, -1}, {0, -1}, {0, 0}}]}]
VIII. Labeling Figures
To write labels on the graph: &&&
fns[x_] := {1 + x^3, 2 + 8*x};
len := Length[fns[x]];
Plot[Evaluate[fns[x]], {x, 0, 6}, Epilog -&
Table[Inset[
Framed[DisplayForm[fns[x][[i]]], RoundingRadius -& 5], {5,
fns[5][[i]]}, Background -& White], {i, len}]]
You can do something similar with Locators that allows you to move the labels wherever you want:
fns[x_] := {Log[x], Exp[2*x], Sin[4*x], Cos[6*x]};
DynamicModule[{pos = Table[{1, fns[1][[i]]}, {i, len}]},
LocatorPane[Dynamic[pos], Plot[Evaluate[fns[x]], {x, 0, 1.8}],
Appearance -&
Table[Framed[Text@TraditionalForm[fns[x][[i]]],
RoundingRadius -& 5, Background -& White], {i, len}]]]
Export[&label2.png&,%]
The Parametrization
cycloid[a_, b_][t_] := {a*t - b*Sin[t], a - b*Cos[t]}
Manipulate[
ParametricPlot[
cycloid[a, b][t] // Evaluate, {t, -\[Pi]/2, 5*\[Pi]/2}], {a, 1, 5}, {b, 1, 5}]
Cycloid[\[Rho]_, \[Tau]_] := {\[Rho]*\[Tau] - \[Rho]^2*
Sin[\[Tau]/\[Rho]], \[Rho]^2*(1 - Cos[\[Tau]/\[Rho]])};
PolarPlot[Cycloid[1.5,theta],{theta, 0, 4*Pi}]
IX. Some famous curves
Antiversiera
For two values of parameters:
a=-2; b=1;
a = 1; b = 2;
we have two graphs:
ContourPlot[ x^4 - 2*a*x^3 + 4*a^2/b^2*y^2 == 0, {x, -5, 2}, {y, -2, 2}, AspectRatio -& Automatic]
&&&&&&&&&&&&
a = 1; n = 3;
PolarPlot[ 2*a*Sin[n*\[Phi]]/Sin[(n - 1)*\[Phi]], {\[Phi], .0001, 2*\[Pi]}]
t = {1, 2, 3, 4};
ContourPlot[(x^2 + y^2 - t^2)^3 + 27*x^2*y^2 == 0, {x, -5, 5}, {y, -5, 5}]
a = {1, 2, 3}; b = {1, 2, 3};
ContourPlot[(x^2 - b*y)^2 + a^2*(y^2 - x^2) == 0, {x, -5, 5}, {y, -1.5, 4.5}, AspectRatio -& Automatic]
b = {0, 1, 2, 3};
ContourPlot[(x^2 + y^2)^2 == b*x^2*y, {x, -1, 1}, {y, -0.2, 1}, AspectRatio -& Automatic]
r = {1, 2, 3};
PolarPlot[2*r*(1 - Cos[\[Phi]]), {\[Phi], 0, 2*\[Pi]}, AspectRatio -& Automatic]
Circular Tractrix
f[r_, th_] := th - ArcTan[Sqrt[4*a^2 - r^2]/r] - Sqrt[4*a^2 - r^2]/r
g[r_, th_] := {r Cos[th], r Sin[th]}
pl = ContourPlot[f[r, th] == 0, {r, 0, 8 Pi}, {th, 0, 4 Pi}, PlotPoints -& 30];
pl[[1, 1]] = g @@@ pl[[1, 1]];
Show[pl, PlotRange -& All, AspectRatio -& 1.5/2]
ContourPlot[ x*(x^2 + y^2) == (r + l)*x^2 - (r - l)*y^2, {x, -1, 5}, {y, -5, 5}, AspectRatio -& 1]
Epicycloid
R = 1; h = 5; r = 2;
PolarPlot[Sqrt[
R^2 + h^2 - 2*(R + r)*h*Cos[R/r*\[Phi]]], {\[Phi], 0, 200*\[Pi]}]
Galileo's Spiral
a=-1;l=10;
PolarPlot[a*\[Phi]^2 - l, {\[Phi], 0, 6*\[Pi]}]
l = {1, 2, 3};
PolarPlot[(l^3*Cos[3*\[Phi]])^(1/3), {\[Phi], -2*\[Pi], 2*\[Pi]}]
ContourPlot[(x^2 + y^2 - 2*a*x)^2 == l^2*(x^2 + y^2), {x, -1,
10}, {y, -7, 7}, AspectRatio -& 14/11]
PolarPlot[a*Cos[k*\[Phi]], {\[Phi], 0, 4*\[Pi]}]
ParametricPlot[{r*(2*Cos[2*t] - Cos[t]), r*(2*Sin[2*t] + Sin[t])}, {t, 0, 10}]
Martha L. Abell, James P. Braselton
Differential Equations With Mathematica,
Academic Press, 2004
Alfred Gray, Mike Mezzino, and Mark Pinsky
Introduction to Ordinary Differential Equations with Mathematica: An Integrated Multimedia Approach
| ISBN-13: 978-
Brian R. Hunt, Ronald L. Lipsman, John E. Osborn, Donald A. Outing, Jonathan Rosenberg
Differential Equations with Mathematica, 3rd Edition
ISBN: 978-0-471-77316-0
Clay C. Ross
Differential Equations
An introduction with Mathematica
Springer-Verlag, 1995
ISBN: 0-387-94301-3
Return to the
(APMA0330)
Return to the
(First Order ODEs)
Return to the
(Numerical Methods)
Return to the
(Second and Higher Order ODEs)
Return to the
(Laplace Transform)

我要回帖

更多关于 cs1.6 的文章

 

随机推荐