Docsity

MATLAB Functions - Fundamental Programming Concepts - Quiz, Exercises of Computer Programming

Toggle sidebar
bg1
1 Assignment (5 points)
x = 6;
y = 3;
z=x/y;
x=x-y;
y=z+2*x;
What are the final values for
x: y: z:
2 MATLAB functions (5 points)
phi = 2*pi;
theta = phi/2;
st = sin(theta);
val = exp(st);
% theta = 2*theta;
cos(theta)
What are the final values for
theta: ct: val: ans:
3 Swapping two values (5 points)
Complete the following function so that it produces the desired output.
function [x,y] = swap(x,y)
% This function should swap the values of two variables.
% If you want, you can use extra variables.
Now assume that the above function is stored in our current working directory
and it is named swap.m. On the command window if we enter the following
lines,
x = 0;
y = 4;
z = 5;
[x,y] = swap(x,y);
[z,r] = swap(x,z);
swap(y,r);
What will be the stored values for
x: y: z: r: ans:
1
docsity.com

Partial preview of the text

Download MATLAB Functions - Fundamental Programming Concepts - Quiz and more Exercises Computer Programming in PDF only on Docsity!

1 Assignment (5 points)

x = 6; y = 3; z = x / y; x = x - y; y = z + 2 * x;

What are the final values for

x: y: z:

2 MATLAB functions (5 points)

phi = 2pi; theta = phi/2; st = sin(theta); val = exp(st); % theta = 2theta; cos(theta) What are the final values for

theta: ct: val: ans:

3 Swapping two values (5 points)

Complete the following function so that it produces the desired output.

function [x,y] = swap(x,y) % This function should swap the values of two variables. % If you want, you can use extra variables.

Now assume that the above function is stored in our current working directory and it is named swap.m. On the command window if we enter the following lines,

x = 0; y = 4; z = 5; [x,y] = swap(x,y); [z,r] = swap(x,z); swap(y,r);

What will be the stored values for

x: y: z: r: ans:

docsity.com