Sie sind auf Seite 1von 5

QUESTION 1- 10:

--> disp("Hello World") F

"Hello World" COMPARISION


--> 2==3
ARITMETIC OPERATORS ans =
--> 6+2
ans = F

8. IF-ELSE
--> a
--> 6-4 a =
ans =
10.
2.
--> b
--> 2*3+5 b =
ans =
10.2
11.
if a > b then
--> 2/0.5 > disp(a)
ans = > else
> disp(b)
4. > end

--> a =10 10.2


a =

10. --> a==b


ans =
--> %a = 5
%a = F

5. LOGICAL OPERATIONS
--> a = 1
--> b = 10.2 a =
b =
1.
10.2
--> b = 2
BOOLEAN VARIABLES b =
--> c = true //wrong
2.
Undefined variable: true
--> a&b
--> c = %t ans =
c =
T
T
--> a && b
--> f = %f ans =
f =
T --> bitxor(1,2)
ans =
--> a!=b//‘a!’ is treated as a var
a! = 3.

2. DEC-TO-BIN AND BIT-SET


--> dec2bin(10)
--> a ans =
a =
"1010"
1.
--> x = dec2bin(10)
--> a! x =
a! =
"1010"
2.
--> bitset(8,2)//set 2nd bit to 1
--> 0|1 ans =
ans =
10.
T TAKING INPUT
--> n = input("Enter any number:
--> 0&1 ")
ans = Enter any number: 5

F --> n =

--> ~2 5.
ans = FUNCTION TO CHECK FOR EVEN
--> function y = isEven(n)
F > if modulus(n,2)==0 then
> disp("Even")
--> ~1 > else
ans = > disp("Odd")
> endfunction
F >
--> ~0 --> n
ans = n =
T 5.

BITWISE OPERATIONS IF-ELSE FOR EVEN ODD


--> bitand(1,2) --> if modulo(n,2)==0 then
ans = > disp("Even")
> else
0. > disp("Odd")
> end
--> bitor(1,2)
ans = "Odd"
3. --> n = 10
n =
1024.
10. --> a
a =
--> if modulo(n,2)==0 then
> disp("Even") 1.
> else
> disp("Odd") --> b
> end b =

"Even" 2.

--> c
QUESTIONS 11-20 c =

NESTED IF-ELSE: MAX OF 3 NUMS 3.


--> a=1 FRACTIONAL POWERS
a = --> -1^0.5 //incorrect output
ans =
1.
-1.
--> b=2
b = --> sqrt(-1) //works
ans =
2.
0. + i
--> c=3 ROOTS OF QUADRATIC EQUATIONS
c = --> discriminant = sqrt(b^2 -
4*a*c)
3. discriminant =
--> if a>b: 0. + 2.8284271i
>
--> root1 = (-b + discriminant)
--> if a>b then /2*a
> if a>c then root1 =
> disp(a)
> else -1. + 1.4142136i
> disp(c)
> end --> root2 = (-b - discriminant)
> else /2*a
> if b>c then root2 =
> disp(b)
> else -1. - 1.4142136i
> disp(c)
NESTED FUCTIONS
> end
function []= fun1()
> end
> function []= fun2()
> disp("World")
3.
> endfunction
> disp("Hello")
POWER OPERATOR > fun2()
2^10 > endfunction
ans =
--> fun1()
> plot(cos(x),x)
"Hello" > subplot(223)
> plot(tan(x),x)
"World" > subplot(224)
GLOBAL VARIABLES > plot(cot(x),x)
--> function [] = G() > endfunction
> global a
> a = 2 --> makePlot()
> endfunction at line 9 of function makePlot
Undefined variable: cot
--> G()

--> a
a =

1.

--> global a

--> a
a =

2.
STRING CONCATENATION
--> "Line1" + "Line2"
ans =

"Line1Line2" GRAPH USING SCRIPT


Code:
--> "Line1" + " " + "Line2" x = [-5:0.1:5]
ans = function f=fun(x)
f = x^2
"Line1 Line2" endfunction
TYPE CASTING y = fun(x)
--> a = 2.1234 plot(x,y)
a = xlabel("X")
ylabel("X^2")
2.1234 title("PARABOLA")

--> a = int(a)
a =

2.

--> a = bool2s(a)
a =

1.
GRAPH PLOTTING - SUBPLOT
-> function [] = makePlot()
> subplot(221)
> plot(sin(x),x)
> subplot(222)

Das könnte Ihnen auch gefallen