Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8774477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:34:40+00:00 2026-06-13T18:34:40+00:00

I’m trying to design a Ruby script that will help with RC/RL circuit design

  • 0

I’m trying to design a Ruby script that will help with RC/RL circuit design by taking values of E24 series resistors and E12 and E6 series capacitors and inductors. Basically just cycling through each possible combination with the equation F = 1 / ( 2 * Pi * R * C ) [for the RC circuit for eg].

I’m not after efficiency here, just reliability. I need it to cycle through every single combination of the resistor array and capacitor/inductor array (never all 3) using the values for the equation above and if it is within plus/minus x% of a certain value to return which values in the array it used. I can nest 2 for loops to go through each combination, but I want it to not just return values within a tolerance but tell me which value is the closest (or exact).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:34:41+00:00Added an answer on June 13, 2026 at 6:34 pm

    This is a mild refactoring of your code:

    # I noticed that your resistance array is just the same set of values
    # repeated with factors from 1 to 1000000, so this would be more concise
    # way of defining it (and less prone to typing errors):
    RES_ARRAY = [*-1..5].map{ |e| 10 ** e }.map{ |factor|
                 [ 10, 11, 12, 13, 15, 16, 18, 20,
                   22, 24, 27, 30, 33, 36, 39, 43,
                   47, 51, 56, 62, 68, 75, 82, 91 ].map{ |e| e * factor }
               }.reduce( :+ )
    
    # Global variables should be used very rarely. Constants should be written IN UPCASE:
    CAP_ARRAY, IND_ARRAY = [], []
    BREAK_FREQ = 19 * ( 10 ** 3 )
    
    # Whole words should be used whenever possible in the code:
    TOLERANCE = 0.997
    
    # Methods should be named in snake_case:
    def make_array( j, arr )
      # Let us use #each_slice and #map insterad of % and << operators:
      arr.each_slice( j ).map( &:first ).map{ |e| e * 1e-9 }
    end
    
    def cap_test
      puts "RC Circuit Estimation"
      for i in 0...RES_ARRAY.size
        for j in 0...CAP_ARRAY.size
          n = 1 / ( 2 * Math::PI * RES_ARRAY[ i ] * CAP_ARRAY[ j ] )
          if n > BREAK_FREQ * TOLERANCE and n < BREAK_FREQ * ( 2 - TOLERANCE )
            diff = 100 - ( ( n - BREAK_FREQ ) / BREAK_FREQ ).abs
            puts "Resistor:  #{RES_ARRAY[ i ]} Ohms"
            puts "Capacitor: #{CAP_ARRAY[ j ].to_f} F"
            puts "Within #{diff}%"
            puts "---------------------"
          end
        end
      end
    end
    
    def ind_test
      puts "RL Circuit Estimation"
      for i in 0...RES_ARRAY.size
        for j in 0...IND_ARRAY.size
          n = RES_ARRAY[ i ] / ( 2 * Math::PI * IND_ARRAY[ j ] )
          if n > BREAK_FREQ * TOLERANCE and n < BREAK_FREQ * ( 2 - TOLERANCE )
            diff = ( 1 - ( ( n - BREAK_FREQ ) / BREAK_FREQ ).abs ) * 100
            puts "Resistor:  #{RES_ARRAY[ i ]} Ohms"
            puts "Inductor: #{IND_ARRAY[ j ].to_f} H"
            puts "Within #{diff}%"
            puts "---------------------"
          end
        end
      end
    end
    
    make_array 2, CAP_ARRAY
    make_array 4, IND_ARRAY
    cap_Test()
    ind_Test()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.