Errors in my program with mpower and mtimes
3 views (last 30 days)
Show older comments
I am writing a program to find conditional density functions for a transmitter going through Gaussian noise to receiver. In order to make plots for f(x|y) vs x given different values for y I need to have f be a piece wise function which I have shown below. These are the errors I am getting when trying to run my program.
??? Error using ==> mtimes Inner matrix dimensions must agree.
Error in ==> PartA at 6 k1 = int((x/(25*((8*3.14).^(1/2)))*(e.^((-(y-x).^2)/8))),x,0,5);
Here is my function and main program. If anyone knows what I am doing wrong please help.
i = 1;
y = -5;
e = 2.71;
x = 0 : 0.1 :10;
while(y <= 20)
k1 = int((x/(25*((8*3.14)^(1/2)))*(e^((-(y-x)^2)/8))),x,0,5);
k2 = int((0.4-(x/25))*(1/((8*3.14)^(1/2))*(e^((-(y-x)^2)/8))),x,5,10);
f = piecewise(x,y,k1,k2);
figure(i)
plot(x,f,'.');
y = y + 5;
i = i + 1;
end
function [ f ] = piecewise( x , y , k1, k2 )
e = 2.71;
if x > 0 && x <= 5
f = ((1/k1) * (x/(25*((8*3.14)^(1/2))) * (e^((-(y-x)^2)/8))));
elseif x > 5 && x <= 10
f = ((1/k2) * (0.4-(x/25)) * (1/((8*3.14)^(1/2))*(e^((-(y-x)^2)/8))));
else
f = NaN;
end
end
0 Comments
Answers (2)
dpb
on 14 Apr 2014
Error in ==> PartA at 6
k1 = int((x/(25*((8*3.14).^(1/2)))*(e.^((-(y-x).^2)/8))),x,0,5);
Looks like you're missing the 'dot' on the '.*' operator. You used it for the exponent, but unless you're intending doing a matrix multiplication of the vectors instead of element-by-element, you need it there, too.
0 Comments
Cameron
on 14 Apr 2014
2 Comments
dpb
on 14 Apr 2014
Whatever changes you've made, you still didn't change the '*' to '.*' in
Error in ==> fun1 at 3 f1 = (x/(25*((8*3.14).^(1/2))) * (e.^((-(y-x).^2)/8)));
What are dimensions of x and y and what is the dimension of f1 intended to be?
Star Strider
on 14 Apr 2014
I suggest putting ‘.’ in front of every *, / and ^ operator in a function unless you know you want to do matrix operations.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!