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

This quiz was conduct in Fundamental Programming Concepts class. This quiz was in beginning while we were learning MATLAB. Tags for this quiz are: Matlab Functions, Swapping two Values, Matlab Code, Matlab For Begginer, Matlab Exercise, Matlab File, Functions

Typology: Exercises

2012/2013

Uploaded on 08/17/2013

zaid
zaid 🇮🇳

4.5

(2)

59 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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