To run simple expressions in MATLAB we can use the command window. Here is how you open the command window.
Command Window is inside the Desktop menu in Matlab.
This is the Command Window open in Matlab:
Type 1+2 now and press enter
This is the output in the Command Window:
When you write an expression in the Matlab Command Window. Matlab evaluates it and stores it in a default variable called ans.
Then prints the answer if no semi colon is added after the expression.
if I write 1+2; then no output is given by default. If I want the output I can simply write ans in the next line and get the output.
% starts a comment, and clc clears the window.
The following scalar arithmetic operators are supported in Matlab. At this moment we are not dealing with matrices.
Uses of these operators.
3+4 will give 7
3-4 will be -1
3*4 is 12
4/5 is 0.8
4\5 reverse the order of division. Answer will be 1.25
3^4 is 3 raised to the power 4. This will be 81.
These are the precedence rules for arithmetic eperators in Matlab.
(.*), right division
(./), left division
(.\), matrix multiplication
(*), matrix right division
(/), matrix left division
(-)Operators in the same level are ealuated from left to right.
Find the area of a triangle having sides 3,4 and 5.
Solve the Quadratic Equation:
>> root1=(-b + discr^0.5)/(2*a);
>> root2=(-b – discr^0.5)/(2*a);