0

I keep getting a matrix dimension error, although i pay attention to the array operators from the below code. As I am not willing to strictly perform matrix operations could someone explain the origin of the dimension / size issue?

Thanks

Error using .* Matrix dimensions must agree

% integrand behaviour
f=@(k) k .* exp(-k);
x=0.5;
al=1;
bet=0.89;
theta0=(1/al) .*atan(bet .*tan(pi*al/2));
c=exp(-(pi .* x) ./2 * bet);
c2=1 /(2.*abs(bet));
v1=@(theta) 2/pi .* ((pi/2 + bet.*theta)/cos(theta)) .* exp(1/bet .* (pi/2 +
bet.*theta)...
.* tan(theta));
g=@(theta) c .* v1(theta);
y=@(theta) f(g(theta)) ;     % values of integrand
a=[-pi/2:0.2:pi/2]';
Y=y(a);
plot(a,Y)

1 Answer 1

1

The source of your problem is here:

(pi/2 + bet.*theta)/cos(theta)

You use the / operator, where I think that you mean to use the ./ operator.

Sign up to request clarification or add additional context in comments.

3 Comments

it does not matter that much. I just realize that the source of the matter is the column vector 'a'. Actually the code works for any scalar (e.g a = pi/6, etc.) thus a solution is to make it work on vectors as far as i am concerned.
It does matter. Indeed, your a is a 16 element column vector. The line I highlighted will turn this into a 16x16 matrix, which is obviously wrong. Remember, that / is a matrix operator, while ./ works element wise.
Many thanks for your prompt feedback, as I definitely missed ./ cos(theta). You're right. Cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.