将循环转换为数学方程式 [英] Convert loop into mathematical equation

查看:95
本文介绍了将循环转换为数学方程式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何用数学方程式表示for循环?

How would I represent this for loop in a mathematical equation?

double n = 1;
    double x = Math.pow(3, n);
    for(double i = 0; i < n; i++){
        x = x + Math.pow(3, i);
    }

抱歉,我们急忙用Java编写了它.

Sorry wrote it in Java in a hurry.

推荐答案

for循环可以简化为

for loop can be simplifed to

x= (pow(3,n)-1)/2

我在这里仔细检查过:

I have double checked this here:
http://www.wolframalpha.com/input/?i=sum+pow%283%2Ci%29+for+i+from+0+to+%28n-1%29

这篇关于将循环转换为数学方程式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆