Re: Numerical Methods
- To: mathgroup at smc.vnet.net
- Subject: [mg16235] Re: Numerical Methods
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Fri, 5 Mar 1999 00:41:01 -0500
- Organization: Universitaet Leipzig
- References: <7bg0t7$5k9@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi Bernard,
no site. It was invented some hundred years ago.
But here is the Mathematica code:
Options[RegulaFalsi]:=
{Compiled->True,AccuracyGoal->10^(-Precision[1.0]+6)}
IntervalLength[{{x1_,_},{x2_,_}}]:=Abs[x2-x1]
RFAux[{{x1_,f1_},{x2_,f2_}}]:=
Module[{xm,fm,xb,fb,p1,p2},
xm=x2-(x2-x1)*f2/(f2-f1); (* Regula Falsi *)
fm=func[xm];
xb=0.5*(x1+x2); (* BiSection *)
fb=func[xb];
If[Sign[f1]==Sign[fm],
p1={{xm,fm},{x2,f2}},
p1={{x1,f1},{xm,fm}}
];
If[Sign[f1]==Sign[fb],
p2={{xb,fb},{x2,f2}},
p2={{x1,f1},{xb,fb}}
];
If[IntervalLength[p1]<IntervalLength[p2],
p1,
p2
]
] /; Sign[f1]!=Sign[f2]
RFSame[_,{{x1_,f1_},{x2_,f2_}}]:=
Abs[x2-x1]<error || Abs[f1]<error2 || Abs[f2]<error2
RegulaFalsi::nrfunc=
"The function `1` does not evaluate to real numbers at `2` and `3`."
RegulaFalsi::nbrack=
"The function `1` does not change the sign between `2` in [`3`,`4`]."
RegulaFalsi[rhs_==lhs_,more__]:=
RegulaFalsi[rhs-lhs,more]
RegulaFalsi[f_,{x_Symbol,x1_?NumberQ,x2_?NumberQ}, opts___]:=
Block[{func,f1,f2,comp,error,error2,ibrack},
comp = Compiled /. {opts} /. Options[RegulaFalsi];
error=AccuracyGoal /. {opts} /. Options[RegulaFalsi];
error2=error*error;
If[comp, (* then *)
func=Compile[{{x,_Real}},Evaluate[f]],
(* else *)
func=Function[x,Evaluate[f]]
];
f1=func[x1];
f2=func[x2];
If[!NumberQ[f1] || !NumberQ[f2],
Message[RegulaFalsi::nrfunc,f,x1,x2];
Return[{}];
];
If[Sign[f1]==Sign[f2],
Message[RegulaFalsi::nbrack,f,x,x1,x2];
Return[{}]
];
ibrack=First[
Transpose[
FixedPoint[
RFAux,
{{x1,f1},{x2,f2}},
SameTest->RFSame
]
]
];
{x->0.5* (Plus @@ ibrack)}
]
Hope that helps
Jens
BERNARD K KEENAN wrote:
>
> Hi
> I was wondering if anybody knew of a site where there was info on the
> modifed method of false position or modified regula falsi.
>
> bernard keenan