Re: Re: I need some help about this error
- To: mathgroup at smc.vnet.net
- Subject: [mg39359] Re: [mg39324] Re: I need some help about this error
- From: Dr Bob <drbob at bigfoot.com>
- Date: Wed, 12 Feb 2003 03:53:36 -0500 (EST)
- References: <b27ft7$nel$1@smc.vnet.net> <200302110942.EAA26073@smc.vnet.net>
- Reply-to: drbob at bigfoot.com
- Sender: owner-wri-mathgroup at wolfram.com
Try this:
<< Graphics`Graphics`
<< Graphics`Colors`
f[x_] = x^2 - 2;
newton[x_] = Simplify[x - f[x]/f'[x]];
ap = NestList[newton, 4., 7];
g = {Line@{{#, f@#}, {newton@#, 0}, {newton@#, f@newton@#}},
Point@{#, f@#}} &;
h = Text[#, {#, f@#}, {1, -1}] &;
DisplayTogether[
Plot[f@x, {x, 0, Max@ap}],
Graphics[{Blue, AbsolutePointSize[5],
g /@ ap,
h /@ Take[ap, 3],
h@Last@ap
}
],
AxesOrigin -> {0, 0}, PlotRange -> {f@0, 1 + f@Max@ap}, ImageSize ->
500
];
Bobby
On Tue, 11 Feb 2003 04:42:14 -0500 (EST), Allan Hayes
<hay at haystack.demon.co.uk> wrote:
> Baruch,
> The basic problem is that Plot decides what kind of expression {t} is
> before
> evaluating {t}. In this case it decides that Flatten[{t}] must be a list
> of
> one real number for the sample values of x that it uses. This is not so,
> in
> fact Flatten[{t}] becomes a list of several real numbers.
> We can supply Plot with information to make the correct decision by
> causing
> {t} to evaluate before is makes its decision ( I have included f[x] in
> the
> plot, and used df = f' (note =, not :=) to avoid evluating f' at each
> iteration).
> You might like to consider avoiding the use of Plot for the tangent
> lines
> by adding fo each approximation,a, Line[{a,f[a]},{b,0}] where {b,0} is
> where the tangent at a meets the x-axis -- Epilog might be used.
>
> f[x_] := x^2 - 2
> Ne[x_] := x - f[x]/f'[x]
> ap = NestList[Ne, 4., 5]
> tang[h_] := f[h] + f'[h]*(x - h)
> t = tang /@ ap
>
> Plot[Evaluate[Prepend[t, f[x]]], {x, -5, 5},
> AxesOrigin -> {0, 0}, PlotRange -> {-3, f[4]}]
>
> Allan
>
> ---------------------
> Allan Hayes
> Mathematica Training and Consulting
> Leicester UK
> www.haystack.demon.co.uk
> hay at haystack.demon.co.uk
> Voice: +44 (0)116 271 4198
> Fax: +44 (0)870 164 0565
>
>
>
> "baruch" <spin9 at terra.com.br> wrote in message
> news:b27ft7$nel$1 at smc.vnet.net...
>> f[x_] := x^2 - 2
>> Ne[x_] := x - f[x]/f'[x]
>> ap = NestList[Ne, 1.5, 5]
>> tang[h_] := f[h] + f'[h](x - h)
>> t = tang /@ ap
>>
>> Plot[{t}, {x, -10, 10}, AxesOrigin -> {0, 0},
>> PlotRange -> {{-5, 5}, {-3, 5}}]
>>
>> Now, How can I plot the last command?
>>
>> I got the following errors:
>>
>> Plot::"plnr": "\!\(te[x]\) is not a machine-size real number at
>> \!\(x\) = \
>> \!\(-9.999999166666667`\)."
>> Plot::"plnr": "\!\(te[x]\) is not a machine-size real number at
>> \!\(x\) = \
>> \!\(-9.188660168541684`\)."
>>
>> I want to make a "program" that will plot the successives tangent
>> lines of approximations of any function (when possible) using the
>> Newton Methods... any idea on how can I implement or solve that
>> problem?
>>
>> Thank you very much!
>>
>
>
>
>
--
majort at cox-internet.com
Bobby R. Treat
- References:
- Re: I need some help about this error
- From: "Allan Hayes" <hay@haystack.demon.co.uk>
- Re: I need some help about this error