0% found this document useful (0 votes)
47 views

Computational Physics Lab Test 2011: 1 The Problem

This document summarizes an experiment calculating integral powers of x = (√5 - 1)/2 using a recursive relation and comparing the results to actual values calculated with a pow() function. For x^16, x^30, and x^40, the recursive values differed significantly from the actual values, demonstrating that the recursive relation becomes unstable for higher powers. The recursive relation accurately calculates lower powers but fails for higher powers due to accumulation of errors from the recursion.

Uploaded by

prahalad19
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Computational Physics Lab Test 2011: 1 The Problem

This document summarizes an experiment calculating integral powers of x = (√5 - 1)/2 using a recursive relation and comparing the results to actual values calculated with a pow() function. For x^16, x^30, and x^40, the recursive values differed significantly from the actual values, demonstrating that the recursive relation becomes unstable for higher powers. The recursive relation accurately calculates lower powers but fails for higher powers due to accumulation of errors from the recursion.

Uploaded by

prahalad19
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Computational Physics Lab Test 2011

Sayan Chatterjee 11PH40043 January 25, 2012

The Problem

Problem No 3: It is desired to calculate all integral powers of the number x = ( (5.0) 1.0)/2.0 It turns out that the integral powers of x satisfy a simple recursive relation x(n+1) = x(n1) xn Show that the above recurrence relation is unstable by calculating x16 , x30 , x40 and x50 from the recurrence relation and comparing with the actual values obtained by using inbuilt function e.g., pow(a,b) in C.

2
2.1

Method
The program

#include<stdio.h> #include<math.h> main() { double x=(sqrt(5.0)-1.0)/2; double p,y1,y; int i,n; float f(int n); printf("\nThe value of x is : %e",x); printf("\nEnter the value of n :: "); scanf("%d",&n);

//Actual Value Evaluated using pow() y1=pow(x,n); y=f(n); printf("\n\n\n\tRecursive value is %e Pow value is %e",y,y1); printf("\n\n\t\tDifference is :: %e \n",y-y1); } //Recursive Value float f(int n) { double x=(sqrt(5.0)-1.0)/2; if(n>=2) return(f(n-2)-f(n-1)); if(n==1) return(x); if(n==0) return(1); }

2.2

Inputs and Outputs from Linux Terminal

[sayan@Sayan C_Programs]$ ./prob3 The value of x is : 6.180340e-01 Enter the value of n :: 30

Recursive value is -1.365757e-02 Pow value is 5.374905e-07 Difference is :: -1.365811e-02

***************************************** [sayan@Sayan C_Programs]$ ./prob3 The value of x is : 6.180340e-01 Enter the value of n :: 40

Recursive value is -1.679836e+00 Pow value is 4.370130e-09

Difference is :: -1.679836e+00

Results

Here we can see higher the value of n,the greater is the dierence between the actual value and the recursive value.The recursion relation holds good only for lower values of n.

Discussions and Conclusions

The method of iteration which we tried at rst for evaluating the recurrence failed,because at the time of iteration we were actually performing the multiplication etc. leading to the null dierence between the concerned results. The report has been prepared using TEX.

You might also like