티스토리 뷰

// kick off : 2016-10-30

// by Ryan C


I am writing this for comparison of the syntax of the three most popular programming languages. This will be useful for the people who interchangeably use those languages but having painful time to recall the grammar of each language.


 

 python

matlab 

c++ 

 continue code next line

... 

(nothing. just enter) 

 end of the sentence 

(nothing) 

 (nothing) for echo

 ; for non-echo

 ;

 block

 indent

 "end"

 e.g.)

 function

     for

        ...

     end

 end

 {} 

 function

 def f1(arg1, arg2) :

      return arg1+arg2



 function [ a, b ] = f1(arg1, arg2)

 a = arg1 + arg2;

 b = arg1 * arg2;

 end

 int f1(arg1, arg2)

 {

     return arg1 + arg2;

 }

 OOP

 yes (in case you want to return multiple variables you would use an object that has a structure inside)

 no (that's why it should have multiple return variables as above, a, and b.)

 yes (same as python)

 variable type

 implicit

 implicit

 explicit (need to define)

 comment (single line)

 #

 % //
 comment (multiple lines) """
   ....
 """

 n.a. (just use % every line)

 /*

     ...

 */

 open new file

 

 edit f1

 % it gives f1.m newly opened for you

 
 differentiate 

 syms t

 diff(cos(t)^2, t)

 

 Matrix calculation

 

Suppose you have an 7x7 matrix X. You want to compute the log of every element : log(X), the square of every element : X.^2, add 1 to every element : X+1, and divide every element by 4 : X/4


cf. X^2 := X*X



댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
TAG
more
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함