I am new to octave. I want to plot lh value for each theta. I am calculating that lh value using below function.
function lh = compute_lh (D, theta)
lh = 1
for i=D
if i == 1
lh = lh * theta
else
lh = lh * (1-theta)
endif
end
endfunction
D = =[1,1,1,1,1,1,0,0,0,0] where theta is generated with theta = 0:0.01:1
plot(theta,compute_lh(D,theta))
error: compute_lh: operator *: nonconformant arguments (op1 is 1x101, op2 is 1x101) error: called from compute_lh at line 29 column 10 error: evaluating argument list element number 2
I don't know why that theta is converted to matrix while plotting.
lh=theta.^sum(D==1).*(1-theta).^(sum(D~=1))is easier than this? Evenlh=theta.^nnz(D).*(1-theta).^nnz(~D)ifDonly has 1's or 0's. - David