当前位置: 动力学知识库 > 问答 > 编程问答 >

Calculate the first N terms of a geometric sequence in Matlab

问题描述:

This question already has an answer here:

  • Common way to generate finite geometric series in MATLAB

    2 answers

网友答案:

First, you set the N terms for your sequence, i.e.: N = 10 %//set first 10

Now you want to make a vector from 1 to N, i.e.:

n= [1:N]
Un = 2.^n %//Note the dot is very important! I almost forgot
%//ans = [2,4,8,16...1024]

This would make function a vector of 1 by N where each element is the corresponding answer to your function.

for your second question (in comment)

you want to do something like:

Bflip = B' %//This flips the matrix B so that what use to be column is now rows

So Bflip would be the result you want, I tested with your example:

A = [2 2 2;4 4 4; 6 6 6];
B = [0 0 0; 1 1 1; 2 2 2];
Bflit = [     0     1     2
              0     1     2
              0     1     2]

This will generate a 3 dimension matrix. To call on each of the 4 sets of results, just do something like result1 = permutation(:,:,1)

分享给朋友:
您可能感兴趣的文章:
随机阅读: