[Date Index]
[Thread Index]
[Author Index]
Re: Plotting symbolic representation of numerica function
*To*: mathgroup at smc.vnet.net
*Subject*: [mg54470] Re: Plotting symbolic representation of numerica function
*From*: "Carl K. Woll" <carlw at u.washington.edu>
*Date*: Mon, 21 Feb 2005 03:44:39 -0500 (EST)
*Organization*: University of Washington
*References*: <cv6rkr$6hd$1@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
Mukhtar,
The reason you are getting error messages is because the right hand side of
your equation is not a list of two objects, like the left hand side is. On
the other hand, when using Set, the right hand side is evaluated, and
becomes a list of two objects if there are no errors. Of course, in your
example below Mathematica will not be able to evaluate the right hand side
since x will not be numerical.
At any rate, it seems to me that you ought to investigate the function
ImplicitPlot. If you can turn your system of two equations into a single
equation for either f1 or f2, then ImplicitSolve ought to be able to plot
it. If you can't or don't want to reduce the number of equations, then you
might be interested in a function I presented in the past called
ImplicitSolve. The usage message for ImplicitSolve is:
"ImplicitSolve[eqns, {x->x0,y->y0,...}, {x, xmin, xmax}, opts] finds a
numerical solution to the implicit equations eqns for
the functions y, ... with the independent variable x in the range xmin to
xmax. The root {x0,y0,...} should satisfy the equations, or should provide a
good starting point for finding a solution when using FindRoot. Options
which can be supplied with opts include those which can be provided to
FindRoot or NDSolve."
In your example, you would use ImplicitSolve as follows:
ImplicitSolve[{g1[f1,f2,x]==0,g2[f1,f2,x]==0},{x->x0,f1->f10,f2->f20},{x,a,b}]
where {x0,f10,f20} is a reasonable approximation to a root of the supplied
equations, and a and b are the endpoints of the range of x that you are
interested in. ImplicitSolve returns InterpolatingFunctions which you can
then plot.
The code for ImplicitSolve is given below.
Carl Woll
When copying the code below into mathematica, it's probably a good idea to
change your DefaultInputFormatType to InputForm before you cut and paste.
When I cut and paste the code below into a StandardForm input cell, I get
extraneous input which Mathematica treats as multiplication, so that running
the code produces output like Null^6. Cutting and pasting into an InputForm
input cell avoids this problem.
Clear[ImplicitSolve]
ImplicitSolve[eqn_List, rt_, {x_, min_, max_}, opts___?OptionQ] :=
Module[{x0, y, y0, ag},
ag = AccuracyGoal /. {opts} /. AccuracyGoal -> 6;
x0 = Cases[rt, (x -> a_) -> a];
If[x0 == {},
Message[ImplicitSolve::badroot, x];Return[],
x0 = x0[[1]]
];
{y, y0} = Transpose[DeleteCases[rt, x -> x0] /. Rule -> List];
If[!(And @@ Thread[Abs[eqn /. Equal -> Subtract /. rt] < 10^-ag]),
Message[ImplicitSolve::inaccurate];
y0 = FindRoot[Evaluate[eqn /. x->x0], Evaluate[Sequence@@Transpose[{y,
y0}]],opts][[All,2]],
Null,
Message[ImplicitSolve::incomplete]; Return[]
];
NDSolve[Flatten[{D[eqn /. Thread[Rule[y, #[x]& /@ y]], x], Thread[#[x0]&
/@ y == y0]}],
y, {x, min, max}, opts, PrecisionGoal -> ag]
]
ImplicitSolve::usage =
"ImplicitSolve[eqns, {x->x0,y->y0,...}, {x, xmin, xmax}, opts] finds a
numerical solution to the implicit equations eqns for
the functions y, ... with the independent variable x in the range xmin to
xmax. The root {x0,y0,...} should satisfy the equations, or should provide a
good starting point for finding a solution when using FindRoot. Options
which can be supplied with opts include those which can be provided to
FindRoot or NDSolve.";
ImplicitSolve::badroot = "Supplied root is missing value for `1`";
ImplicitSolve::incomplete = "Supplied root is incomplete";
ImplicitSolve::inaccurate = "Supplied root is inaccurate, using FindRoot to
improve accuracy";
"mbekkali" <mbekkali at gmail.com> wrote in message
news:cv6rkr$6hd$1 at smc.vnet.net...
> Hello. I need to plot solutions to system of equations solved using
> numerical functions. I tried:
>
> {f1[(x_)?NumericQ],f2[(x_)?NumericQ]}:={f1,f2}/.FindRoot[{g1[f1,f2,x]==0,g2[f1,f2,x]==0},{f1,0},{f2,0}][[1]]
> Plot[Evaluate[{f1[x],f2[x]},{x,x0,x1}]
>
> where g1,g2 are some functions and x0,x1 some starting variables. I
> get an error message SetDelayed::shape : Lists
> {f1[x_?NumericQ],f2[x_?NumericQ]} and {f1,f2} are not the same shape.
> I suspect that there is something wrong with SetDelayed because using
> Set and Solve plots functions, yet SetDelayed and Solve generates the
> same message as SetDelayed and FindRoot.
>
> I do not understand what is wrong and help file is not useful as it
> does not contain examples with SetDelayed for several variables.
>
> Mukhtar Bekkali
>
Prev by Date:
**Solving a weakly singular integral equation - Take 2.**
Next by Date:
**Re: legend scaling**
Previous by thread:
**Re: Plotting symbolic representation of numerica function**
Next by thread:
**real telescopic sum becomes complex?**
| |