Professional Documents
Culture Documents
CH 4 Draft
CH 4 Draft
T4.3-1.
x=[5,-3,18,4];
y=[-9,13,7,4];
z=~y>x
z =
1×4 logical array
0 1 0 0
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
x=[5,-3,18,4];
y=[-9,13,7,4];
z = x|y
z =
1×4 logical array
1 1 1 1
x=[5,-3,18,4];
y=[-9,13,7,4];
z = xor(x,y)
z =
1×4 logical array
0 0 0 0
T4.3-2.
x=[5,-3,18,4];
y=[-9,13,7,4];
z=~y>x
Section 3.2
8.
p8([32,212])
ans =
0 100
9.
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)
ans =
7.4612
2.7324
10.
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}')
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
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
f= p27(20,-200,12);
[x,fval]=fminbnd(f,0,10)
Press Enter:
x =
5.0000
fval =
-488
Section 3.4