[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: average of a function
From: |
Henry F. Mollet |
Subject: |
Re: average of a function |
Date: |
Tue, 09 Nov 2004 09:31:06 -0800 |
User-agent: |
Microsoft-Entourage/10.1.1.2418 |
Hacking my way to a close enough? solution compared to answer below and the
one provided by P.K.
Henry
octave:8> t=(-1:0.01:5/2);
octave:9> y = t.^2 - 5.*t + 6*cos(pi*t);
octave:10> mean(y)
ans = -1.6253
octave:11> plot (t,y,"x")
octave:12> t=(-1:0.001:5/2);
octave:13> y = t.^2 - 5.*t + 6*cos(pi*t);
octave:14> mean(y)
ans = -1.6214
octave:15> t=(-1:0.0001:5/2);
octave:16> y = t.^2 - 5.*t + 6*cos(pi*t);
octave:17> mean(y)
ans = -1.6210
octave:18> format long
octave:19> mean(y)
ans = -1.62103554930008
octave:20> quad('x', -1, 5/2)/(5/2 - -1)
ans = -1.62099257606588
*** local user variables: % at the end
prot type rows cols name
==== ==== ==== ==== ====
rwd range 1 35001 t
rwd matrix 1 35001 y
on 11/9/04 2:10 AM, (Ted Harding) at address@hidden wrote:
> On 09-Nov-04 Fred J. wrote:
>> Hello
>>
>> debian 2.6.8 i686-pc-GNU/Linux
>> GNU Octave, version 2.1.60
>>
>> I just started with octave, and appreciate some help
>> with this simple
>> task, could not get much help from reading the FAQs
>> and the manual.
>>
>> OK,
>> I need to determine the average value of this function
>> which I expect
>> it to be -1.620993 but I am getting a different ans
>> and not sure if I am
>> using octave correctly.
>>
>> octave> function y=x(t), y = t^2 - 5*t + 6*cos(pi*t);
>> end;
>> octave> quad('x', -1, 5/2)
>> ans = -5.6735
>
> If I've understood correctly, your code returns the numerical *integral*
> of x(t) over the range (-1,2.5). The length of this range is 3.5.
>
> The *average* of the function is the integral divided by the length
> of the range. With your numerical answer I get
>
> (-5.6735)/3.5 = -1.621
>
> which is very close to the value (-1.620993) that you expected to get.
>
> Best wishes,
> Ted.
>
>
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <address@hidden>
> Fax-to-email: +44 (0)870 094 0861 [NB: New number!]
> Date: 09-Nov-04 Time: 10:10:21
> ------------------------------ XFMail ------------------------------
>
>
>
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
>
> Octave's home on the web: http://www.octave.org
> How to fund new projects: http://www.octave.org/funding.html
> Subscription information: http://www.octave.org/archive.html
> -------------------------------------------------------------
>
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------