I need to split a number into N parts such that the difference between each part is exponentially increasing

4 次查看(过去 30 天)
Hi, I need to split a number into N parts, for eg. number 1058 should be divided into 6 numbers (the sum of the 6 numbers will be equal to 1058) such that the difference between the numbers is exponentially increasing.
To elaborate if the 6 numbers are [n1, n2, n3, n4, n5, n6], the numbers n2-n1, n3-n2, n4-n3, n5-n4 give an exponential function.
Thanks for your help

回答(1 个)

Abhishek Chakram
Abhishek Chakram 2023-9-22
Hi Jyoti Mangal,
It is my understanding that you are facing difficulty in writing the code to divide a number into N parts such that difference between each part is exponentially increasing and sum of all the parts is equal to the number itself.
You can use the concept of geometric progression (GP) for it.
Here’s an example for the same:
gp_sum = 4586; % The number to be split
N = 6; % Number of parts
r = 2; % Common ratio for geometric progression
starting_number = (gp_sum * (r - 1)) / (r^N - 1); % starting number of geometric progression
split_numbers = zeros(1, N);
split_numbers(1) = starting_number;
for i = 2:N
split_numbers(i) = starting_number * r^(i-1);
end
sum(split_numbers); % Prints the sum of splited numbers that is equal to number itself
split_numbers; % Prints the splited numbers
Best Regards,
Abhishek Chakram

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by