Initially, you assign ‘g’ to the gravitational acceleration constant:
theta0 = pi/3; g = 9.81; L = 1;
then here you assign ‘g’ to the character vector ‘'Omega'’ that is a (1x5) character array:
f = 'Time'; g = 'Omega'; h = 'Theta'; p = 'Alpha'; q = 'Energy';
and that causes problems with ‘g’ in this line:
omega(k+1) = -g/L*sin(theta(k))*dt + omega(k);
that then throws the error and stops running the code.
If you correct that, by assigning ‘'Omega'’ to a different variable that is not used elsewhere in your code, you then encounter the problem with ‘^’ here because ‘omega’ is a vector:
Etotal = g*H + (1/2)*(L*omega)^2;
that you can correct by using element-wise exponentiation:
Etotal = g*H + (1/2)*(L*omega).^2;
I will let you do the necessary corrections.
.