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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:57:41+00:00 2026-05-25T12:57:41+00:00

I have an array contanining the position of the different objects in my scene.

  • 0

I have an array contanining the position of the different objects in my scene.
To calculate the next movement step

I want to build a function like this:

f(x) = 1/(x-pos1)^2 + 1/(x-pos2)^2 + ...
       ^term1         ^term2         ^term_n

I don’t know how many objects are in my scene so I want to add terms in the function for each objects:

something like:

for object in scene:
     add_one_term_to_the_function
return function

is there a way to program this?
Preferably in C++ or Python… the only two languages I know…

PS: thx for the answers… but a loop is not what I’m looking for. This would be extremly slow.. because it will calculate the function everytime I call a next event… but I want to calculte it only once… and then pass the events to the calculated “function”…

  • 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-05-25T12:57:41+00:00Added an answer on May 25, 2026 at 12:57 pm

    Why not loop over them?
    It’s not going to be very much slower than otherwise.

    def f(x,poslist):
      v = 0
      for pos in poslist:
        v += 1/((x-pos)*(x-pos))
      return v
    

    If you really want to do it in python you can do it like this (but I beleive it’s going to be very slow)

    def addterm(f, pos):
      def g(x):
        return f(x)+1/((x-pos)*(x-pos))
      return g
    
    def zero(x): return 0
    f = zero
    for pos in poslist:
      f=addterm(f, pos)
    

    There is no real analogue in C++, because C++ doesn’t have closures.
    One could simulate it, but it won’t be the same, and then you could use a list and a loop instead anyway.

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

Sidebar

Related Questions

I have an array containing a list of files. I want to sort it
Ruby 1.8.6 I have an array containing numerical values. I want to reduce it
I have a 1d array containing Nd data, I would like to effectively traverse
I have an array list containing objects from the class EventOnMap . Every object
I have an array list containing few elements. What i want to do is
I have an array of Range objects with properties Offset and Length, as shown
I want to make a view move to a different position on window resize.
I have an array containing the hrefs of colours and I want to go
I have an array containing names of items. I want to give the user
I have an array containing words, some of them with accents. I want to

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.