Professional Documents
Culture Documents
Homework, Part 4 Due: 02/9/18
Homework, Part 4 Due: 02/9/18
Problem 1
Part-a:
Without matlab:
a+b = 8;
a-b = 4;
c = -5;
y = 8>4<-5
8>4 =1
1<-5 = 0
Answer is y = 0 .
Code:
a = 6;
b = 2;
c = -5;
y_a = a+b>a-b<c
Output:
Part-b:
Without matlab:
y = -6<-5<-2
From left to right:
-6<-5 = 1
1<-2 = 0
Answer is y = 0
Code:
a = 6;
b = 2;
c = -5;
y_b = -6<c<-2
Output:
Part-c:
Without matlab:
First division:
a/b = 3
b+c = -3
c> a/b = 0
Y = b+c >=0
Answer is 0 .
Code:
a = 6;
b = 2;
c = -5;
y_c_1 = a/b
y_c_2 = b+c
y_c_3 = c>a/b
y_c_4 = b+c >= c>a/b
Output:
Part-d:
Without matlab:
First Parenthesis:
c+a ~=a/b-b
a/b = 3
1 ~= 1 answer is 0
~(0) =1
A+c = 1;
Now equal condition will be checked:
1 == 1
Code:
a = 6;
b = 2;
c = -5;
y_d = a+c==~(c+a~=a/b-b)
Output:
Problem 2
Part-a:
Without matlab:
0&21
Answer is 0 .
Part-b:
Without matlab:
~-2>-1 & 11>=~0
Answer is y = 1
Part-c:
Without matlab:
Answer is y = 1
Part-d:
Without matlab:
First negation:
~2 = 0;
Then multiplication:
0*-3 = 0
-1&0 = 0
-3|0|0 = 1
So answer is 1.
Code and Output:
Problem 3:
Code:
Main code:
Function:
Output:
Problem 4:
Code:
TCH = [75 79 86 86 79 81 73 89 91 86 81 82 86 88 89 90 82 84 81 79 73 69 73
79 82 72 66 71 69 66 66]
TSF = [69 68 70 73 72 71 69 76 85 87 74 84 76 68 79 75 68 68 73 72 79 68 68
69 71 70 89 95 90 66 69]
%% Part-a Average of temperature
sprintf('PART-A')
no_days = size(TCH);
n = 1;
sum_CH = 0;
sum_SF = 0;
while n <= no_days(2)
sum_CH = sum_CH + TCH(n);
sum_SF = sum_SF + TSF(n);
n = n+1;
end
avg_CH = sum_CH/no_days(2)
avg_SF = sum_SF/no_days(2)
Code:
Main code:
m_1 =5;
m_2 = 10;
m_3 = 20;
sprintf('With m = 5')
[out] = pi_func(m_1)
format long
actual = pi
sprintf('With m = 10')
[out] = pi_func(m_2)
actual = pi
sprintf('With m = 20')
[out] = pi_func(m_3)
actual = pi
Function: