thanks Global variables can be a tricky concept at first and are a true test of
ID: 3543013 • Letter: T
Question
thanks
Global variables can be a tricky concept at first and are a true test of your knowledge of the scope of a variable (which variables a function can see and what they cannot see). Assume that you have the following two functions in your working directory: function y = func1 (x) global G; % G has been declared as a global variable G = 5*x; y = G + 2*x; end function y = func2 (x) G = 50; % G is NOT a global variable, it is local to func2 y = G + 3*x; The following commands are entered at the MATLAB prompt: clear global G G = 5; a = func1(G + 2); b = func2 (G + 2) ; a = b b = G G =Explanation / Answer
a = 49
b = 161
G=35
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.