MATLAB: Am trying to plot P and Q but the matrix dimensions seems to disagree with me.

matrix array

clc
clf
qmod = @(a) abs((k*exp(-2*(-(a + k)*(a - k))^(1/2))*(a/k - ((-(a + k)*(a - k))^(1/2)*1i)/k)*1i)/(exp(-2*(-(a + k)*(a - k))^(1/2))*(-(a + k)*(a - k))^(1/2) + exp(2*(-(a + k)*(a - k))^(1/2))*(-(a + k)*(a - k))^(1/2) + a*exp(-2*(-(a + k)*(a - k))^(1/2))*1i - a*exp(2*(-(a + k)*(a - k))^(1/2))*1i) + (k*exp(2*(-(a + k)*(a - k))^(1/2))*(a/k + ((-(a + k)*(a - k))^(1/2)*1i)/k))/(exp(-2*(-(a + k)*(a - k))^(1/2))*(-(a + k)*(a - k))^(1/2)*1i + exp(2*(-(a + k)*(a - k))^(1/2))*(-(a + k)*(a - k))^(1/2)*1i - a*exp(-2*(-(a + k)*(a - k))^(1/2)) + a*exp(2*(-(a + k)*(a - k))^(1/2))))^2/abs((k*exp(-2*(-(a + k)*(a - k))^(1/2))*1i)/(exp(-2*(-(a + k)*(a - k))^(1/2))*(-(a + k)*(a - k))^(1/2) + exp(2*(-(a + k)*(a - k))^(1/2))*(-(a + k)*(a - k))^(1/2) + a*exp(-2*(-(a + k)*(a - k))^(1/2))*1i - a*exp(2*(-(a + k)*(a - k))^(1/2))*1i) + (k*exp(2*(-(a + k)*(a - k))^(1/2)))/(a*exp(2*(-(a + k)*(a - k))^(1/2)) - a*exp(-2*(-(a + k)*(a - k))^(1/2)) + exp(-2*(-(a + k)*(a - k))^(1/2))*(-(a + k)*(a - k))^(1/2)*1i + exp(2*(-(a + k)*(a - k))^(1/2))*(-(a + k)*(a - k))^(1/2)*1i))^2
normwave = @(a) 1/(1+(2.*a./31400))
a=linspace(0.1,1);
P=normwave(a);
Q=qmod(a);

Best Answer

Somewhere in that humongous anonymous function you have made a mistake.
In this case the mistake is that you didn't use array operations, so all those products, powers and divisions are matrix operations.
Try to split qmod over multiple lines is segments that make sense. You could even consider writing the parts as separate anonymous functions. Then make sure to change matrix operations to array operations (replace * by .* etc).