0
votes

Doing some matlab work and keep getting: "Error using * Inner matrix dimensions must agree."

This is my code, what can I do to fix it?

a=2
b=5
x=[0:(pi/40):(pi/2)]
y=b*(exp(1).^(-a*x))*sin(b*x)*(0.012*(x.^4) -0.15*(x.^3) + 0.075*(x.^2) + 2.5*x)
1
You need to use element wise multiplications not matrix multiplications in the last statement - tpb261

1 Answers

0
votes

You are mixing elemnt-wise (.*) and matrix (*) multiplication. Since you want element-wise multiplication for the vector x, you have to make sure that every vector/vector operation is element-wise. You just missed a few dots, it should be like this:

y=b*(exp(1).^(-a*x)).*sin(b*x).*(0.012*(x.^4)-0.15*(x.^3)+0.075*(x.^2)+2.5*x)