Introduction to Mathematica
For Math 76, Mathematical Analysis II
Remember to use Shift + Enter to process your inputs.
Graphs of exponential and logarithmic functions
Plot the graphs of the exponential and logarithmic functions with base 1.5, that is, 1.5x and log1.5x, on the same coordinate system, e.g. type
Plot[{1.5^x, Log[1.5,x]}, {x,-10,10}]. You get some error messages. Why?
It is hard to see how the two graphs are related because the range of y is different from that of x. To make the graph easier to study, try
Plot[{1.5^x, Log[1.5,x]}, {x,-10,10}, PlotRange->{-10,10}, AspectRatio->1].
Notice that the two graphs are reflections of each other about the line y=x.
Exercise: Add the line y=x to the above graphs.
Limits and indeterminate forms
Consider the limit
It is an indeterminate form of type 0/0. There are several approaches (some of which were discussed in Math 75). First define Define f[x_]=(x+Tan[x])/Sin[x];
- Look at the values of f(x) as x becomes closer and closer to 0. To find the values of f(x) at several values of x, type f[{1, .5, .1, .05, .01, .005}], or, for numerical
answers, use N[f[{1, .5, .1, .05, .01, .005}]]. Can you guess the value of the limit?
- Use the command Limit[f[x],x->0].
- Plot the graph of the function, say, from -1 to 1: Plot[f[x],{x,-1,1}].
- Finally, use L'Hospital's Rule. Find the derivatives of the numberator and the denominator:
D[x+Tan[x],x] - get answer1;
D[Sin[x],x] - get answer2;
Now simplify: Simplify[answer1/answer2] - get answer3;
(Of course, you can do the above in one step: Simplify[D[x+Tan[x],x]/D[Sin[x],x]].)
Evaluate the limit of answer3 as x approaches 0 without using Mathematica.
Exercise: Explore and compute the following limits:
Note: For x approaching infinity, type x->Infinity.
Indefinite integrals
To find the indefinite integral (an antiderivative) of a function f(x), use Integrate[f[x],x].
Exercise: Try the following and explain the results you get:
Integrate[E^x,x]
Integrate[e^x,x]
Exercise: Evaluate the following integrals by hand first and then use Mathematica to check your answers:
Definite integrals
To evaluate the definite integral of a function f(x) from a to b, use Integrate[f[x],{x,a,b}], or NIntegrate[f[x],{x,a,b}] to get a numerical answer.
For example, Integrate[Cos[x],{x,1,2}] gives sin(2)-sin(1), and NIntegrate[Cos[x],{x,1,2}] gives 0.0678264.
Exercise: Evaluate the following integrals by hand first and then use Mathematica to check your answers:
Not all functions can be integrated
in the sense that for some functions, their antiderivatives can not be expressed in terms of elementary functions (power, exponential, log, trig, inverse trig...). Definite integrals, can,
of course, still be estimated if interpreted in terms of areas, and sufficiently many thin rectangles are used (recall the definition of the definite integral!)
Exercise: Try the following and explain the relults you get:
Integrate[E^Sin[1/x],x]
NIntegrate[E^Sin[1/x],{x,1,2}]
NIntegrate[E^Sin[1/x],{x,0,2}]. To explain the warning messages, try graphing the function from 0 to 2.
Extra exercise: Answer the following questions without using Mathematica first, and then use Mathematica to check your answers.
- If a, b, c > 0, what is the area of the region under that graph of the parabola ax2+bx+c and above the x-axis between x=0 and x=1?
- Find the value of c such that the area under x2+3x+c and above the x-axis between x=0 and x=1 is equal to 5.
Differential equations
Use DSolve[equation, y[x], x], e.g. DSolve[y'[x]==3y[x], y[x], x]
or DSolve[y''[x]+y[x]==0, y[x], x].
To find the solution that satisfies initial condition(s), write the equation and the condition(s) in curly brackets,
e.g. DSolve[{y'[x]==3y[x], y[0]==2}, y[x], x]
or DSolve[{y''[x]+y[x]==0, y[0]==3, y'[0]==4}, y[x], x].
Exercise: Solve the equation: y'+y=sin(x)+3.
Exercise: Solve the initial value problem: y'+y=sin(x)+3, y(0)=1.
Numerical solutions
Try the following:
solution=NDSolve[{y'''[x]+y''[x]+y'[x]==-(y[x])^3, y[0]==1, y'[0]==0, y''[0]==0}, y[x], {x,0,20}];
Plot[y[x]/.solution, {x,0,20}]
It will graph the solution of y'''(x)+y''(x)+y'(x)=-(y(x))^3 satisfying y(0)=1, y'(0)=0, y''(0)=0.
Exercise: Plot the solution of the initial value problem: y'=y-x3, y(0)=2, for x in [0,5].
Parametric curves
Use ParametricPlot[{f[t],g[t]},{t,min,max}] to plot the curve given by x=f(t), y=g(t), for t in the interval [min,max]. Sometimes Mathematica gets upset (I don't really know why), and
you have to use "Evaluate" as follows: ParametricPlot[Evaluate[{f[t],g[t]}],{t,min,max}].
Plot the curve given by x=t3+t2, y=1-t2, for t in the interval [-5,5]. Also plot this curve for t in the interval [-50,50].
Just as when plotting the graph of a regular function, you can define f(t) and g(t) first. So you can do the above as follows:
f[t_]=t^3-t^2;
g[t_]=1-t^2;
ParametricPlot[{f[t],g[t]},{t,-5,5}]
ParametricPlot[{f[t],g[t]},{t,-50,50}]
Exercise:
- Plot the curve given by x=cos(3t), y=sin(4t) (for t in [0,2pi])
- Change the constants 3 and 4 to some other (I suggest larger) numbers and see what happens.
Exercise:
- Save your file (click on "File", then on "Save as". Choose "Desktop", "Student Folder", "Groop Share",
"mnogin". Write the name of your file under "Save this document as". I suggest that you make your name a part of the
file name, e.g. maria-nogin-math76lab.nb. The file extension should be ".nb".)
- Send the file as an attachment to me: open Netscape, open this page
(http://zimmer.csufresno.edu/~mnogin/mathematica76.html), and click on my email address:
mnogin@csufresno.edu. Attach your file. Write "just practicing" in
the body of the message.
Project due November 3, 2004, at 11:59 pm:
Note 1: Collaboration is allowed, however, every person is expected to type and submit their own work.
Note 2: If you make a typo, please fix it instead of trying all over again. If you don't see what you typed wrong and wish to rewrite the whole thing, then erase the command that did
not work.
Open a new Mathematica file and write your name.
Consider the cycloid given by parametric equations x=t-sin(t), y=1-cos(t) (See example 6 on pages 690-691, let r=1).
- Use Mathematica to plot the curve.
Set up integrals for the areas and arc length described below, and use Mathematica to evaluate your integrals (get numerical values).
- Find the area of the region under one arch of the cycloid.
- Find the length of one arch of the cycloid.
- One arch of the cycloid is rotated about the x-axis. Find the area of the obtained surface.
- One arch of the cycloid (the one where t is in [0, 2pi]) is rotated about the y-axis. Find the area of the obtained surface.
For extra credit:
- The region under one arch of the cycloid is rotated about the x-axis. Find the volume of the obtained solid.
- The region under one arch of the cycloid (the one where t is in [0, 2pi]) is rotated about the y-axis. Find the volume of the obtained solid.
Save your file (if in the lab: click on "File", then on "Save as". Choose "Desktop", "Student Folder", "Groop Share",
"mnogin". Write the name of your file under "Save this document as". I
suggest that you make your name a part of the file name, e.g. maria-nogin-math76proj.nb. The file extension should be
".nb".) Remember to leave in your file only stuff that actually worked
(warning messages are OK).
You may turn in your project in any of the following ways:
- Send the file as an attachment to mnogin@csufresno.edu by 11:59
on Wednesday, Nov 3.
One way to send your file is to open Netscape, open this page
(http://zimmer.csufresno.edu/~mnogin/mathematica76.html), and click on my email address above. Then attach your file.
If the name of your file does not contain your name, then write your name in the body of the message. Also, indicate
if you have done the extra credit questions.
- Print it out and bring it to class not later than on Wednesday, Nov 3.
- Print it out and bring it to my office office (PB 341) not later than on Wednesday night.
This page was last revised on 26 October 2004.