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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:16:00+00:00 2026-06-13T22:16:00+00:00

I am so new to maple and I dont know what to do exactly!

  • 0

I am so new to maple and I dont know what to do exactly! I have 10 numbers, for finding k nearest number to any of this number I need to keep distances between all numbers and sort them, based on these distances I can get which x is the nearest x to current number so:

for i from 1 to 10 do
  for j from 1 to 10 do
    dist[j]     := abs(x[i]-x[j]);
    result[i,j] := abs(x[i]-x[j]);
  end do; 
end do;

for h from 1 to 10 do
  for k from 1 to 10 do 
    arr[k] := result[h,k];   
  end do;

  distances := (quicksort(arr,1,10));
  for t from 1 to 10 do
    sortedMatrix[h,t] := distances[t];
  end do; 
end do;

print(sortedMatrix);

Now I have distances and a number, but i dont know what the other number is?

  • 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-13T22:16:01+00:00Added an answer on June 13, 2026 at 10:16 pm

    If I understand correctly, you start with an array of N elements and you want, for each of those N elements, the nearest neighbour in that array.
    My approach would be to just sort the array first and then loop over it, setting each elements nearest neighbour equal to its neighbour in the sorted array.

    Example: suppose you have the array [5,1,86,54,23,46]. If you sort that, you get [1,5,23,46,54,86]. To find the nearest neighbours, you go over the array and look at both elements adjacent. For example, 46 has 23 and 54 as neighbouring elements in the sorted array. 45 is closest to 54 so that’s his neighbour.

    There is no need to calculate all distances (n*n differences) between elements, you only need the distances between neighbouring nodess in the sorted array (2*n differences).

    You can expand that for k nearest neighbours by looking to the k nearest neighbours in the sorted array (2*k*n differences).

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

Sidebar

Related Questions

New to PHP and MySQL, have heard amazing things about this website from Leo
New to Regex. I want to validate to this format: Any character allowed, except
New programmer here, I am trying to understand and break down this code below
Consider this jsfiddle: http://fiddle.jshell.net/maple/JbEJN/show/ (this is the result window, in order for replaceState to
I'm setting the radio button like this: $gender = new Zend_Form_Element_Radio('gender'); $gender->setLabel('Gender') ->addMultiOptions(array('m'=>'Male','f'=>'Female')) ->setDecorators(array('ViewHelper'))
I'm new to JavaScript and I can't figure out why this code isn't working.
Ok, I'm not great at explaining this as I'm new to Android so work
I am trying to do this, and I really need help from expirienced fellows.
Here I have a small VBS script that helps me append a new line
I'm pretty new to rails and this is also my first post, but I'm

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.