Posts

Showing posts from February, 2023

POWER METHOD

/* 1. Start 2. Get the values of a,x aerr, maxtir 3.  Define Subroutine findmax 4. Call function findmax with e, x, n 5. Loop for itr = 1 to maxtir 6.  Calculate r = a*x 7.  Call function findmax with t, r, n 8.  normalise  r 9.  maxe = 0; 10.  Loop for i = 0 to N-1 11.  err = fabs(x[i] - r[i]) 12.  Is err>maxe, if yes maxe = err otherwise proceed 13.  x[i] = r[i] 14.  End Loop (i) 15.  errv = fabs(t-e) 16.  e = t 17.  Print results of Iteration 18.  Is errv < aerr  && maxe < aerr, if Yes Print Solution and STOP otherwise proceed 19.  End Loop (itr) 20.  Print Solution does not converge 21.  Stop Algorithm for findmax function   1.  max = fabs(x(1)) 2.  Loop for i = 1 to N-1 3.  Is fabs (x[i] > max?, If yes proceed otherwise go to step 5 4.  max = fabs(x[i]) 5.  End loop (i) 6.  Stop */  /* Power method for finding largest eigenvalue ...

TRAPEZOIDAL RULE

/* 1. Start 2. Define function f(x) 3. Read lower limit of integration, upper limit of integration and number of sub interval 4. Calculate: step size = (upper limit -lower limit)/number of sub interval 5. Set: integration value = f(lower limit) + f(upper limit) 6. Set: i = 1 7. If i > number of sub interval then goto 8. Calculate: k = lower limit + i * h 9. Calculate: Integration value =Integration Value + 2* f(k) 10. Increment i by 1 i.e. i = i+1 and go to step 7 11. Calculate: Integration value =Integration value * step size/2 12. Display Integration value as required answer 13. Stop */  /* Trapezoidal rule.*/ #include <stdio.h> float y(float x) {  return 1/(1+x*x); } main() {  float x0,xn,h,s;  int i,n;  puts("Enter x0,xn,no. of subintervals");  scanf ("%f %f %d",&x0,&xn,&n);  h = (xn-x0)/n;  s = y(x0)+y(xn);  for (i=1;i<=n-1;i++)  s += 2*y(x0+i*h);  printf ("Value of integral is % 6.4f\n",  (h/2)*s);...