����������������������������
Consider the ordinary first order equation.
sin(x + y) + (2 y + sin(x + y))
dy
dx
=0
Let’s first solve for dy/dx.
dy
dx
=
-sin(x+y)
2 y+sin(x+y)
Now, let’s create a direction field.
�������
- ���[� + �]
�[�_� �_] �=
�
� � + ���[� + �]
�� = ����������[{�� �[�� �]}� {�� - ��� ��}� {�� - �� �}�
����������� → {����� ����� ����}� ����� → ������ ���� → ����� ��������� → {�� �}]
y
4
2
�������
-10
5
-5
10
x
-2
-4
Now, let’s try to solve the differential equation.
�������
�������
��� = ��������������[� + �[�]] + � �[�] + ���[� + �[�]] � �[�] ⩵ �� �[�]� �
��������������[� + �[�]] + ���[� + �[�]] + � �[�] �′ [�] ⩵ �� �[�]� �
That did not seem to work. Let’s use the more ancient DSolve command.
�������
�������
��� = ���������[� + �[�]] + � �[�] + ���[� + �[�]] � �[�] ⩵ �� �[�]� �
�����- ���[�] ���[�[�]] + ���[�] ���[�[�]] + �[�]� ⩵ �[�]� �[�]
That worked, but it did not give us an explicit equation because it could not solve the resulting implicit
equation
y2 - cos x cos y + sin x sin y = C
2 ���
IntroductionToNDSolveValue.nb
for y in terms of x (neither can I).
���������������
Let' s use the implicit solution to draw some integral curves and add them to our direction field. First,
let’s replace each occurrence of y[x] in the expression
-Cos[x] Cos[y[x]] + Sin[x] Sin[y[x]] + y[x]2 ⩵ C
with a y. To do this, I will copy and paste the expression (without the C), store it in the variable sol, then
replace each occurrence of y[x] with y. Of course, I could just type in the expression by hand, but this
gives an opportunity to practice with the replace command.
�������
�������
��� = - ���[�] ���[�[�]] + ���[�] ���[�[�]] + �[�]� /� �[�] → �
�� - ���[�] ���[�] + ���[�] ���[�]
Now, we are going to create a contour plot.
�������
�� = �����������[���� {�� - ��� ��}� {�� - �� �}]
4
2
�������
0
-2
-4
-10
-5
0
5
10
When you hover your mouse over a contour, it displays its value. In multivariable calculus, these are
known as level curves. Each curve consists of all points in the plane such that the multivariable function
h(x, y) = y2 - cos x cos y + sin x sin y equals the constant C.
Let' s remove the shading.
IntroductionToNDSolveValue.nb
�������
���3
�� = �����������[���� {�� - ��� ��}� {�� - �� �}�
�������������� → ����]
4
2
�������
0
-2
-4
-10
-5
0
5
10
Let’s select two particular contours, C=0 and C=2, the ones shown in Example 6.25 on page 68 of the
textbook. Then, let’s make them thick and color them blue.
�������
�� = �����������[���� {�� - ��� ��}� {�� - �� �}�
�������������� → �����
�������� → {�� �}�
������������ → ���������[������ ����]]
4
2
�������
0
-2
-4
-10
-5
0
5
10
4 ���
IntroductionToNDSolveValue.nb
Finally, let’s add these to our direction field.
�������
����[��� ��]
y
4
2
�������
-10
5
-5
10
x
-2
-4
Note how well these contours (level curves) fit in the direction field. In differential equations, these
contours are known as Integral Curves. But, they are not solutions. In fact, they are not even functions
as they fail the vertical line test. But they do “contain” solutions of the differential equation. Let’s see if
we can demonstrate that fact.
������������������
This will be our first use of the numerical solver NDSolveValue. We’ve met a point where the DSolveValue command failed, so now we will turn to a numerical solver.
Let focus on the contour
y2 - cos(x) cos((y) + sin(x) sin(y) = C,
which can be written as
y2 - cos(x + y) = C.
Now, let’s let x=0 and C=0 and determine y.
��������
��������
������[� � � - ���[� + �] ⩵ � �� - � < � < �� �]
{{� → - ��������}� {� → ��������}}
Thus, the points (0,-0.824132) and (0,0.824132) lie on the contour y2 - cos(x + y) = 0. With this in mind,
let’s try to find the solution of the IVP
dy
dx
=
-sin(x+y)
2 y+sin(x+y)
, y(0) = 0.824132
Let’s examine our current direction field with the two given contour plots again.
IntroductionToNDSolveValue.nb
��������
���5
����[��� ��]
y
4
2
��������
-10
5
-5
10
x
-2
-4
Is it possible that the ellipse centered at the origin contains the initial condition y(0) = 0.824132? Let’s try
and find out. Here comes our first use of the NDSolveValue command.
Note that the use of the NDSolveValue command is similar to the DSolveValue command, that is, until
we come to the use of the independent variable at the end of the command. This time, you must state
an interval over which you wish to find the solution. In this case, we’ve used {x,-10,10} in an attempt to
find a solution over the interval (-10,10).
��������
��� = ������������
���[� + �[�]] + � �[�] + ���[� + �[�]] � �[�] ⩵ �� �[�] ⩵ ��������� �� {�� - ��� ��}
������������������ � �����==�-�������� ���� ���� �� ����������� ����� ����������� �� ����� ������ ����������
������������������ � �����==�������������������� ���� ���� �� ����������� ����� ����������� �� ����� ������ ����������
��������
���������������������
������� {{-����� ����}}
������� ������
There are a couple of things here that need explaining. First, note that a couple of warnings mention
singularities or stiff systems, suspected near the points -1.81834 and 1.81834.
Secondly, the output is something known as an Interpolating Function (look it up in the Wolfram Documentation with the command ?InterpolatingFunction). There is also a gray box where the domain is
stated as (-1.82,1.82), which is related to the difficulties described in the warning messages.
When we use this interpolating function, stored in the variable sol, we must restrict our plot to this
domain, otherwise we will run into difficulties. For example, consider what happens when we try to plot
over the domain [-10,10].
6 ���
IntroductionToNDSolveValue.nb
��������
����[���[�]� {�� - ��� ��}]
���������������������������� �
����� ������{-�������}����� ������� ��� ����� �� ���� �� ��� ������������� ��������� ������������� ���� �� �����
1 × 1033
-10
5
-5
��������
10
-1 × 1033
-2 × 1033
-3 × 1033
In statistics, when fitting a line or curve to a set of data, using the line or curve to make a prediction
within the boundary of the data set is often acceptable. However, if you try to use the line or curve to
make a prediction on data lying beyond the boundary of the data set, you can run into trouble. For
example, if your line predicts the height of a girl based on her age, your model might predict that she is
18 feet tall when she reaches the age of 60. When you use data outside the boundary of the original
data set, that leads to an error called extrapolation. That is exactly what we are facing here as well. The
interpolating function is limited to the range (-1.82,1.82), so going outside that range can lead to error
based on extrapolation.
So, let’s restrict the plot to the domain (-1.82,1.82).
��������
����[���[�]� {�� - ����� ����}]
���������������������������� �
����� ������{-�������}����� ������� ��� ����� �� ���� �� ��� ������������� ��������� ������������� ���� �� �����
2.0
1.5
1.0
��������
0.5
-1.5
-1.0
0.5
-0.5
1.0
1.5
-0.5
We have a little warning that our data still lies outside the range of the interpolating function (a little
roundoff error). Let’s shrink our domain a little bit more.
IntroductionToNDSolveValue.nb
��������
���7
����[���[�]� {�� - ����� ����}]
1.0
0.8
0.6
0.4
��������
0.2
-1.5
-1.0
0.5
-0.5
1.0
1.5
-0.2
-0.4
Interesting! Could that be the top half of the ellipse centered at the origin? Let’s make this a bit thicker
and color it red.
��������
�� = ����[���[�]� {�� - ����� ����}� ��������� → ���������[������ ���]]
1.0
0.8
0.6
0.4
��������
0.2
-1.5
-1.0
0.5
-0.5
1.0
-0.2
-0.4
Now, let’s add it to our direction field and contours.
1.5
8 ���
IntroductionToNDSolveValue.nb
��������
����[��� ��� ��]
y
4
2
��������
-10
5
-5
10
x
-2
-4
Aha! This particular IVP solution does lie within one of the integral curves. Now, let’s focus on the
second initial condition that we found to lie on the contour C=0, namely, y(0) = -0.824132.
��������
��� = ������������
���[� + �[�]] + � �[�] + ���[� + �[�]] � �[�] ⩵ �� �[�] ⩵ - ��������� �� {�� - ��� ��}
������������������ � �����==�-�������� ���� ���� �� ����������� ����� ����������� �� ����� ������ ����������
������������������ � �����==�������������������� ���� ���� �� ����������� ����� ����������� �� ����� ������ ����������
��������
���������������������
������� {{-����� ����}}
������� ������
Now we draw the plot, this time immediately over the domain (-1.81,1.81).
��������
�� = ����[���[�]� {�� - ����� ����}� ��������� → ���������[������ ���]]
0.4
0.2
-1.5
-1.0
0.5
-0.5
-0.2
��������
-0.4
-0.6
-0.8
-1.0
1.0
1.5
IntroductionToNDSolveValue.nb
���9
Aha! That looks like the bottom half of the ellipse centered at the origin. Let’s add it to our direction field
and contour plot to find out.
��������
����[��� ��� ��]
y
4
2
��������
-10
5
-5
10
x
-2
-4
Aha! That is the bottom half of the ellipse centered at the origin.
Now, let’s add both.
��������
����[��� ��� ��� ��]
y
4
2
��������
-10
5
-5
-2
-4
10
x
10 ���
IntroductionToNDSolveValue.nb
Wow! A little blue showing at the endpoints of the top curve on the ellipse and the bottom curve of the
ellipse, due to the fact we did a little rounding. But note how both solutions are contained in the integral
curve C=0.
Welcome to your first use of the NDSolveValue command.
© Copyright 2026 Paperzz