DSolve@8y’’@xD + y@xD == 0, y@0D == 1, y’@0D == 0<,y@xD,xD
Find a second-order linear ODE that Mathematica cannot solve.
ì 1.3 Assignment, substitution and function definition
As you’ve seen, the percent sign, %, gives us a useful way of referring to earlier output. And in fact you can
refer to any output in this way using its “In/Out” number—see Section 1.6. However, it’s inadvisable to
rely on
% in this way. The principal drawback is that if you save your work and call it up again, or even if
you need to edit or debug work you’ve already done, the sequencing on which
% depends can be disrupted.
It’s better instead to get into the habit of naming things which it’s likely you’ll want to use again, like this:
expression1 =
2 x
H1 + x
2
L H1 + xL
expression2 = Apart@expression1D
expression3 = Together@expression2D
TrueQ@expression1 == expression3D
An important thing to note is the use of the single equals sign, =, in commands such as
expression1 =
2 x
H1 + x
2
L H1 + xL
which means “let the symbol expression1 have value
2 x
H1 + x
2
L H1 + xL
”. This is to be distinguished from
the double equals sign,
==, which, as you’ve seen, is used to set up equations. The final command,
TrueQ@expression1 == expression3D
means “test whether the equation expression1 == expression3 is true for all values of the variable
or variables”. Notice the final
Q in the function name: this is a convention for logical functions (those
whose output is
True or False).
Assigning values to symbols in this way is clearly very useful: indispensable, in fact. But one thing that’s a
disadvantage in some circumstances is that these assignments are completely global: unless we take steps,
the symbol
expression1 will continue to call up the value
2 x
H1 + x
2
L H1 + xL
in whatever future context we
use it. This is not irreversible: we can make
expression1 into an unassigned symbol again by clearing
its value:
Clear@expression1D
We could also quit our Mathematica session: that will clear all assignments pretty effectively, and leave
everything clear for our next go! But these approaches are all fairly cumbersome, and it’s sometimes more
appropriate to avoid global assignments of this type and opt for local substitution instead.
Course.nb 9