Question

In Matlab: Given the script: x = 1; x = fun(x-1); y = x-1 and the...

In Matlab:

Given the script:

x = 1;

x = fun(x-1);

y = x-1

and the function:

function y = fun(x)

x = x-1;

y = x-1;

end

What is the output

a) -2

b) -4

c) -3

d) -1

Homework Answers

Answer #1

c) -3

Explanation:
-------------
function y = fun(x)
    x = x-1;
    y = x-1;
end

x = 1;
x = fun(x-1);   // calls fun with 1-1 = 0
    x = x-1; changes x to 0-1 = -1
    y = x-1; so, y = -1-1 = -2
    so, function returns -1
y = x-1, y = -2-1 = -3
so, value of y is -3.
since there is no semi-colon after y=x-1, value of y is printed.
so, -3 is printed


Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Using the Script: function EulerMethod1(n) X = 0 : 1/n : 1 ; Y = zeros(...
Using the Script: function EulerMethod1(n) X = 0 : 1/n : 1 ; Y = zeros( 1, n + 1 ) ; Y(1) = 1 ; for k = 1 : n m = Y(k) ; Y(k + 1) = Y(k) + m*( X(k + 1) - X(k) ) ; end clf plot( X, Y ) Create a new script, which defines the function EulerMethod2. The purpose of EulerMethod2 is to use Euler's Method to approximate the solution to the...
Write a matlab script file to solve the differential equation dy/dt = 1 − y^3 with...
Write a matlab script file to solve the differential equation dy/dt = 1 − y^3 with initial condition y(0)=0, from t=0 to t=10. matlab question
Using Matlab to solve the problem below Given X=[-2 -1 0 1 2] Y=[1.5 3.2 4.5...
Using Matlab to solve the problem below Given X=[-2 -1 0 1 2] Y=[1.5 3.2 4.5 3.4 2] a). Plot a scatter plot of the data b). Determine the coefficients of the polynomial ?0 + ?1? + ?2?2 which best fits the data c). Plot this function on the same plot as in part ‘a’. USE MATLAB CODE ONLY! USE MATLAB CODE ONLY! THANK YOU
Write Matlab script to plot the spectrum (-? to ? radians) of DTMF signal for keys...
Write Matlab script to plot the spectrum (-? to ? radians) of DTMF signal for keys 1, A and B. Choose an appropriate sampling frequency. The DTMF frequencies are indicated in table 1.     Critically analyze the design specification.                                           Row/column 1209HZ 1336Hz 1477HZ 1633HZ 697 1 2 3 A 770 4 5 6 B 852 7 8 9 C 941 * 0 # D     Write Matlab script to plot the spectrum (-? to ? radians) of DTMF signal for...
Let f(x, y) = c/x, 0 < y < x < 1 be the joint density...
Let f(x, y) = c/x, 0 < y < x < 1 be the joint density function of X and Y . a) What is the value of c? a) 1   b) 2 c) 1/2 d) 2/3 e) 3/2 b)what is the marginal probability density function of X? a) x/2 b)1 c)1/x d)x e)2x c)what is the marginal probability density function of Y ? a) ln y   b)−ln y c)1 d)y e)y2 d)what is E[X]? a)1 b)2 c)4 d)1/2 e)1/4
Write a MATLAB function and test bench script code to solve the above simple RL/RC circuits...
Write a MATLAB function and test bench script code to solve the above simple RL/RC circuits by following the instructions noted below. The input signal and impulse response generation should be done in the function. The test bench script should be used only to call the function and for signal plotting purposes. No plotting should be done inside the function itself. Name your function L2_C Instructions: Input voltage ,x(t), can be AC or DC. Consider a variable ‘w1’ which can...
12. Let f(x, y) = c/x, 0 < y < x < 1 be the joint...
12. Let f(x, y) = c/x, 0 < y < x < 1 be the joint density function of X and Y . What is the value of c? a) 1; b) 2; c) 1/2; d) 2/3; e) 3/2. 13. In Problem 12, what is the marginal probability density function of X? a) x/2; b)1; c)1/x; d)x; e)2x. 14. In Problem 12, what is the marginal probability density function of Y ? a) ln y; b)−ln y; c)1; d)y; e)y2....
1. Write a MATLAB script, by hand, on this page, that calculates the nth degree Taylor...
1. Write a MATLAB script, by hand, on this page, that calculates the nth degree Taylor expansion of cos x and then compares the plot of this expansion to the original function. In one of your first lines, you may fix n (e.g., n = 6) but the remainder of the code should refer to n.
Write a Matlab script that plots the following functions over 0 ≤ x ≤ 5π: f1(x)...
Write a Matlab script that plots the following functions over 0 ≤ x ≤ 5π: f1(x) = sin2 x − cos x, f2(x) = −0.1 x 3 + 2 x 2 + 10, f3(x) = e −x/π , f4(x) = sin(x) ln(x + 1). The plots should be in four separate frames, but all four frames should be in one figure window. To do this you can use the subplot command to create 2 × 2 subfigures.
Write and upload a MATLAB script to do the following. Compute the sequence S(n+1) = (2...
Write and upload a MATLAB script to do the following. Compute the sequence S(n+1) = (2 – K) S(n) – S(n-1) ;   Assume S(1) = 0, S(2) = 1; (a)    Case 1, Assume K = 1 (b)    Case 2, Assume K = 2 (c)     Case 3, Assume K = 4 Plot all of these on the same plot, for N = 1 to 20