Как СУММА может быть повторена в уравнении, пока ответ не станет меньше или равен 1?

477
deflime

Базовое уравнение

(J3+x)/150 

Умножьте ответ, xзатем разделите все на 150и повторите

( ((J3+x)/150)x )/150 (( ( ((J3+x)/150)x )/150 )x)/150 

Продолжайте повторять, пока ответ на последний повтор не будет <=1. Сумма всех частей.

Возможно, визуально это лучше объяснит. enter image description here

Прямо сейчас я просто разбил уравнение на несколько ячеек и затем суммировал их, но это ужасно неэффективно.

A1: =(J3+x)/150 B1: =(((J3+x)/150)x)/150 C1: =(( (((J3+x)/150)x)/150 )x)/150 D1: =(( (( (((J3+x)/150)x)/150 )x)/150 )x)/150 E1: etc, etc 
1
Может ли J3 или x быть отрицательным? fixer1234 9 лет назад 0
Этого никогда не случится. deflime 9 лет назад 0
Для этого потребуется решение VBA. К вашему сведению, x должно быть <150, иначе не будет слагаемого <= 1. fixer1234 9 лет назад 0
Правильно, `x` не должен превышать 150. deflime 9 лет назад 0
Могу ли я проверить, у меня есть это право? Если, например, J3 = 10000 и x = 20, то A1 = 66,8, B1 = 8,9, C1 = 1,19 и D1 = 0,16, так что это последнее значение <1, вы хотите просто сложить эти 4 значения и получить результат 77,05 (приблизительно)? barry houdini 9 лет назад 0
Это точно правильно. В моей рабочей тетради в настоящее время она охватывает 8 ячеек, и, как вы можете себе представить, она колеблется с умеренным изменением на `x`. deflime 9 лет назад 0

2 ответа на вопрос

2
Gary's Student

Put the following User Defined Function (UDF) in a standard module:

Public Function deflime(J3 As Variant, x As Variant) As Double deflime = 0 result = (J3 + x) / 150 For i = 1 To 9999 deflime = deflime + result If result <= 1 Then Exit Function End If result = x * result / 150 Next i End Function 

User Defined Functions (UDFs) are very easy to install and use:

  1. ALT-F11 brings up the VBE window
  2. ALT-I ALT-M opens a fresh module
  3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it. If you are using a version of Excel later then 2003, you must save the file as .xlsm rather than .xlsx

To remove the UDF:

  1. bring up the VBE window as above
  2. clear the code out
  3. close the VBE window

To use the UDF from Excel:

=deflime(A1,B1) 

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

and

http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx

and for specifics on UDFs, see:

http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx

Macros must be enabled for this to work!

Here is an example:

enter image description here

0
barry houdini

I see you have a VBA solution but it is possible to do this with formulas.

Assuming your "x" value is in J2 put this formula in J4 to give the number of iterations that will take you to <= 1 for the first time

=MATCH(TRUE,(J3+J2)/150^*J2^<=1,0)

and then this formula in J5 to get your final value

=SUMPRODUCT((J3+J2)/150^ROW(INDIRECT("1:"&J4))*J2^(ROW(INDIRECT("1:"&J4))-1))

That first formula limits you to 10 iterations but you could expand that if required.....or even amalgamate those two formulas in to one "megaformula"

in my tests those formulas gave me the same results as Gary's Student's UDF

Похожие вопросы