Facebook
From as, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 241
  1. function rlc_f_newton_raphson
  2.     C1 = 2e-6;
  3.  
  4.     C2 = 7e-6;
  5.  
  6.     x = C1;
  7.  
  8.     if (f(x)*dfdf(x)>0)
  9.  
  10.         x = C1;
  11.  
  12.     else
  13.  
  14.         x = C2;
  15.  
  16.     end
  17.  
  18.     for i=1:100
  19.  
  20.         %x = x-f(x)/df_a(x)
  21.  
  22.         x = x-f(x)/df_n(x)
  23.  
  24.         if(abs(f(x)) < 1e-7)
  25.  
  26.             break;
  27.  
  28.         end
  29.  
  30.     end
  31.  
  32.     x
  33.  
  34.     i    
  35.  
  36. end
  37.  
  38. function y = f(x)
  39.  
  40.     L = 20e-3;
  41.  
  42.     y = 500 - 1./(2*pi.*sqrt(L*x))
  43.  
  44. end
  45.  
  46. function y = df_a(x)
  47.  
  48.     y = 0.562698./(x^(3/2));
  49.  
  50. end
  51.  
  52. function y = df_n(x)
  53.  
  54.     dx = 1e-8;
  55.  
  56.     y = (f(x+dx)-f(x))/dx;
  57.  
  58. end
  59.  
  60. function y = dfdf(x)
  61.  
  62.     y = -0.844047./(x^(5/2));
  63.  
  64. end