Scot Gould

Scot Gould

917 Reputation

14 Badges

11 years, 296 days
Claremont McKenna, Pitzer, Scripps College
Professor of Physics
Upland, California, United States
Dr. Scot Gould is a professor of physics at Claremont McKenna, Pitzer, and Scripps Colleges - members of The Claremont Colleges in California. He was involved in the early development of the atomic force microscope. His research has included numerous studies and experiments using scanning probe microscopes, particularly those involving natural fibers such as spider silk. More recently, he was involved in developing and sustaining AISS. This full-year multi-unit, non-traditional, interdisciplinary undergraduate science education course integrated topics from biology, chemistry, physics, mathematics, and computer science. His current interest is integrating computational topics into the physics curriculum. He teaches the use of Maple's computer algebraic and numerical systems to assist students in modeling and visualizing physical and biological systems. His Dirac-notation-based quantum mechanics course is taught solely through Maple.

MaplePrimes Activity


These are answers submitted by Scot Gould

f''(w) = 0

For a first derivative condition: 

f'(w) = diff_f_at_w_expression

 

Whether I use an indexed variable vs. an atomic one depends upon the problem I am trying to solve and how I wish to solve it. For example, if I have wish to write or refer to elements in a sequence, list or vector, being able to use indexed variables is quite valuable in readability and worksheet real estate. E.g. seq(a[n]*x^n, n=0..3). Such choices are made when I am writing code, which I perform nearly always within a Code Edit Region.  

However, if I am writing mathematical equations that I want non-Maple users to be able to read, particularly if including a subscript is informative, then I use an “atomic variable”. For writing mathematical equations and functions I use 2D-input because it makes the equations more readable and reduces the content on a page. The output of a 2D-input is repetative.

I agree with Carl Love, the atomic variable leads to fewer problems, particularly with new users, which, clearly, you are not. Many of the students in my courses prefer the image of the subscript provided within 2D input, such as F__x or F__Earth. However, when constructing such variables, too often they end up with the equivalent of F[x], only to discover that should they assign a value to x, their worksheet starts producing unexpected outcomes. Thus, I encourage them to avoid subscripts until they are more familiar with Maple.

There is a post on the evaluation of subscripts in Maple by Robert Lopez that might be of interest to readers: https://www.mapleprimes.com/maplesoftblog/208838-The-Saga-Of-The-Subscript

Personally, I enjoy atomic variables. They truly do make Maple input more readable, i.e., more aligned with what one sees in papers and textbooks.

 

Use 2D Input. Then, and only then,  the "dot" notation is available and can be found in the Calculus palette. 

 

When I am in your situaiton, I hit enter after the "x" to add another line. Then I hit the "Remove section" button on the Toolbar. (It is on the right in the circled region shown below.) This ends Section 1 and steps-left the cursor into the "Chapter 1" section. Then I hit "Insert section" button to add another section and step-right. I find this step-left / step-right structure logical since it is akin to what one uses in Word. 

If you end up with more lines in a section then desired, <ctrl>-<delete> (or <command>-<delete> for Mac) works to remove the entire line. 

I could see using this plot in my own courses. Others here are likely to give you some slicker ideas, but here is a start. All the plots are "plot", but one is of "style=point". I put the commands in a procedure so that you could pass it different functions.

 

restart


This procedure receives a function, f, that is to be plotted from a to b. N points are shown

NeatPlot := proc (f, a::numeric, b::numeric, N::posint, aclr::string) local x, n, lplot, dx, pts, fplot, pplot; fplot := plot(f(x), x = a .. b, thickness = 4, color = aclr); dx := (b-a)/(N-1); pts := [seq([x, f(x)], x = a .. b, dx)]; pplot := plot(pts, style = point, symbolsize = 20, symbol = solidcircle, color = aclr); x := a; for n to N do lplot[n] := plot([[x, f(x)], [x, 0]], thickness = 3, color = aclr); x := x+dx end do; plots:-display([fplot, pplot, seq(lplot[n], n = 1 .. N)]) end proc

"fsample(x):=cos(0.5*x)*(e)^(-0.1*x^(2)):  a:=evalf(2*Pi):    NeatPlot(fsample, -a, a, 13, "DodgerBlue");"

 

``

``


 

Download NeatPlot.mw

(Note - the grid lines don't show up when you execute it.) More work using textplot is needed to add the values of f(x) at x. 

Snip the image of the Maple output and paste into your document. It requires nanoseconds of effort. 

I wasn't sure which form you used, so I prefer the worksheet mode, using 2d-input...
Maple expects you to differentiate first with respect to t, but then use a different variable to substitute in the values...
 

restart; with(plots)

"r(t) :=< cos(t), sin(t), t>;"

proc (t) options operator, arrow, function_assign; `<,>`(cos(t), sin(t), t) end proc

(1)

spacecurve(r(t), t = -1 .. 1, thickness = 5, color = "DodgerBlue")

 

Differentiate first with respect to t, but t1 is the value that you are inserting

"drdt(t1) := eval(diff(r(t), t), t= t1);"

proc (t1) options operator, arrow, function_assign; eval(diff(r(t), t), t = t1) end proc

(2)

spacecurve(drdt(t), t = -1 .. 1, thickness = 5, color = "DarkMagenta")

 

``


 

Download spacecurve.mw

As an alternative to using a Matrix, might I suggest using DataFrames. They are particularly useful if you plan to continue on with analyzing your data as if it were entered in a spreadsheet. And it is way more readable in manipulation than any spreadsheet.

 

I'm going to guess that the second column is generated by the probability of an outcome from a binomial distribution: (x choose 8?)   Hence I'll create the formula:

"restart;   P(x) := ((8) ? (x))/(2^(8)):"

 

Now to create the DataFrame, it is just like a Matrix, but one can label columns (and rows). The columns counter will help you catch the error that Carl Love points out.


Column 1 is a sequence of numbers from 0 to 8

Column 2 is a sequence of values from the P(x) formula

Column 3 is just of Vector of 0.
'columns' option is the list of labels.

 

m1 := DataFrame(`<|>`(`<,>`(seq(0 .. 8)), `<,>`(seq(P(x), x = 0 .. 8)), Vector(9, 0)), columns = ["# girls", "P(x)", "x*P(x)"])

_m1634490005760

(1)

If you prefer the "P(x)" column to be floating point values and not rational numbers, all you need to do is to say is that you want to evaluate (individually) as a floating point:

m1["P(x)"] := `~`[evalf](m1["P(x)"])

_m1634487619552

(2)

Here is what m1 looks like now:

m1

_m1634490005760

(3)


To see if what we have makes sense, let's add up the "P(x)" column. It should be 1.

add(m1["P(x)"])

1.000000000

(4)

Looks good. Time to move on.

 

To solve for "x*P(x)" This is "#girls"  multiplied (individually) with "P(x)"

m1["x*P(x)"] := `~`[`*`](m1["# girls"], m1["P(x)"])

 

Now the DataFrame looks like this:

m1

_m1634490005760

(5)

At this point, you can add up the values in the "x*P(x)" column

 

By the way, sum explicity says it is designed for symbolic summations. Hence the command of add was created. (This can be frustrating until one gets used to it.)


 

Download DataFrames.mw

While I understand your reasoning, as it has been mine, from the help of ?sum:

      The sum command (sum) is for symbolic summation.

The italicized term is their emphasis. Hence, it sounds like even for "short" sums of discrete terms, don’t expect logical outputs from sum even if the command doesn’t reject the input. (If you are coming from MATLAB, remembering to switch to add can be maddening.)

Dr. Lopez correctly states, the output that you label as answer5[1] are a list of two equations: x = 553,  y = 455.  Since the goal is to calculate the value of the arctan, one wants to use "just the values". Hence a technique that I use frequently is to extract the right-hand-side (RHS) of the equations, i.e., the values, and use that output, for the calculations: 

restart;
answer5 := { x= 553.6, y = 455.0 }, {x = 553.6, y = -455.0 };

{x = 553.6, y = 455.0}, {x = 553.6, y = -455.0}

(1)

theta1 := arctan( rhs(answer5[1][2]) / rhs(answer5[1][1]) );

.6879485439

(2)

 

And for future angles, use the fact that arctan can identify the quadrant using 2 parameters: y, x. So for the other angle:

theta2 := arctan( rhs(answer5[2][2]), rhs(answer5[2][1]) );

-.6879485438

(3)

 


 

Download arctan.mw

Since you appear to want to use the Statistics package, which is a good choice for plotting one data set against another, this approach might be more useful. It uses 2 commands: ScatterPlot and Fit.  I've added some options to make it more interesting, but are not required.
 

restart; with(Statistics); X := Vector([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 8, 12, 12, 22, 30, 40, 44, 51, 65, 70, 97, 111, 131, 135, 174, 184, 210, 214, 232, 238, 254, 276, 285, 305, 318, 323, 343, 373, 407, 442, 493, 542, 627, 665, 782, 873, 981, 1095, 1182, 1273, 1337, 1532, 1728, 1932, 2170, 2388, 2558, 2802, 2950, 3145, 3526, 3912, 4151, 4399, 4641, 4787, 4971, 5162, 5445, 5621, 5959, 6175, 6401, 6677, 7016, 7261, 7526, 7839, 8068, 8344, 8733, 8915, 9302, 9855, 10162, 10819, 11166, 11516, 11844, 12233, 12486, 12801, 13464, 13873, 14554, 15181, 15682, 16085, 16658, 17148, 17735]); Y := Vector([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 8, 12, 12, 22, 30, 40, 44, 51, 65, 70, 97, 111, 131, 135, 174, 184, 210, 214, 232, 238, 254, 276, 285, 305, 318, 323, 343, 373, 407, 442, 493, 542, 627, 665, 782, 873, 981, 1095, 1182, 1273, 1337, 1532, 1728, 1932, 2170, 2388, 2558, 2802, 2950, 3145, 3526, 3912, 4151, 4399, 4641, 4787, 4971, 5162, 5445, 5621, 5959, 6175, 6401, 6677, 7016, 7261, 7526, 7839, 8068, 8344, 8733, 8915, 9302, 9855, 10162, 10819, 11166, 11516, 11844, 12233, 12486, 12801, 13464, 13873, 14554, 15181, 15682, 16085, 16658, 17148, 17735])

 

The following is the more common way using the "Statistics" package - ScatterPlot

ScatterPlot(X, Y, labels = ["X", "Y"], tickmarks = [5, 5], symbolsize = 20, symbol = solidbox)

 

This looks like a straight line. Are the two "vectors" truely identical?

LinearAlgebra:-Equal(X, Y)

true

(1)

Yes, hence the confusion as to why you might want to plot the two against each other.

 

As others have pointed out, you have a sequence of 110 points. Here is the way I prefer to extract this information: numelems

N := numelems(Y)

110

(2)

Let us create a new X variable to plot against the Y made up of a sequence of numbers from 1 to 110:

newX := Vector([seq(1 .. N)])

 

Now we plot, and we can add a possible curve fitting line. I tried a few examples, and this one looks possible given the information provided:

cfit := a3*x^3+a2*x^2+a1*x+a0; ScatterPlot(newX, Y, labels = ["X", "Y"], tickmarks = [6, 10], symbolsize = 15, symbol = circle, fit = [cfit, x], color = ["DarkGreen", "Magenta"], legend = "data")

a3*x^3+a2*x^2+a1*x+a0

 

 

To see the values of a basic curve that fits the data, use Fit in the Statistics package.

sfit := Fit(cfit, newX, Y, x)

HFloat(147.35821613199457)-HFloat(8.219842062292507)*x-HFloat(0.5340254006120428)*x^2+HFloat(0.018747154003949003)*x^3

(3)

May I suggest "Getting Started with Maple" 4th edition, by Doug Meade, et. al.. for other examples.

``


 

Download fitting_with_Statistics_package.mw

See if the command to evaluate an expression over a complex field,  evalc, does the operation that you asking for. 

Thank you Paul for posting this question. I feel your post is important because it identifies a problem with the Context Panel.

The reason your projectile doesn't land is because, in the Context Panel option for "2D-plot", the default range for the horizontal term is from -10 to +10.  I suspect that you changed the properties of the axes, "2-finger click>Axes>Properties", and thus were able to change the display to the limits: from 0 to 24. (And the same for the vertical as well.) Unfortunately, that didn't cause the program to calculate the values beyond t = 10.  Until Maplesoft updates/fixes/provides alternative to this property for the graph, I see no other option for this type of problem than for one to write the command that @tomleslie  states: "plot(ex11(t), t=0..30)" 

And if you want to know when the function is 0, there appears to be no easy shortcut in the Context Panel. Hence I suggest you try this command: "solve(ex11(t))". I rewrote the expression and used the solve sommand.  You are correct, the final t for it to "return to ground" is 24 time-units.

Example: Height of a Projectile

 

"ex11(t):=-16 t^(2)+384 t;"

proc (t) options operator, arrow, function_assign; -16*t^2+384*t end proc

(1.1)

"->"

 

This is the default image shown using the Context Panel...

 

Continuing with this problem:

 

-16*t^2+384*t"(->)"[[t = 0], [t = 24]]

 

plot(ex11(t), t = 0 .. 24)

 

 

``


 

Download projectile_2.mw

I unitentionally deleted my answer to note that I do tend to think more along the lines of @tomleslie
 

Using document mode

``

-3 <= 6*x-1

0 <= 6*x+2

(1)

6*x-1 < 3

6*x < 4

(2)

Here I will use <ctrl>-<L> (for Windows), or <command>-<L> (for Mac) to insert labels

solve(0 <= 6*x+2 and 6*x < 4, x)

RealRange(-1/3, Open(2/3))

(3)

Or we can do in one line:

 

solve(`and`(-3 <= 6*x-1, 6*x-1 < 3), x)

RealRange(-1/3, Open(2/3))

(4)

Or my personal preference, assign each equation to a variable, and then solve

eq1 := -3 <= 6*x-1

0 <= 6*x+2

(5)

eq2 := 6*x-1 < 3

6*x < 4

(6)

solve(eq1 and eq2, x)

RealRange(-1/3, Open(2/3))

(7)

``


 

Download simple_answer.mw

5 6 7 8 Page 7 of 8