@problem@
	@config@
		matlab = true
	@;config@
	@problemtype@
		embedded
	@;problemtype@
	@name@
		tutorial_11_matlab
	@endname@
	@preamble@
		x = randintex(2,35,[4,9,16,25])
		p = matlab.rand(1)
		c = matlab.norminv(p)
		@matlab@
			A = randi(7);
			B = [1 2; 3 4];
			x = 35 + sum(sum(A.*B));
		@endmatlab@
	@;preamble@
	@content@
		In many cases, Matlab is far more suitable for computations of correct answers to exam questions than Python. Once the Matlab engine API has been installed successfully, and the configuration option 'matlab' has been set to 'true', you can execute and evaluate Matlab code in two different ways.
		@pb;@
		First, during compilation, an initialized Matlab engine object is available within the local Python environment under the variable name "matlab", both in the preamble and in the content. For example, the command "matlab.normcdf(0.42)" will be evaluated as the value of the standard normal distribution function at 0.42, which can be expressed as
		\[
			\Phi(0.42) \approx @num(matlab.normcdf(0.42),keepFloat=4)@
			\,.
		\]
		Similarly, due to the variable assignments in the preamble,
		\[
			\Phi(x) = @num(p,keepFloat=4)@ \quad\implies\quad x \approx @num(c,keepFloat=4)@
			\,.
		\]
		In general, you can use this method to call arbitrary Matlab functions. You can run custom scripts and functions as well, provided that the path variables are set globally in your Matlab installation (otherwise you would need to call 'matlab.addpath(...)' in the preamble).
		@pb;@
		Alternatively, if you need to execute larger amounts of Matlab code, you can use 'matlab' blocks which will be executed line by line if encountered in the preamble and evaluated (as a single line) when appearing in the content. Note that all variable assigments within Matlab code are restricted to the Matlab workspace, which is distinct from the local Python environment. For example, the variable "x" declared in the 'matlab' block in the preamble does not conflict with the variable "x" previously declared in the Python code. The former can be accessed only in another matlab block, i.e.
		\[
			@matlab@ x @endmatlab@ \neq @num(x,keepFloat=4)@
			\,.
		\]
		@pb;@
		Of course, the result of a Matlab code evaluation can also be used directly when stating the correct answer to a problem.
		@lb;@
		Let $x=@x@$. Then $\sqrt{x}=$ @numericalans(100,matlab.sqrt(float(x)))@.
		@pb;@
		There are, however, some caveats to keep in mind when using the Matlab engine API within Python code. Most importantly, the argument and return value types need to be converted explicitly at times; note the expression "matlab.sqrt(float(x))" above. For example, the function call 'matlab.normcdf(4)' will yield an error message instead of the expected result 2, since the single argument of the 'sqrt' function needs to be an explicit floating point number, whereas integers are not cast automatically. However, both the commands 'matlab.sqrt(4.0)' and 'matlab.sqrt(float(4))' work as expected. In general, if an argument "x" inteded for a Matlab function is (or might be) an integer, it should always be explicitly cast into a 'float' object via 'float(x)'.
		
		For the exact formatting required for vectors and matrices, please refer to the Matlab engine API documentation by MathWorks. For other methods of obtaining and setting Matlab workspace variables to and from .xmu files, please refer to Tutorial 17.
	@;content@
@;problem@