This is a question that I need answered from MATLAB Thanks i
This is a question that I need answered from MATLAB! Thanks in advance!
1. Suppose we have the following if/then statements. What are the resulting values of w if we initialize z to the following values and then execute the statement? if z 5 elseif z 10 w 39- z elseif z 100 sqrt(z) else end 10 points a. z 1: w (4 points) w-0 w-1 w 2 W-3 W-9 O w-10 w 100Solution
============================================================
1.
------------
Answer:
------------
-------------------------------------------------
a) z=1
if z<5 -> True since 1<5
w = 2*z
w = 2*1 =2
Hence w = 1 is the answer
-------------------------------------------------
b) z=9
if z<10 -> True since 9<5
w = 9-z
w = 9-9 =0
Hence w = 0 is the answer
-------------------------------------------------
c) z=100
if z<100 -> False since 100<100
Next statement is else
i.e
w = z
w = 100
Hence w = 100 is the answer
============================================================
2.
------------
Answer:
------------
Initlal Q= 5 and T = 2
if(Q>T |Q>8) &(T<=4) i.e if(5>2|5>8)&&(2<=4)
The first condition olny satisfies
=> R = Q*T
= 5*2
= 10
Hence R = 10 is the correct answer
============================================================
3.
------------
Answer:
------------
Initlal T=9
if T<30 i.e 9<30
The first condition olny satisfies
=> h = 2*T +1
= 2*9+1
= 19
Hence h = 19 is the correct answer
============================================================
4.
------------
Answer:
------------
Initlal r=0
for y=1:2:5
r=r+3
This for loop executes 3 times since
Initial y value is 1 , condition till 5 not reached
r = 0+3 = 3
next y value is 1+2= 3,condition till 5 not reached
r = 3+3 = 6
next y value is 3+2= 5,condition till 5 reached,terminates loop
r = 6+3 = 9
Hence r = 9 is the correct answer
============================================================

