BASIC SYNTAX OF MATLAB

  • As MATLAB is a high-level computer language, it must be written in a specific manner.
  • MATLAB environment behaves like a super-complex calculator. You can enter commands at the >>command prompt.
  • MATLAB is an interpreted environment. In other words, you cant write a command in command prompt and it will execute it right away.

For example no.1:-

If we give command to add two digits in the command window, it will show as follows

>>1+2
When you click the RUN button or press the ENTER, MATLAB executes it immediately and the result returned is:–
ans=
                    3
For example no.2:-
Another example, when a digit is divided by zero
>>7/0
When you click the RUN button or press the ENTER, MATLAB executes it immediately and the result returned is:–
ans = Inf
warning: Division by zero
For example no.3:-
>>524*20.3
When you click the RUN button or press the ENTER, MATLAB executes it immediately and the result returned is:–
ans=
            1.0637e+04
For example no.4:-
When a digit raised to the power of another digit
>>5^3
When you press Enter, it executes,
ans=
            125
For example no.5:-
To represent in a trigonometric value
>>sin(pi/2)
When you press Enter, it executes, 
ans=
            1

Note:-
o   Here we write pi instead of using the symbol, because MATLAB don’t recognize the pi symbol.
o   Also we can use the value of pi which is 3.14 instead of writing pi.


Use Of SEMICOLON ";" in MATLAB:-

Generally in other programming languages semicolon: is used as a statement terminator, but in MATLAB it is also sided for statement terminator as well as to hide what we got after executed some blocks of statements. 

For example no.6:-
x=3;
y=x+2
When you Press  enter, it executes,
y=5

Adding comments in MATLAB:-

The per cent symbol(%) is used for indicating a comment line.

For example no.7:-

y=5         %assign the value 5 to y
    • if you want to write a block of comments just write it in between the block comment operators % ................% 
contact-form


Post a Comment

If you have any doubts regarding this topic...
feel free to ask...

Previous Post Next Post