Re: More troubles coming from indexed variables

• To: mathgroup at smc.vnet.net
• Subject: [mg25092] Re: [mg25000] More troubles coming from indexed variables
• From: Tomas Garza <tgarza01 at prodigy.net.mx>
• Date: Fri, 8 Sep 2000 03:00:40 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```I hope it's not too late to suggest an alternative treatment to the
problem you pose.
I take your least squares example. Sometime ago I was asked a similar
question, and I proposed the following approach.

I wil use Array[y, n] to denote your y values, and Array[x, n] to denote

values. "ones" is a vector of 1's, and "." means Dot (dot product):

First, assign a value to n:

In:=

n = 10;

In:=

ones = Table[1, {10}]

Out=

{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}

This is where you define the function you want to minimize:

In:=

Q[v_, w_, k_] := (Array[y, k] - v*ones - w*Array[x, k]).(Array[y, k]
- v*ones -

w*Array[x, k])

and now you ask for the solution of the two equations:

In:=

e = Solve[{D[Q[a, b, n], a] == 0, D[Q[a, b, n], b] == 0}, {a,
b}]

(I omit the output, but you may try it: it works fine, in all
generality,

and it requires only that n be previously specified, as above)

The output looks a bit messy, but you can reduce it by using
ReplaceRepeated on Simplify[e], giving adequate transformation rules for
each of the forms you obtain, like sums, sums of squares and sums of
cross products (these will appear clearly in the output Out):

In:= Simplify[e] //. {Plus @@ Array[y, k] -> Sy, Plus @@ Array[x,
k] -> Sx,

Plus @@ (Array[x, k]^2) -> Sx2, Array[x, k].Array[y, k] -> Sxy}

Again, I omit the output, but it certainly gives the right answer for
the

least squares estimators of a and b, in a relatively neat form, which
you

could further reduce if you wished to. And, of course, from this result
for

a particular value of n you might be able to infer the general formula.

I wonder if this is what you were looking for.

Tomas Garza

Mexico City

Barbara DaVinci [barbara_79_f at yahoo.it] wrote:

<Snip>
> I'm writing an educational notebook

> on least-square fit and in a subsection I must show

> how the well-known

> formula is carried out.

>

> This provides a symbolic data set :

> datsimx = Table[x[k], {k, 1, 10}]

> datsimy = datsimx /. x -> y

>

> {x, x, x, x, x, x, x, x, x,

> x}

> {y, y, y, y, y, y, y, y, y,

> y}

>

> Now I must declare x ... x and y ... y

> to be costants

> (otherwise D[] and Dt[] ...) .

>

> I tried two ways, both ineffective.

>

<Snip>

```

• Prev by Date: Re: How to keep things real?
• Next by Date: Re: Re: Simple integral wrong
• Previous by thread: Re: More troubles coming from indexed variables
• Next by thread: Re: Functional or rules-based equivalent for procedural program
{"ft_lang_label":"__label__en","ft_lang_prob":0.8491631,"math_prob":0.95130074,"size":2562,"snap":"2023-14-2023-23","text_gpt3_token_len":829,"char_repetition_ratio":0.096559815,"word_repetition_ratio":0.025423728,"special_character_ratio":0.3637783,"punctuation_ratio":0.208,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9935563,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-06-07T15:45:01Z\",\"WARC-Record-ID\":\"<urn:uuid:91fbd692-33f3-4e22-b7ec-c3d6db99cae7>\",\"Content-Length\":\"46362\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:37d80de3-a81b-4787-8ab5-b733b170351c>\",\"WARC-Concurrent-To\":\"<urn:uuid:5f0cd828-86c3-4123-b5e4-7fc4b786808a>\",\"WARC-IP-Address\":\"140.177.205.73\",\"WARC-Target-URI\":\"https://forums.wolfram.com/mathgroup/archive/2000/Sep/msg00112.html\",\"WARC-Payload-Digest\":\"sha1:EBNJC36BTW6CXPWBHBZPM4YRZOGK6YHK\",\"WARC-Block-Digest\":\"sha1:XLHCMHGBJ5KD56SNZVYPAQM6IVQQEYY7\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224653930.47_warc_CC-MAIN-20230607143116-20230607173116-00551.warc.gz\"}"}