RE: Re: NSolve with varying parameter

• To: mathgroup at smc.vnet.net
• Subject: [mg18837] RE: [mg18719] Re: [mg18692] NSolve with varying parameter
• From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
• Date: Thu, 22 Jul 1999 08:19:45 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```Carl Woll wrote a fabulous solution on how to get InterpolatingFunctions
that solve a system of equations.  See [mg18719] Re: [mg18692] NSolve with
varying parameter
(17 July, 1999).

I noticed Carl's solution can be simplified a bit (see below).
I will use the same example Carl used, but slightly change some notation.
Suppose we wanted to solve the equations:

t^2==x[t]^2 + y[t]^2
y[t]==x[t]^2

In many applications the variables are a function of time.  So I think it's
easier to grasp when we use (t) instead of (a).  Notice I have (x, y)
depending on (t) from the very beginning.

- The way I solve it below (f, g) are only functions of (t).

- The Diff Eqs and BCs are shown at Out[4] below.
----------------------------------

In[1]:=
f[t_] := x[t]^2 + y[t]^2 - t^2;
g[t_] := y[t] - x[t]^2;
eqs={f'[t]==0, g'[t]==0, f[1]==0, g[1]==0}

Out[4]=
{-2*t + 2*x[t]*x'[t] + 2*y[t]*y'[t] == 0,
-2*x[t]*x'[t] + y'[t] == 0,
-1 + x[1]^2 + y[1]^2 == 0,
-x[1]^2 + y[1] == 0}

In[6]:=
soln=NDSolve[eqs,{x,y},{t,0,1}]

Out[6]=
{{x->InterpolatingFunction[{{0.,1.}},<>],
y->InterpolatingFunction[{{0.,1.}},<>]},
{x->InterpolatingFunction[{{0.,1.}},<>],
y->InterpolatingFunction[{{0.,1.}},<>]},
{x->InterpolatingFunction[{{0.,1.}},<>],
y->InterpolatingFunction[{{0.,1.}},<>]},
{x->InterpolatingFunction[{{0.,1.}},<>],
y->InterpolatingFunction[{{0.,1.}},<>]}}

---------------------------------------------
Below I provide non-trivial code to make nice plots of
the real and imaginary parts of x[t] and y[y] for the
first of four solutions.

In[7]:=
x1=x/.soln[[1]];
y1=y/.soln[[1]];

Block[{\$DisplayFunction=Identity},
p1=Plot[Re[x1[t]],{t,0,1},PlotLabel->"Real Part of x"];
p2=Plot[Im[x1[t]],{t,0,1},PlotLabel->"Imaginary Part of x"];
p3=Plot[Re[y1[t]],{t,0,1},PlotLabel->"Real Part of y"];
p4=Plot[Im[y1[t]],{t,0,1},PlotLabel->"Imaginary Part of y"];
];
Show[GraphicsArray[{{p1,p2},{p3,p4}},
GraphicsSpacing -> 0.2,ImageSize->{550,380}]];

(* Graphics Not Shown *)

------------------
Regards,
Ted Ersek
ersektr at navair.navy.mil

```

• Prev by Date: Re: InputStream in version 3 vs version 4
• Next by Date: Re: implcit plot with undefined expression
• Previous by thread: Re: NSolve with varying parameter