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 个评论
Bruno Luong
2022-8-3
编辑:Bruno Luong
2022-8-3
Here is one solution
n(1)=n(2)=... = n(6) = 1058 /6
All the different are
n(k+1)-n(k) = 0 = exp(k*(-Inf)) for k = 1..., 5, so it is an exponential function wrt k
回答(1 个)
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!