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 7795977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:13:43+00:00 2026-06-01T23:13:43+00:00

Hey I have a problem with my simulation. I am a Ruby-Starter and don’t

  • 0

Hey I have a problem with my simulation.

I am a Ruby-Starter and don’t know what’s wrong in my code. That is only the part with the simulation:

def mean
 mean = self.reduce(:+)/self.length.to_f
 return mean
end

def randn
  begin 
  rg1 = (rand*2)-1 
  rg2 = (rand*2)-1 
  q = rg1**2 + rg2**2
  end while (q == 0 || q > 1)
  p = Math.sqrt((-2*Math.log(q))/q)

  rn1 = rg1 * p
  rn2 = rg2 * p
  return rn1, rn2
 end

monte_carlo = 10
ren1_sim = Array.new
ren2_sim = Array.new

monte_carlo.times {
 (1..20).each{ |i|
 (1..250).each { |j|
  r = randn() 
    ren1= * Math.exp(mu_ren1 + sigma_ren1 * r[0]) 
    # ren1 is an array with prices, mu_ren1 and sigma_ren1 are individual values

    ren2= * Math.exp(mu_ren2 + chol_21 * r[0] + chol_22 * r[1])
    # chol_21 and chol_22 are also individual values

     ren1_sim.push(ren1)
     ren2_sim.push(ren2)
   } 
  }
 }
 puts ren1_sim.mean
 puts ren2_sim.mean

I don’t get an error without the last two puts, but when I want to calculate the average of the arrays ren1_sim and rent_sim I get the error:

 undefined method 'mean' for #<Array:0x2acf318> (NoMethodError)

Do you know how to fix that?

  • 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-01T23:13:45+00:00Added an answer on June 1, 2026 at 11:13 pm

    You’re trying to invoke mean on an Array, which is not a method of Array. Perhaps you meant to use Statsample::Vector, which is Statsample’s extension of Array, and does have mean?

    ren1_sim = Statsample::Vector.new
    ren2_sim = Statsample::Vector.new
    

    You can also call to_vector on an Array instance to get a Statsample::Vector.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, I have a problem with a code that I've been writing. I
Hey guys, I have a weird problem. I have an update system that refreshes
Hey dudes.i am having this problem while symlinking. I have successfully deployed a ruby
hey there i am having problem i have List<List<memoryCard>> that i want to show
Hey! i want to know the best solution for my problem. I have a
hey I have a small problem with my rake class CreateEvents < ActiveRecord::Migration def
Hey! Have a problem that is driving me crazy! My Main Window will not
hey all i have a problem in webservice that i am consuming. it takes
Hey guys i have a problem. I have a listview that is dynamically filled.
Hey I have a problem in Javascript-PHP variable passing heres my php code: <li

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.