In: Advanced Math
USING MATLAB....
a.) Create anonymous functions:
fa(x)=sin(x^2)
fb(x)=sin^2(x)
b.) Evaluate them both at x=1/2 pi
c.)Evaluate them both at x=(0,1,2,...,10)^T
d.) Calculate fa(fb(2)) and fb(fa(2))
clc;
clear all;
%%% Answer a
fa=@(x)sin(x.^2);
fb=@(x)(sin(x)).^2;
%%% Answer b
x1=pi/2;
disp('fa at x1')
fa(x1)
disp('fb at x1')
fb(x1)
%%% Answer c
x=0:10;
disp('fa at x=0 to 10')
fa(x)'
disp('fb at x=0 to 10')
fb(x)'
%%% Answer d
disp('fb(fa(2))')
fb(fa(2))
disp('fa(fb(2))')
fa(fb(2))
fa at x1
ans =
0.624265952639699
fb at x1
ans =
1
fa at x=0 to 10
ans =
0
0.841470984807897
-0.756802495307928
0.412118485241757
-0.287903316665065
-0.132351750097773
-0.991778853443116
-0.953752652759472
0.920026038196791
-0.629887994274454
-0.506365641109759
fb at x=0 to 10
ans =
0
0.708073418273571
0.826821810431806
0.019914856674817
0.572750016904307
0.919535764538226
0.078073020633754
0.431631390896083
0.978829740161692
0.169841645877960
0.295958969093304
fb(fa(2))
ans =
0.471419918046348
fa(fb(2))
ans =
0.631614802553066
>>