# Defining a MATLAB code for a series expansion

Status
Not open for further replies.

#### rakue

##### Newbie level 5 Hi guys, I'm relatively new to the matlab designing process (i.e. making good use of it's vector-based system) I need help producing a matlab code for the following equation: is there a way to be able to produce it using matrices without the tedious use of for and while loops? or is there no other way?

thank you very much for any help that guys can extend.

#### hate

##### Member level 4 That equation doesn't seem to be following a pattern so it'll be easier to input by hand.

#### rakue

##### Newbie level 5 That equation doesn't seem to be following a pattern so it'll be easier to input by hand.

Hi thanks for your reply. actually there is a pattern. It's basically a combination of the powers of T_RF, T_LO and T_IF from 0 to 2.

I'm hoping I could come up with a "generalized" code so that if I decide to add more T variables and increase the power up to say, 6 or 8.

#### rakue

##### Newbie level 5 Okay I realized that a possible approach would be to use permutations like say for my 3 variables x,y,z I want to make a permutation of their powers from 0 to 2 such that the output would look like this

0 0 0
0 0 1
0 1 0
1 0 0
0 1 1
1 1 0
1 0 1
1 1 1
.
.
.
2 2 2

and then using the output for each row from the matrix produced, assign that element to my variables.

will that work? if so, can anyone tell me how? thank you~

#### hate

##### Member level 4 Hi thanks for your reply. actually there is a pattern. It's basically a combination of the powers of T_RF, T_LO and T_IF from 0 to 2.

I'm hoping I could come up with a "generalized" code so that if I decide to add more T variables and increase the power up to say, 6 or 8.

So, what's the pattern here? The pattern must match certain rules if you'll write a compact equation and did you notice the multiplier count for each term is not constant? The constants (I'm guessing they are constants) from m8 to m19 have only 2 variables in the multiplication while the last 8 have 3. So again what's the pattern here? I think the best you can do is to divide the total formula into 4 parts each for the number of variables in each term (0, 1, 2, 3).

#### zorro Hi rakue,

Please analyse this. I use 3-dimensional arrays:

T1 = [ 1, T_RF, T_RF*T_RF ];
T2 = [ 1, T_LO, T_LO*T_LO ];

T12 = T1.' * T2;

T123 = cat(3, T12, T12*T_IF, T12*T_IF*T_IF);

% Here, M must be a 3*3*3 array containing the 27 "m" coefficients

mc = sum(sum(sum(M .* T123)))

Regards

Z

#### zorro In order to see the structure of the resulting array T123, it is possible to generate it as a symbolic variable in the following way. Type these commands:

syms T_RF T_LO T_IF

T1 = [ 1, T_RF, T_RF*T_RF ];
T2 = [ 1, T_LO, T_LO*T_LO ];

T12 = T1.' * T2;

T123 = cat(3, T12, T12*T_IF, T12*T_IF*T_IF)

Then T123 is printed like this:

123 ,:,1) =

[ 1, T_LO, T_LO^2]
[ T_RF, T_RF*T_LO, T_RF*T_LO^2]
[ T_RF^2, T_RF^2*T_LO, T_RF^2*T_LO^2]

T123 ,:,2) =

[ T_IF, T_IF*T_LO, T_IF*T_LO^2]
[ T_IF*T_RF, T_IF*T_RF*T_LO, T_IF*T_RF*T_LO^2]
[ T_IF*T_RF^2, T_IF*T_RF^2*T_LO, T_IF*T_RF^2*T_LO^2]

T123 ,:,3) =

[ T_IF^2, T_IF^2*T_LO, T_IF^2*T_LO^2]
[ T_IF^2*T_RF, T_IF^2*T_RF*T_LO, T_IF^2*T_RF*T_LO^2]
[ T_IF^2*T_RF^2, T_IF^2*T_RF^2*T_LO, T_IF^2*T_RF^2*T_LO^2]

Regards

Z

• rakue

### rakue

Points: 2

#### rakue

##### Newbie level 5 Thank you very much, Zorro. Sorry for the noob-ish question, but is it possible to use syms in my code and then eventually replace the variables with actual data from a separate file?

Status
Not open for further replies.