2^1+2^2+2^3+2^4.......用matlab怎么算

2025-01-06 02:21:12
推荐回答(3个)
回答1:

设s=2^1+2^2+2^3+2^4.......+2^n
2s=2^2+2^3+2^4.......+2^n+1
2s-s=2^n+1-2
2^1+2^2+2^3+2^4.......+2^n=2^(n+1)-2

回答2:

sum(2.^(1:n));

回答3:

n=input('n=')
x=1:n;
y=2.^x;
sum(y)