CMP 1
CMP 1
>> f = 3^2-((5+4)/2)+6*3
f=
22.5000
Function values:
1.0e+06 *
>> x = 5; % Value of x
y = 10; % Value of y
f = 5 * x + 10 * y; % Evaluate the function
disp(f); % Display the result
125
% Assign values
a = 2;
b = 3;
c = -4;
d = -3;
3.
% Expression
result = (b - (a / (b + (b + (a / (w * a))))));
% Display the result
disp(result);
4.7273
5. Set up a vector x which contains the values from zero to one in steps of one
tenth.
Columns 13 through 21
Columns 13 through 24
0.5216 0.5227 0.5237 0.5246 0.5254 0.5262 0.5268 0.5274
0.5279 0.5283 0.5286 0.5288
Columns 25 through 36
Columns 37 through 48
Columns 49 through 60
Columns 61 through 72
Columns 73 through 84
Columns 85 through 96
Columns 13 through 24
Columns 25 through 36
Columns 37 through 48
Columns 61 through 72
Columns 73 through 84
Columns 85 through 96
disp('f(x) at x = 1:');
disp(f_x(11)); % f(1) (index 11 corresponds to x = 1)
disp('f(x) at x = 2:');
disp(f_x(21)); % f(2) (index 21 corresponds to x = 2)
f(x) at x = 1:
3
f(x) at x = 2:
6
1)
% Given value of x
x = 1.3;
2)
>> % Given value of x in degrees
x_deg = 30;
3)
>> % Given value of x
x = 1;
4)
13.Calculate the value of the function y(x) = |x| sin x 2 for values of x = π/3 and
π/6 (use the MATLAB command abs(x) to calculate |x|).
14.Calculate the quantities sin(π/2), cos(π/3), tan 60◦ and ln(x +√x2 + 1) where
x = 1/2 and x = 1. Calculate the expression x/((x2 +1) sin(x)) where x = π/4
and x = π/2.
15.Explore the use of the functions round, ceil, floor and fix for the values x =
0.3, x = 1/3, x = 0.5, x = 1/2, x = 1.65 and x = −1.34.
round_x2 = round(x2);
ceil_x2 = ceil(x2);
floor_x2 = floor(x2);
fix_x2 = fix(x2);
round_x3 = round(x3);
ceil_x3 = ceil(x3);
floor_x3 = floor(x3);
fix_x3 = fix(x3);
round_x4 = round(x4);
ceil_x4 = ceil(x4);
floor_x4 = floor(x4);
fix_x4 = fix(x4);
round_x5 = round(x5);
ceil_x5 = ceil(x5);
floor_x5 = floor(x5);
fix_x5 = fix(x5);
round_x6 = round(x6);
ceil_x6 = ceil(x6);
floor_x6 = floor(x6);
fix_x6 = fix(x6);
% Display results
disp('Results for x = 0.3:');
disp(['round(0.3) = ', num2str(round_x1)]);
disp(['ceil(0.3) = ', num2str(ceil_x1)]);
disp(['floor(0.3) = ', num2str(floor_x1)]);
disp(['fix(0.3) = ', num2str(fix_x1)]);
For x = 3 and y = 4:
rem(x, y) = 3
mod(x, y) = 3
For x = 3 and y = 6:
rem(x, y) = 3
mod(x, y) = 3
For x = 4 and y = 3:
rem(x, y) = 1
mod(x, y) = 1
For x = 4 and y = 4:
rem(x, y) = 0
mod(x, y) = 0
For x = 4 and y = 6:
rem(x, y) = 4
mod(x, y) = 4
For x = 5 and y = 3:
rem(x, y) = 2
mod(x, y) = 2
For x = 5 and y = 4:
rem(x, y) = 1
mod(x, y) = 1
For x = 5 and y = 6:
rem(x, y) = 5
mod(x, y) = 5
17.
3 0.96429
3.01 0.96463
3.02 0.96497
3.03 0.9653
3.04 0.96563
3.05 0.96595
3.06 0.96628
3.07 0.96659
3.08 0.96691
3.09 0.96722
3.1 0.96752
3.11 0.96783
3.12 0.96812
3.13 0.96842
3.14 0.96871
3.15 0.969
3.16 0.96928
3.17 0.96956
3.18 0.96984
3.19 0.97012
3.2 0.97039
3.21 0.97065
3.22 0.97092
3.23 0.97118
3.24 0.97144
3.25 0.97169
3.26 0.97195
3.27 0.9722
3.28 0.97244
3.29 0.97269
3.3 0.97293
3.31 0.97316
3.32 0.9734
3.33 0.97363
3.34 0.97386
3.35 0.97409
3.36 0.97431
3.37 0.97454
3.38 0.97476
3.39 0.97497
3.4 0.97519
3.41 0.9754
3.42 0.97561
3.43 0.97582
3.44 0.97602
3.45 0.97623
3.46 0.97643
3.47 0.97663
3.48 0.97682
3.49 0.97702
3.5 0.97721
3.51 0.9774
3.52 0.97759
3.53 0.97777
3.54 0.97796
3.55 0.97814
3.56 0.97832
3.57 0.97849
3.58 0.97867
3.59 0.97884
3.6 0.97902
3.61 0.97919
3.62 0.97936
3.63 0.97952
3.64 0.97969
3.65 0.97985
3.66 0.98001
3.67 0.98017
3.68 0.98033
3.69 0.98049
3.7 0.98064
3.71 0.98079
3.72 0.98094
3.73 0.98109
3.74 0.98124
3.75 0.98139
3.76 0.98154
3.77 0.98168
3.78 0.98182
3.79 0.98196
3.8 0.9821
3.81 0.98224
3.82 0.98238
3.83 0.98251
3.84 0.98265
3.85 0.98278
3.86 0.98291
3.87 0.98304
3.88 0.98317
3.89 0.9833
3.9 0.98342
3.91 0.98355
3.92 0.98367
3.93 0.98379
3.94 0.98391
3.95 0.98403
3.96 0.98415
3.97 0.98427
3.98 0.98439
3.99 0.9845
4 0.98462
4.01 0.98473
4.02 0.98484
4.03 0.98495
4.04 0.98506
4.05 0.98517
4.06 0.98528
4.07 0.98538
4.08 0.98549
4.09 0.98559
4.1 0.9857
4.11 0.9858
4.12 0.9859
4.13 0.986
4.14 0.9861
4.15 0.9862
4.16 0.9863
4.17 0.9864
4.18 0.98649
4.19 0.98659
4.2 0.98668
4.21 0.98678
4.22 0.98687
4.23 0.98696
4.24 0.98705
4.25 0.98714
4.26 0.98723
4.27 0.98732
4.28 0.98741
4.29 0.98749
4.3 0.98758
4.31 0.98766
4.32 0.98775
4.33 0.98783
4.34 0.98791
4.35 0.988
4.36 0.98808
4.37 0.98816
4.38 0.98824
4.39 0.98832
4.4 0.9884
4.41 0.98847
4.42 0.98855
4.43 0.98863
4.44 0.9887
4.45 0.98878
4.46 0.98885
4.47 0.98893
4.48 0.989
4.49 0.98907
4.5 0.98915
4.51 0.98922
4.52 0.98929
4.53 0.98936
4.54 0.98943
4.55 0.9895
4.56 0.98956
4.57 0.98963
4.58 0.9897
4.59 0.98976
4.6 0.98983
4.61 0.9899
4.62 0.98996
4.63 0.99003
4.64 0.99009
4.65 0.99015
4.66 0.99021
4.67 0.99028
4.68 0.99034
4.69 0.9904
4.7 0.99046
4.71 0.99052
4.72 0.99058
4.73 0.99064
4.74 0.9907
4.75 0.99076
4.76 0.99081
4.77 0.99087
4.78 0.99093
4.79 0.99098
4.8 0.99104
4.81 0.99109
4.82 0.99115
4.83 0.9912
4.84 0.99126
4.85 0.99131
4.86 0.99136
4.87 0.99142
4.88 0.99147
4.89 0.99152
4.9 0.99157
4.91 0.99162
4.92 0.99167
4.93 0.99172
4.94 0.99177
4.95 0.99182
4.96 0.99187
4.97 0.99192
4.98 0.99197
4.99 0.99202
5 0.99206
18.
-2 -1.375
-1.9 -1.4477
-1.8 -1.5295
-1.7 -1.6222
-1.6 -1.7285
-1.5 -1.8519
-1.4 -1.9971
-1.3 -2.1711
-1.2 -2.3843
-1.1 -2.6521
-1 -3
19.Evaluate the functions (For x from 1 to 2 in steps of 0.1)
a)
1 5 0.84147 0.70807
1.1 5.961 0.93562 0.79425
1.2 7.048 0.99146 0.8687
1.3 8.267 0.9929 0.92844
1.4 9.624 0.92521 0.97111
1.5 11.125 0.77807 0.995
1.6 12.776 0.54936 0.99915
1.7 14.583 0.24895 0.9834
1.8 16.552 -0.098249 0.94838
1.9 18.689 -0.45147 0.89548
2 21 -0.7568 0.82682
b)
1 0.25565
1.1 0.089488
1.2 -0.10891
1.3 -0.33424
1.4 -0.58011
1.5 -0.83935
1.6 -1.1042
1.7 -1.3667
1.8 -1.6191
1.9 -1.8538
2 -2.0641
c)