Physics 123
      Helps for Challenge Problems
       


        Return to Physics 123 Home page.

        Graphing
        • Basic graphs in Maple
          • Graph a simple function: plot(sin(3*x),x=0..4);
          • Parametric plot: plot([sin(3*t),sin(6*t),t=0..4]);
        • Basic graphs in Python
          • Python takes quite a bit more work to generate a simple plot.
          • Here is a sample:

              • from visual.graph import *  #This has function and graphing definitions

                #Define constants
                k=10
                a=3;

                #Set graph parameters - must be before gcurve is used,
                # or it creates a second graph
                graph1=gdisplay(ymin=-1,ymax=+5)

                #Define curves
                tancurve=gcurve(color=color.blue)
                linecurve=gcurve(color=color.green)

                #plot
                for x in arange (0,2,0.01):
                    tancurve.plot(pos=(x,tan(k*x)))
                    linecurve.plot(pos=(x,a*x))
                 

        • Basic graphs in Excel
          • Generate a column of x values (Place the first value in one cell and the next in the cell below. Highlight the cells and dgag from the lower right-hand corner to create the column of values.)
          • Create an equation to the right of the first cell by typing something like =SIN(*) where * means you insert the address of the first cell. This can be done by clicking on the cell.
          • Clcik on Insert/Chart/XY and follow the instructions there.

        Finding Roots Algebraically in Maple

        • Maple can solve for roots of simple equations in closed form. For example:
          >eq:=a*x^2+b*x+c=0;
          > solve(eq,x);
        • Systems of linear equations can be solved in a similar fashion:

        • A:=solve([3*x+5*y=6,5*x-3*y=4],{x,y});

        Finding Roots Numerically

        • One "quick and dirty" way to find roots numerically is graphically. If the equation is f(x) = g(x), then plot f(x)-g(x) and see where the function crosses the x-axis.
        • Another simple way to solve the equation is to evaluate f(x)-g(x) for a number of different values of x
        • and see where the function is near zero. The range can be refined over several iterations.
        • Using Excel: We do this to find the root of tan(10x)=3x
        • :
          x tan(10x)-3x   x tan(10x)-3x
          0.20 -2.78504   0.402000 -0.00025
          0.21 -2.33985   0.402001 -0.00023
          0.22 -2.03382   0.402002 -0.00021
          0.23 -1.80921   0.402003 -0.00019
          0.24 -1.63601   0.402004 -0.00017
          0.25 -1.49702   0.402005 -0.00014
          0.26 -1.38160   0.402006 -0.00012
          0.27 -1.28273   0.402007 -0.00010
          0.28 -1.19553   0.402008 -7.9E-05
          0.29 -1.11641   0.402009 -5.8E-05
          0.30 -1.04255   0.402010 -3.6E-05
          0.31 -0.97162   0.402011 -1.5E-05
          0.32 -0.90153   0.402012 7E-06
          0.33 -0.83025   0.402013 2.85E-05
          0.34 -0.75568   0.402014 5.01E-05
          0.35 -0.67541   0.402015 7.16E-05
          0.36 -0.58653   0.402016 9.32E-05
          0.37 -0.48527   0.402017 0.000115
          0.38 -0.36644   0.402018 0.000136
          0.39 -0.22258   0.402019 0.000158
          0.40 -0.04218   0.402020 0.000179
          0.41 0.193526   0.402021 0.000201
          0.42 0.517780   0.402022 0.000222
          0.43 0.995848   0.402023 0.000244
          0.44 1.776324   0.402024 0.000266
          0.45 3.287332   0.402025 0.000287
          0.46 7.480175   0.402026 0.000309
          0.47 79.30276   0.402027 0.000330
          0.48 -12.82490   0.402028 0.000352
          0.49 -6.737490   0.402029 0.000373
          0.50 -4.880520   0.402030 0.000395

        • Using Maple: To join the lines into one execution group, highlight the lines and press F4.
          >for x from 0.39 to 0.41 by 0.003 do
            >x,tan(10*x)-3*x;
          >end;
        • Using Python: In IDLE (the GUI) type:
          from visual import * #Imports math functions
          for x in arange(0.39,0.41,0.001):
            y=tan(10*x)-3*x
            print x,y

     

        Integrating
        • You can do many indefinite integrals symbolically in Maple:
          int(sin(x),x);
        • You can also do definite integrals:
          int(sin(x),x=0..Pi);
        • In Excel, you have to do integrals as a sum of f(x)dx:
        • x dx f(x)dx=sin(x)*0.01 Cumulative sum
               
          0 0.01 0 0
          0.01 0.01 9.99983E-05 9.99983E-05
          0.02 0.01 0.000199987 0.000299985
          0.03 0.01 0.000299955 0.00059994
          0.04 0.01 0.000399893 0.000999833
          0.05 0.01 0.000499792 0.001499625
          0.06 0.01 0.00059964 0.002099265
          0.07 0.01 0.000699428 0.002798694
          0.08 0.01 0.000799147 0.003597841
          0.09 0.01 0.000898785 0.004496626
          0.1 0.01 0.000998334 0.00549496
          0.11 0.01 0.001097783 0.006592743
          0.12 0.01 0.001197122 0.007789865
          0.13 0.01 0.001296341 0.009086207
          0.14 0.01 0.001395431 0.010481638
          0.15 0.01 0.001494381 0.011976019
          0.16 0.01 0.001593182 0.013569201
          0.17 0.01 0.001691823 0.015261025
          0.18 0.01 0.001790296 0.01705132
          0.19 0.01 0.001888589 0.018939909
          0.2 0.01 0.001986693 0.020926603
          0.21 0.01 0.002084599 0.023011202
          0.22 0.01 0.002182296 0.025193498
          0.23 0.01 0.002279775 0.027473273
          0.24 0.01 0.002377026 0.029850299
          0.25 0.01 0.00247404 0.032324339
          0.26 0.01 0.002570806 0.034895145
          0.27 0.01 0.002667314 0.037562459
          0.28 0.01 0.002763556 0.040326015
          0.29 0.01 0.002859522 0.043185538
          0.3 0.01 0.002955202 0.04614074
          0.31 0.01 0.003050586 0.049191326
          0.32 0.01 0.003145666 0.052336992
          0.33 0.01 0.00324043 0.055577422
          0.34 0.01 0.003334871 0.058912293

        • In Python, you do something similar, but much more conveniently and accurately:

        • from visual import *
          sum=0;
          for x in arange(0,3.142,0.001)
            sum=sum+sin(x)*0.001
          print sum


        Return to Physics 123 Home page.