0
votes

I am trying to plot this function in matlab but I get the error: Error using * Inner matrix dimensions must agree

Why is this happening?

My code:

H_s=2;

f_zero=2;

f=0:0.001:0.01;

S_f=(5*(H_s).^2)/(16*f_zero)*(f/f_zero).^(-5)*exp(-(5/4)*f)   

plot(f,S_f)
1

1 Answers

1
votes

The first terms ((5*(H_s).^2)/(16*f_zero)*(f/f_zero).^(-5)) evaluate to a 1x11 matrix, as does the last term (exp(-(5/4)*f)). The matrix multiplication operator * indeed requires the inner dimensions to match. But you were probably trying to do element-wise multiplication .*:

S_f=(5*(H_s).^2)/(16*f_zero)*(f/f_zero).^(-5).*exp(-(5/4)*f)