COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### calculate Recurrence Equations

• Email
• Follow

```hi,

i?m in trouble with my Recurrence Equations:

i?ve defined the following function

anteil[0] = 1
anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100

i want mathematica to calculate the values for anteil[30] and so on.

Unfortunately mathematica needs for this calculation over 2 hours (and
is still running, athlon x2 4600, 2 gb ram).

I don?t see where are the difficulties for mathematica...

frank

```
 0
Reply frank.hechtner (10) 8/17/2006 8:40:30 AM

See related articles to this posting

```Hallo Frank,

try:

anteil[0] = 1
anteil[n_] := anteil[n] = anteil[n - 1] + (anteil[n - 1]*5 - 1)/100

and you might want to read the section on dynamic programming
(section 2.5.9) in the HelpBrowser

Oliver

On Thu, 17 Aug 2006, Frank Hechtner wrote:

> hi,
>
> i?m in trouble with my Recurrence Equations:
>
> i?ve defined the following function
>
> anteil[0] = 1
> anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100
>
> i want mathematica to calculate the values for anteil[30] and so on.
>
> Unfortunately mathematica needs for this calculation over 2 hours (and
> is still running, athlon x2 4600, 2 gb ram).
>
> I don?t see where are the difficulties for mathematica...
>
>
> frank
>
>

Oliver Ruebenkoenig, <ruebenko@uni-freiburg.de>
Phone: ++49 +761 203 7388

```
 0
Reply ruebenko1 (68) 8/18/2006 7:20:43 AM

```Frank

Check the section 2.5.9 in The Mathematica Book for an explanation of

anteil[n_] := anteil[n]=anteil[n - 1] + (anteil[n - 1]*5 - 1)/100

The effect of this is that the values of anteil[n] are stored when
first calculated, and not recalculated next time they are required.
You can see the effect by executing ?anteil after executing the
function.

On my PC anteil[30] runs in a second or so.

Regards
Mark Westwood

Frank Hechtner wrote:
> hi,
>
> i?m in trouble with my Recurrence Equations:
>
> i?ve defined the following function
>
> anteil[0] = 1
> anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100
>
> i want mathematica to calculate the values for anteil[30] and so on.
>
> Unfortunately mathematica needs for this calculation over 2 hours (and
> is still running, athlon x2 4600, 2 gb ram).
>
> I don?t see where are the difficulties for mathematica...
>
>
> frank

```
 0
Reply markc.westwood (96) 8/18/2006 7:23:48 AM

```Frank Hechtner wrote:

> hi,
>
> i?m in trouble with my Recurrence Equations:
>
> i?ve defined the following function
>
> anteil[0] = 1
> anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100
>

perfect problem for a function that remembers values it has already
calculated (see the mathematica book, section 2.5.9) Try the following:

anteil[n_] := anteil[n] = anteil[n - 1] + (anteil[n - 1]*5-1)/100

if you need even more speed and an approximate result is o.k., the following
might be even faster for large n, but could probably give you wrong results
(it does not for n=10,20,30):

anteil[n_] := anteil[n] = anteil[n - 1] + (anteil[n - 1]*5.-1.)/100.

hth,

albert

```
 0
Reply awnl (185) 8/18/2006 7:27:51 AM

```Hi.  I believe the syntax of your equations are a little off.  This worked
for me...

In[1]:=
equ = {
v[0] == 1,
v[n] == v[n - 1] + (v[n - 1]*5 - 1)/100
} ;

In[2]:=
RSolve[equ, v[n], n]

Out[2]=
{{v[n] -> (1/5)*(1 + 4^(1 - n)*(21/5)^n)}}

--
HTH.  :>)

Dana DeLouis
Mathematica 5.2

"Frank Hechtner" <frank.hechtner@rub.de> wrote in message
news:ec1a1u\$omo\$1@smc.vnet.net...
> hi,
>
> i?m in trouble with my Recurrence Equations:
>
> i?ve defined the following function
>
> anteil[0] = 1
> anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100
>
> i want mathematica to calculate the values for anteil[30] and so on.
>
> Unfortunately mathematica needs for this calculation over 2 hours (and
> is still running, athlon x2 4600, 2 gb ram).
>
> I don?t see where are the difficulties for mathematica...
>
>
> frank
>

```
 0
Reply ddelouis (10) 8/18/2006 7:30:53 AM

```"Frank Hechtner" <frank.hechtner@rub.de> wrote in message
news:ec1a1u\$omo\$1@smc.vnet.net...
> hi,
>
> i?m in trouble with my Recurrence Equations:
>
> i?ve defined the following function
>
> anteil[0] = 1
> anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100
>
> i want mathematica to calculate the values for anteil[30] and so on.
>
> Unfortunately mathematica needs for this calculation over 2 hours (and
> is still running, athlon x2 4600, 2 gb ram).
>
> I don?t see where are the difficulties for mathematica...

Redefine the function as follows.  (notice the extra = ???)

anteil[0] = 1
anteil[n_] := anteil [n] = anteil[n - 1] + (anteil[n - 1]*5 - 1)/100

They way you've inputed it, Mathematica needs to recalculate a[0 through n],
every time it increments "n".

Adding the extra syntax;     a[n_]:=a[n]= "the function"
forces Mathematica to commit all calculations to the cache, so as not to
re-evaluate what has already been evaluated.  This will significantly
decrease processing time.

```
 0
Reply stotz1 (17) 8/18/2006 7:36:56 AM

```Hello

If you modify (your expression) to:

anteil[0] = 1;
anteil[n_] := (anteil[n] = anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 )
anteil[30]//N

you can save the intermediate calculations. But even with this
modification you will run into problems for large n (a few 100),
because you build up your expression starting with the last index = n
and you will get a deeply nested expression (which might use up the

I would rather use the following command (which forward calculates the
expression starting with the starting value=1):

n=1000;Nest[(# + (#*5 - 1)/100) &, 1, n]//N

Even 1000 iterations work and need less than a second (on my computer).

Best Regards
Norbert Marxer
www.mec.li

Frank Hechtner wrote:
> hi,
>
> i?m in trouble with my Recurrence Equations:
>
> i?ve defined the following function
>
> anteil[0] = 1
> anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100
>
> i want mathematica to calculate the values for anteil[30] and so on.
>
> Unfortunately mathematica needs for this calculation over 2 hours (and
> is still running, athlon x2 4600, 2 gb ram).
>
> I don?t see where are the difficulties for mathematica...
>
>
> frank

```
 0
Reply marxer (143) 8/18/2006 7:50:04 AM

```Frank Hechtner wrote:
> hi,
>
> i?m in trouble with my Recurrence Equations:
>
> i?ve defined the following function
>
> anteil[0] = 1
> anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100
>
> i want mathematica to calculate the values for anteil[30] and so on.
>
> Unfortunately mathematica needs for this calculation over 2 hours (and
> is still running, athlon x2 4600, 2 gb ram).

Hi Frank,

The following definition should help:

anteil[0]=1;
anteil[n_]:= anteil[n]= anteil[ n-1]+ ( anteil[ n-1]*5-1)/100

anteil[30]
-->
4909085745117164100520051333566036654601/1342177280000000000000000000000000000000

See "Functions That Remember Values They Have Found"
http://documents.wolfram.com/mathematica/book/section-2.5.9

HTH,
Jean-Marc

```
 0
Reply jeanmarc.gulliet (2157) 8/18/2006 7:52:05 AM

```Do you need exact answers as integer factions?

In[1]:=
anteil[0] := 1. ;
anteil[n_] := 1.05 anteil[n - 1] - .01 ;
In[6]:=
Table[ { i, anteil[i]}, { i, 0, 35 } ] // TableForm

Seems to execute quickly.

I'm not sure why, but when there are two references, it seems to get
lost.

Paul

-----Original Message-----
From: Frank Hechtner [mailto:frank.hechtner@rub.de]
Subject:  calculate Recurrence Equations

hi,

i?m in trouble with my Recurrence Equations:

i?ve defined the following function

anteil[0] = 1
anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100

i want mathematica to calculate the values for anteil[30] and so on.

Unfortunately mathematica needs for this calculation over 2 hours (and
is still running, athlon x2 4600, 2 gb ram).

I don?t see where are the difficulties for mathematica...

frank

```
 0
Reply Paul.Erickson (34) 8/18/2006 8:02:11 AM

```Frank Hechtner schrieb:
> hi,
>
> i?m in trouble with my Recurrence Equations:
>
> i?ve defined the following function
>
> anteil[0] = 1
> anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100
>
> i want mathematica to calculate the values for anteil[30] and so on.
>
> Unfortunately mathematica needs for this calculation over 2 hours (and
> is still running, athlon x2 4600, 2 gb ram).
>
> I don?t see where are the difficulties for mathematica...
>
>
> frank
>

Hi Frank,

Mathematika doesn't remeber the values it has alraedy calculated. So
anteil[30] leads to 2^30 ~ 10^9 calls to anteil[]. If you store the
calculated values, the calls to anteil[] are 31:

In[1]:=
anteil[0] = 1;
anteil[n_] := anteil[n] = anteil[n - 1] + (anteil[n - 1]*5 - 1)/100;
AbsoluteTiming[anteil[30]]
Out[3]=
{0.*Second,
4909085745117164100520051333566036654601/1342177280000000000000000000000000000000}

But I prefer using RSolve[]:

In[1]:=
<< "DiscreteMath`RSolve`"
anteil = a /. First[RSolve[{a[0] == 1,
a[n] == a[n - 1] + (a[n - 1]*5 - 1)/100}, a, n]]
anteil[30]
N[%]

Out[2]=
Function[{n}, (1/5)*(1 + 4^(1 - n)*(21/5)^n)]
Out[3]=
4909085745117164100520051333566036654601/
1342177280000000000000000000000000000000
Out[4]=
3.6575539001205297

HTH,
Peter

```
 0
Reply petsie (836) 8/18/2006 8:04:12 AM

9 Replies
93 Views

Similar Articles

12/8/2013 3:05:04 PM
[PageSpeed]

Similar Artilces:

Question: calculate normal to a parabola
Hi, I need advice on how to calculate the coordinates of a vector normal to a parabola section. The parabola is defined by 3 points on a plane: (x1, y1), (x2, y2), (x3, y3). I need to calculate the coordinates of the end point of the normal vector with the starting point (x2, y2) and a prescrived magnitude A. Any help would be greatly appreciated. Thank you, David On May 10, 6:09 pm, copain <DHouc...@gmail.com> wrote: > Hi, > > I need advice on how to calculate the coordinates of a vector normal > to a parabola section. The parabola is defined by 3 points on a > plane: (x1, y1), (x2, y2), (x3, y3). I need to calculate the > coordinates of the end point of the normal vector with the starting > point (x2, y2) and a prescrived magnitude A. > > Any help would be greatly appreciated. The equation of the parabola will be y = a x^2 + b x + c. Set up three equations in three unknowns using the coordinates of your three points: a x1^2 + b x1 + c = y1 a x2^2 + b x2 + c = y2 a x3^2 + b x3 + c = y3 Solve these three equations for the unknowns, a, b, and c. From the calculus, the slope of the parabola at (x2, y2) is m = 2 a x2 + b Let d = A / sqrt

How to calculate R-square
Dear Matlab experts, Dear Dr. D'Errico, I would like to calculate R-square after fitting procedure. I know the formula of R-square which is: R-square=1-SSE/SST where SSE=sum(weight_i*(y_i-y_calculated_i)) SST=sum(weight_i*(y_i-mean(y_i))) here sum is summation over all fitting points, y_i is data to be fitted, y_calculated_i is y calculated by a model. Assume that I have a dataset of N points, first column is x, second is y and third is errorbar. I have a model for the data after fitting I get a 'y_calculated'. It is easy to calculate SSE but I don't know what is mean(y_i) in SST, since y_i is already mean(y_i), if I understand correctly. Thank you for teaching me this subject. Peter "Peter Pan" <thai_optics@yahoo.com> wrote in message <fgl7ol\$hu4 \$1@fred.mathworks.com>... > Dear Matlab experts, > Dear Dr. D'Errico, (smile) > I would like to calculate R-square after fitting procedure. > I know the formula of R-square which is: > R-square=1-SSE/SST > where SSE=sum(weight_i*(y_i-y_calculated_i)) > SST=sum(weight_i*(y_i-mean(y_i))) > here sum is summation over all fitting points, y_i is data > to be fitted, y

Calculate contour without plotting
Hello I need to call the 'contour' function without plotting the results. i.e. i need the output contour matrix only not the plot. ps: please don't tell me to close the window because the problem is that i am developing a real-time application. Regards 'contours' was what i was looking for.. "John Melek" <johnpccd@yahoooo.com> wrote in message <gmhr2t\$cll\$1@fred.mathworks.com>... > Hello > > I need to call the 'contour' function without plotting the results. > > i.e. i need the output contour matrix only not the plot. >

How to calculate the RMS of a waveform
Hi there, &nbsp; I haven�t worked with signal analysis yet, I need to calculate the RMS of the&nbsp;signal shown on the graph in the attached VI. &nbsp; I don�t need a final solution, just some hints or tipps...! &nbsp; Thank you in advance! RMS.vi: http://forums.ni.com/attachments/ni/170/130270/1/RMS.vi Hi, Use the waveform measurement functions. Check attachment, Hope it helps, Paulo RMS[1].vi: http://forums.ni.com/attachments/ni/170/130271/1/RMS[1].vi

how to calculate signal and noise power
how to calculate signal and noise power hello, i have a signal current I(t)=Acos(wt+theta) How can i calculate the signal power and noise power individually? thanks Reza On Nov 8, 4:23=A0am, "sunshineshuvo" <sohagiut@n_o_s_p_a_m.yahoo.com> wrote: > how to calculate signal and noise power > hello, > i have a signal current I(t)=3DAcos(wt+theta) > How can i calculate the signal power and noise power individually? > > thanks > Reza Assuming a resistive load: Turn on the signal and compute the product of RMS voltage and RMS current. This is the total (signal plus noise) power. Turn off the signal and repeat. This is the noise power. John

How to calculate the channel bandwidth with Matlab ?
Hello. I have a problem in calculation the bandwidth of channel, which contains variable signal and noise. What I have: 200 kHz channel, signal and noise ratio, which I must change. Calculation is based on Shannon equation: C=F*log2(1+S/N). For example, from 0 to 2 kHz I have S/N ration of 31 dBm, from 2 to 4 kHz - 30,5 dBm, from 4 to 6 kHz - 30 dBm and so go on, till I will reach 200 kHz. All this changes of S/N is needed, because I must simulate some types of color noise, like brown, rose and red. Then I must plot the picture of this and calculate the summary bandwidth of all frequency steps. So what is the best way how it can be done with Matlab?

How to calculate weighted mean in Matlab
I have a 180-by-360 matrix of (surface temperature) values and I want to calculate a weighted average of all values given in this matrix. However, I need to weight these values with respect to latitude. Is there a way to calculate a weighted mean in Matlab? Please help me. Thanks in advance for any help! - Jan-Erik A=3D180-by-360 matrix of (surface temperature) B=3D180-by-360 matrix of latitudes corresponding to A weighted mean=3D(sum(A.*B))/(180*360) On Sunday, 17 February 2013 20:16:14 UTC-5, Jan-Erik wrote: > I have a 180-by-360 matrix of (surface temperature) values and I want to = calculate a weighted average of all values given in this matrix. However, I= need to weight these values with respect to latitude. Is there a way to ca= lculate a weighted mean in Matlab? Please help me. >=20 >=20 >=20 > Thanks in advance for any help! >=20 >=20 >=20 > - Jan-Erik hesam eivazy <hesamaldien@gmail.com> wrote in message <25a0e76d-84b5-4aba-a3da-803630b7a046@googlegroups.com>... > A=180-by-360 matrix of (surface temperature) > B=180-by-360 matrix of latitudes corresponding to A > weighted mean=(sum(A.*B

Calculate distance-to-agreement of two matrices?
I wonder if any of you MATLAB whizzes out there can help me with this... I have two 2-D matrices of the same size. They show distribution of radiation in a target. The distributions are pretty much smooth, and mostly hill-like, i.e. maximum is near the centre. Values range from 0 to 150 double-precision values. The two matrices look very similar, but are generated from a simulation with slightly different inputs. One way to compare the distributions is by absolute or relative difference - that's easy. Another way is distance-to-agreement (DTA). DTA works like this: For each position in matrix 1, we want the distance from the corresponding position in matrix 2 to the nearest position in matrix 2 with the same value as the posiiton in matrix 1. Basically, we have to plot contours of the distributions, and the contours have to match within a certain distance tolerance, and I'm looking at how to calculate that distance. The only way I've yet to come up with is to calculate the distance to every position, and it's value, then take the nearest one of the same value (or within a 0.1 value threshold). However, this is order n-squared cacluation time

How to calculate average leads by day
People,=0AI have a datafile that includes create_dt monthdt and ctr=0Acreat= e_dt monthdt ctr=0A01/10/06 10 1=0A01/10/06 10 = 1=0A02/10/06 10 1=0A.=0A.=0A.=0A31/10/06 10 1=0A= 01/11/06 11 1=0A02/11/06 11 1=0A02/11/06 11 = 1=0A.=0A.=0A.=0A30/11/06 11 1=0A01/12/06 12 1=0A.=0A= ..=0A.=0A31/12/06 12 1=0A=0AI want to sum the ctr and divide by th= e number of days in each month.=0Adesired output=0Amonth total average = leads per day =0A10 62 2=0A11 90

Calculate the procurement cost of Web reporting tool
Generally, Web reporting tool accounts for about 10% of a software development project. In recent 2 years, it showed an increasing trend. According to my own projects, the cost of Web reporting tool can reach 20% at most. However, in calculations below, we still use 10% as a standard, and assume the cost of each man-month as \$2,500. Take a \$100,000 software development project for example, then the procurement cost of Web reporting tool is \$10,000. As the cost of each man-month is \$2,500, it needs 4 employees to accomplish the report. In a practical project, there are several ways to