Asked by Cheung Ka Ho
on 2 Jul 2017

Here is the equation I'm going to solve.

where epsilon is a variable.

I wrote the following code.

r = 1:(2^h)-1;

v = 1:h-1

T = exp(x*h/1000)+sum(exp((x/1000)*(cos(2*pi*r/(2^h))+cos(2*pi*r*(2^v)/(2^h)))));

I can run the code when h=2; however, when h becomes greater than or equal to 3, an error that input must be a scalar and a square matrix shows up.

Could anyone please help me on this error?

Answer by Matthew Taliaferro
on 2 Jul 2017

Edited by Matthew Taliaferro
on 3 Jul 2017

You cannot raise things to a power unless they are scalar or square (like the warning said). If you want to square each element, the notation is a little different.

h = 1:10

h_square = h.^2 % as opposed to h^2, which won't work

You also cannot divide something element by element unless it is a scalar.

r = 1:10; h = 1:10;

r_over_h = r./(h.^2); % as opposed to r/(h^2), which won't do what you think it does

Cheung Ka Ho
on 4 Jul 2017

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## Cheung Ka Ho (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/347116-solving-a-sum-of-series-of-exponential-function-with-a-sum-of-series-of-cosine-function-inside#comment_466478

## Torsten (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/347116-solving-a-sum-of-series-of-exponential-function-with-a-sum-of-series-of-cosine-function-inside#comment_466594

## Cheung Ka Ho (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/347116-solving-a-sum-of-series-of-exponential-function-with-a-sum-of-series-of-cosine-function-inside#comment_466618

Sign in to comment.