Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Test your understanding

T4.3-1.

Write the following in your command prompt:

x=[5,-3,18,4];
y=[-9,13,7,4];
z=~y>x

You will get the following:

z =

1×4 logical array

0 1 0 0

Write the following in your command prompt:

x=[5,-3,18,4];
y=[-9,13,7,4];
z = x & y
You will get the following:

z =

1×4 logical array

1 1 1 1

Write the following in your command prompt:

x=[5,-3,18,4];
y=[-9,13,7,4];
z = x|y

You will get the following:

z =
1×4 logical array

1 1 1 1

Write the following in your command prompt:

x=[5,-3,18,4];
y=[-9,13,7,4];
z = xor(x,y)

You will get the following:

z =

1×4 logical array

0 0 0 0

T4.3-2.

Write the following in your command prompt:

x=[5,-3,18,4];
y=[-9,13,7,4];
z=~y>x

You will get the following:

Section 3.2

8.

Open a function file. Write the following:


function y = p8(x)
%Converts from F to C
y=(5/9)*(x-32);
end
Click Run. Your function name will be same as your file name. I used my function as p8 (means problem
8). Now, write the following in your command window:

p8([32,212])

Press Enter. You will get the following:

ans =

0 100

9.

Open a function file. Write the following:


function t = p9(h,v0,g)
%Computes the time t to reach height h, with initial speed v0
roots ([0.5*g,-v0,h])
end

Click Run. Your function name will be same as your file name. I used my function as p8 (means problem
8). Now, write the following in your command window:

p9(100,50,9.81)

Press Enter. You will get the following:

ans =

7.4612
2.7324

10.

Open a function file. Write the following:

Click Run.

Section 3.3

23.
Write in your command window:

ex=@(x) 10*exp(-2*x);
x=[0:0.01:2];
plot(x,ex(x)),xlabel('x'),ylabel('10*e^{-2x}')

You will get a graph

24.

fn=@(x) 20*x.^2-200*x+3;
x=[4:0.01:6];
plot(x,fn(x)),xlabel('x'),grid

Press Enter. You will get a graph. Then, write the following and press Enter:

[x,fval]=fminbnd(fn,4,6)

x =

fval =

-497

25.

26.
function f = p26(a,b,c,d)
f=@p;
function y=p(x)
y=a*x.^3+b*x.^2+c*x+d;
end

end
Type the following in your command file:

f= p26(3,-12,-33,80);

x=[-10,0.01:10];

plot(x,f(x)), grid
fzero(f,-4)

Press Enter:

ans =

-2.9143

Now write the following and press Enter:

fzero(f,6)

ans =

5.1309

27.
function f = p27(a,b,c)
f =@p;
function y = p(x)
y=a*x.^2+b*x+c;
end
end

Type the following in your command file:

f= p27(20,-200,12);
[x,fval]=fminbnd(f,0,10)

Press Enter:
x =

5.0000

fval =

-488

 
Section 3.4

You might also like